In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to write the source code of the dup2 () function for you. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
The original dup2 () function:
# include int dup2 (int fd, int fd2)
For dup2, you can use the fd2 parameter to specify the value of the new descriptor. If fd2 is already open, close it first. If fd equals fd2, dup2 returns fd2 without closing it. Otherwise, the FD_CLOEXEC file descriptor flag for fd2 is cleared, so that fd2 is open when the process calls exec. The new file descriptor returned by this function shares the same file table entry as the parameter fd.
The following is the dup2 function implemented by yourself:
# include # include / / check whether the file descriptor is valid int isFileDescriptor (int fd) {struct stat st; if ((- 1 = = fstat (fd,&st)) & & (EBADF = = errno) return-1; return 0;} int my_dup2 (int oldfd, int newfd) {int tempfd; int fd_count; int fdarray [newfd]; int res If (- 1 = = isFileDescriptor (oldfd)) {printf ("the file descriptor is invalid.\ n"); return-1;} / / if newfd equals oldfd, return newfd directly without closing it if (oldfd = = newfd) return newfd; / / otherwise, close newfd if (0 = = isFileDescriptor (newfd)) {res = close (newfd) If (- 1 = = res) {perror ("close file descriptor failed"); return-1;}} / / copy file descriptor for (fd_count=0; fd_count
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.