📄 00000020.htm
字号:
<HTML><HEAD> <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>发信人: SuperSB (孤鹰), 信区: Linux <BR>标 题: [转载]unix环境高级编程-附B <BR>发信站: BBS 水木清华站 (Wed Mar 15 14:32:22 2000) <BR> <BR> <BR> <BR> <BR>发信人: taosm (128+64-->cool), 信区: unix <BR>标 题: unix环境高级编程--附录B 其他源代码 <BR>发信站: 西十八BBS (Sat Mar 11 14:31:25 2000), 转信 <BR> <BR>附录 B <BR>其它源代码 <BR>B.1 我们的头文件 <BR> 在书正文中的大多数程序都包含头文件ourhdr.h,这示于程序B.1中。其中定义了 <BR>常数(例如MAXLINE)和我们自编函数的原型。 <BR> 因为大多数程序序包含下列头文件:<stdio.h>、<stdlib.h>(其中有exit函数原 <BR>型),以及<unistd.h>(其中包含所有标准Unix函数的原型),所以ourhdr.h包含 <BR>了这些系统头文件,同时还包含了<string.h>。这样就减少了本书正文中所有程序 <BR>的长度。 <BR>/* Our own header, to be included *after* all standard system headers * <BR>/ <BR>#ifndef __ourhdr_h <BR>#define __ourhdr_h <BR>#include <sys/types.h> /* required for some of our prototypes */ <BR>#include <stdio.h> /* for convenience */ <BR>#include <stdlib.h> /* for convenience */ <BR>#include <string.h> /* for convenience */ <BR>#include <unistd.h> /* for convenience */ <BR>#define MAXLINE 4096 /* max line length */ <BR>#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) <BR> /* default file access permissions for n <BR>w files */ <BR>#define DIR_MODE (FILE_MODE | S_IXUSR | S_IXGRP | S_IXOTH) <BR> /* default permissions for new directori <BR>s */ <BR>typedef void Sigfunc(int); /* for signal handlers */ <BR> /* 4.3BSD Reno <signal.h> doesn't define <BR>SIG_ERR */ <BR>#if defined(SIG_IGN) && !defined(SIG_ERR) <BR>#define SIG_ERR ((Sigfunc *)-1) <BR>#endif <BR>#define min(a,b) ((a) < (b) ? (a) : (b)) <BR>#define max(a,b) ((a) > (b) ? (a) : (b)) <BR> /* prototypes for our own functions */ <BR>char *path_alloc(int *); /* {Prog pathalloc} */ <BR>int open_max(void); /* {Prog openmax} */ <BR>void clr_fl(int, int); /* {Prog setfl} */ <BR>void set_fl(int, int); /* {Prog setfl} */ <BR>void pr_exit(int); /* {Prog prexit} */ <BR>void pr_mask(const char *); /* {Prog prmask} */ <BR>Sigfunc *signal_intr(int, Sigfunc *);/* {Prog signal_intr_function} */ <BR>int tty_cbreak(int); /* {Prog raw} */ <BR>int tty_raw(int); /* {Prog raw} */ <BR>int tty_reset(int); /* {Prog raw} */ <BR>void tty_atexit(void); /* {Prog raw} */ <BR>#ifdef ECHO /* only if <termios.h> has been included */ <BR>struct termios *tty_termios(void); /* {Prog raw} */ <BR>#endif <BR>void sleep_us(unsigned int); /* {Ex sleepus} */ <BR>ssize_t readn(int, void *, size_t);/* {Prog readn} */ <BR>ssize_t writen(int, const void *, size_t);/* {Prog writen} */ <BR>int daemon_init(void); /* {Prog daemoninit} */ <BR>int s_pipe(int *); /* {Progs svr4_spipe bsd <BR>spipe} */ <BR>int recv_fd(int, ssize_t (*func)(int, const void *, size_t)); <BR> /* {Prog <BR> recvfd_svr4 recvfd_43bsd} */ <BR>int send_fd(int, int); /* {Progs sendfd_svr4 se <BR>dfd_43bsd} */ <BR>int send_err(int, int, const char *);/* {Prog senderr} */ <BR>int serv_listen(const char *); /* {Progs servlisten_svr4 servli <BR>ten_4 <BR>4bsd} */ <BR>int serv_accept(int, uid_t *); /* {Progs servaccept_svr4 servac <BR>ept_4 <BR>4bsd} */ <BR>int cli_conn(const char *); /* {Progs cliconn_svr4 cliconn_4 <BR>bsd} */ <BR>int buf_args(char *, int (*func)(int, char **)); <BR> /* {Prog <BR>bufargs} */ <BR>int ptym_open(char *); /* {Progs ptyopen_svr4 p <BR>yopen_44bsd} */ <BR>int ptys_open(int, char *); /* {Progs ptyopen_svr4 ptyopen_4 <BR>bsd} */ <BR>#ifdef TIOCGWINSZ <BR>pid_t pty_fork(int *, char *, const struct termios *, <BR> const struct winsize *); /* {Prog ptyfork <BR> */ <BR>#endif <BR>int lock_reg(int, int, int, off_t, int, off_t); <BR> /* {Prog <BR>lockreg} */ <BR>#define read_lock(fd, offset, whence, len) \ <BR> lock_reg(fd, F_SETLK, F_RDLCK, offset, whence, len) <BR>#define readw_lock(fd, offset, whence, len) \ <BR> lock_reg(fd, F_SETLKW, F_RDLCK, offset, whence, len) <BR>#define write_lock(fd, offset, whence, len) \ <BR> lock_reg(fd, F_SETLK, F_WRLCK, offset, whence, len) <BR>#define writew_lock(fd, offset, whence, len) \ <BR> lock_reg(fd, F_SETLKW, F_WRLCK, offset, whence, len) <BR>#define un_lock(fd, offset, whence, len) \ <BR> lock_reg(fd, F_SETLK, F_UNLCK, offset, whence, len) <BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -