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

📄 ptyopen.c

📁 unix环境高级编程一书源代码 本书全面介绍了UNIX系统的程序设计界面—系统调用界面和标准C库提供的许多函数。 本书的前15章着重于理论知识的阐述
💻 C
字号:
#include	<sys/types.h>#include	<sys/stat.h>#include	<errno.h>#include	<fcntl.h>#include	<stropts.h>#include	"ourhdr.h"extern char	*ptsname(int);	/* prototype not in any system header */intptym_open(char *pts_name){	char	*ptr;	int		fdm;	strcpy(pts_name, "/dev/ptmx");	/* in case open fails */	if ( (fdm = open(pts_name, O_RDWR)) < 0)		return(-1);	if (grantpt(fdm) < 0) {		/* grant access to slave */		close(fdm);		return(-2);	}	if (unlockpt(fdm) < 0) {	/* clear slave's lock flag */		close(fdm);		return(-3);	}	if ( (ptr = ptsname(fdm)) == NULL) {	/* get slave's name */		close(fdm);		return(-4);	}	strcpy(pts_name, ptr);	/* return name of slave */	return(fdm);			/* return fd of master */}intptys_open(int fdm, char *pts_name){	int		fds;			/* following should allocate controlling terminal */	if ( (fds = open(pts_name, O_RDWR)) < 0) {		close(fdm);		return(-5);	}	if (ioctl(fds, I_PUSH, "ptem") < 0) {		close(fdm);		close(fds);		return(-6);	}	if (ioctl(fds, I_PUSH, "ldterm") < 0) {		close(fdm);		close(fds);		return(-7);	}	if (ioctl(fds, I_PUSH, "ttcompat") < 0) {		close(fdm);		close(fds);		return(-8);	}	return(fds);}

⌨️ 快捷键说明

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