Create a file descriptor

冷暖自知 提交于 2019-12-06 15:12:48

fd = open ("sample.dat", O_RDONLY); open the file

dup2 (fd, 5); and copy the file descriptor fd into the descriptor number 5

now you can do read (5, buffer, BUFF_MAX); or also use fd to access the same file. You need to close the fd explicitly if you do not need it.

As @Arkadiy told see man dup2 for details.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!