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

📄 ttyslot.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
字号:
/*	@(#)ttyslot.c	1.4	*//*	@(#)ttyslot.c	1.2	*//*LINTLIBRARY*//* * Return the number of the slot in the utmp file * corresponding to the current user: try for file 0, 1, 2. * Returns -1 if slot not found. */#include <sys/types.h>#include <utmp.h>	/* DAG -- not "utmp.h" */#define	NULL	0extern char *ttyname(), *strrchr();extern int strncmp(), open(), read(), close();intttyslot(){	struct utmp ubuf;	register char *tp, *p;	register int s, fd;	if((tp=ttyname(0)) == NULL && (tp=ttyname(1)) == NULL &&					(tp=ttyname(2)) == NULL)		return(-1);	if((p=strrchr(tp, '/')) == NULL)		p = tp;	else		p++;	if((fd=open(UTMP_FILE, 0)) < 0)		return(-1);	s = 0;	while(read(fd, (char*)&ubuf, sizeof(ubuf)) == sizeof(ubuf)) {		if(			/* no ut_type *//* BRL			(ubuf.ut_type == INIT_PROCESS ||			ubuf.ut_type == LOGIN_PROCESS ||			ubuf.ut_type == USER_PROCESS ||			ubuf.ut_type == DEAD_PROCESS ) &&*/			strncmp(p, ubuf.ut_line, sizeof(ubuf.ut_line)) == 0){			(void) close(fd);			return(s);		}		s++;	}	(void) close(fd);	return(-1);}

⌨️ 快捷键说明

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