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

📄 syscalls.par.lib

📁 su 的源代码库
💻 LIB
字号:
SYSCALLS - routines for SYSTEM CALLs with error checkingecreat		creat with error checkefork		fork with error checkeopen		open with error checkeclose		close with error checkeunlink		unlink with error checkelseek		lseek with error checkepipe		pipe with error checkeread		read with error checkewrite		write with error check Function Prototypes:int ecreat(char *path, int perms);int efork(void);int eopen(char *path, int flags, int perms);int eclose(int fd);int eunlink(char *path);off_t elseek(int fd, off_t offset, int origin);int epipe(int fd[2]);ssize_t eread(int fd, char *buf, size_t nbytes);ssize_t ewrite(int fd, char *buf, size_t nbytes);Returns:ecreat returns a file descriptorefork returns child pid to parent, 0 to child or -1 on erroreopen returns a file descriptoreclose returns 0 on success or -1 on erroreunlink returns 0 on success or -1 on errorelseek returns number of bytes actually readepipe returns 0 on success or -1 on erroreread returns number of bytes actually readewrite returns number of bytes actually writtenNotes:Last arg to read/write is unsigned int on some ANSI systems,here we follow K&R, page 170.Rochkind says creat is superfluous, K&R say its mandatory.I think Rochkind is right--see TEST program below.Getting less than the number of bytes asked for on a readis *not* a system error--usually it just means end of filehas been reached.  However, it *might* be an error in someapplication.  Similarly coming up empty is not a system error,but might be an application error.  It is left to the user totrap these instances.  Here is an example of the first situationafter Rochkind, page 43:	#define SIZE sizeof(struct direct) 	...		while ((nread=eread(fd, &dlink, SIZE)) == SIZE) { 			... (process dlink) 		} 		switch(nread) { 		case 0: 			return; 		default: 			err("partial read"); 		} 	In an application where end of file was an error, we could replace 	case 0 by : 		case 0: 			err("EOF");References: Rochkind, "Advanced UNIX Programming"Kernighan and Pike, "The UNIX Programming Environment"Kernighan and Ritchie, "The C Programming Language"Mark Williams Company, "ANSI C--A Lexical Guide"Authors: SEP: Rick Otolini, Ron, Jon Claerbout, Stew LevinCWP: Shuki Ronen, Jack Cohen

⌨️ 快捷键说明

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