⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myopen.c

📁 unix网络编程卷1:套接口API的全书源码
💻 C
字号:
#include	"unp.h"intmy_open(const char *pathname, int mode){	int			fd, sockfd[2], status;	pid_t		childpid;	char		c, argsockfd[10], argmode[10];	Socketpair(AF_LOCAL, SOCK_STREAM, 0, sockfd);	if ( (childpid = Fork()) == 0) {		/* child process */		Close(sockfd[0]);		snprintf(argsockfd, sizeof(argsockfd), "%d", sockfd[1]);		snprintf(argmode, sizeof(argmode), "%d", mode);		execl("./openfile", "openfile", argsockfd, pathname, argmode,			  (char *) NULL);		err_sys("execl error");	}	/* parent process - wait for the child to terminate */	Close(sockfd[1]);			/* close the end we don't use */	Waitpid(childpid, &status, 0);	if (WIFEXITED(status) == 0)		err_quit("child did not terminate");	if ( (status = WEXITSTATUS(status)) == 0)		Read_fd(sockfd[0], &c, 1, &fd);	else {		errno = status;		/* set errno value from child's status */		fd = -1;	}	Close(sockfd[0]);	return(fd);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -