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

📄 sendfd.c

📁 unix环境高级编程第二版配套源代码 unix环境高级编程第二版配套源代码
💻 C
字号:
#include "apue.h"#include <stropts.h>/* * Pass a file descriptor to another process. * If fd<0, then -fd is sent back instead as the error status. */intsend_fd(int fd, int fd_to_send){	char	buf[2];		/* send_fd()/recv_fd() 2-byte protocol */	buf[0] = 0;			/* null byte flag to recv_fd() */	if (fd_to_send < 0) {		buf[1] = -fd_to_send;	/* nonzero status means error */		if (buf[1] == 0)			buf[1] = 1;	/* -256, etc. would screw up protocol */	} else {		buf[1] = 0;		/* zero status means OK */	}	if (write(fd, buf, 2) != 2)		return(-1);	if (fd_to_send >= 0)		if (ioctl(fd, I_SENDFD, fd_to_send) < 0)			return(-1);	return(0);}

⌨️ 快捷键说明

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