nspipe.c

来自「apue第二版每一章节的c语言源码」· C语言 代码 · 共 29 行

C
29
字号
/* Create a named stream pipe.  Called by server on initialization. */#include	<sys/types.h>#include	<sys/socket.h>#include	<sys/un.h>#include	<string.h>#include	<unistd.h>#include	"ourhdr.h"int			/* returns 0 if all OK, -1 if error (with errno set) */ns_pipe(const char *name, int fd[2]){	int					len;	struct sockaddr_un	unix_addr;	if (s_pipe(fd) < 0)		/* create unnamed stream pipe */		return(-1);	unlink(name);	/* remove the name, if it already exists */	memset(&unix_addr, 0, sizeof(unix_addr));	unix_addr.sun_family = AF_UNIX;	strcpy(unix_addr.sun_path, name);	len = strlen(unix_addr.sun_path) + sizeof(unix_addr.sun_family);	return(bind(fd[0], (struct sockaddr *) &unix_addr, len));						/* fd[0] has the name bound to it */}

⌨️ 快捷键说明

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