apue.h及编程环境配置
来源:互联网 发布:抓取淘宝数据包 编辑:程序博客网 时间:2024/06/01 15:05
apue全称指的是Advanced Programming in the UNIX Environment,即由超级大神W.Richard Stevens 写的unix环境高级编程。这本书可以算的上是unix环境编程的圣经,小弟不才,将一些学习经验分享,大家就仁者见仁智者见智吧。
由于书中的示例包含的文件很多,而版面有限,那么就来看看作者自己编写的头文件<apue.h>吧。这个头文件主要包含了经常要用到的头文件<stdio.h>,<stdlib.h>,<unistd.h>以及<string.h>。新建一个文件命名为apue.h,保存一下内容即可。
/* Our own header, to be included before all standard system headers */#ifndef_APUE_H#define_APUE_H#if defined(SOLARIS)#define _XOPEN_SOURCE500/* Single UNIX Specification, Version 2 for Solaris 9 */#define CMSG_LEN(x)_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)+(x))#elif !defined(BSD)#define _XOPEN_SOURCE600/* Single UNIX Specification, Version 3 */#endif#include <sys/types.h>/* some systems still require this */#include <sys/stat.h>#include <sys/termios.h>/* for winsize */#ifndef TIOCGWINSZ#include <sys/ioctl.h>#endif#include <stdio.h>/* for convenience */#include <stdlib.h>/* for convenience */#include <stddef.h>/* for offsetof */#include <string.h>/* for convenience */#include <unistd.h>/* for convenience */#include <signal.h>/* for SIG_ERR */#defineMAXLINE4096/* max line length *//* * Default file access permissions for new files. */#defineFILE_MODE(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)/* * Default permissions for new directories. */#defineDIR_MODE(FILE_MODE | S_IXUSR | S_IXGRP | S_IXOTH)typedefvoidSigfunc(int);/* for signal handlers */#ifdefined(SIG_IGN) && !defined(SIG_ERR)#defineSIG_ERR((Sigfunc *)-1)#endif#definemin(a,b)((a) < (b) ? (a) : (b))#definemax(a,b)((a) > (b) ? (a) : (b))/* * Prototypes for our own functions. */char*path_alloc(int *);/* {Prog pathalloc} */long open_max(void);/* {Prog openmax} */void clr_fl(int, int);/* {Prog setfl} */void set_fl(int, int);/* {Prog setfl} */void pr_exit(int);/* {Prog prexit} */void pr_mask(const char *);/* {Prog prmask} */Sigfunc*signal_intr(int, Sigfunc *);/* {Prog signal_intr_function} */int tty_cbreak(int);/* {Prog raw} */int tty_raw(int);/* {Prog raw} */int tty_reset(int);/* {Prog raw} */void tty_atexit(void);/* {Prog raw} */#ifdefECHO/* only if <termios.h> has been included */struct termios*tty_termios(void);/* {Prog raw} */#endifvoid sleep_us(unsigned int);/* {Ex sleepus} */ssize_t readn(int, void *, size_t);/* {Prog readn_writen} */ssize_t writen(int, const void *, size_t);/* {Prog readn_writen} */void daemonize(const char *);/* {Prog daemoninit} */int s_pipe(int *);/* {Progs streams_spipe sock_spipe} */int recv_fd(int, ssize_t (*func)(int, const void *, size_t));/* {Progs recvfd_streams recvfd_sockets} */int send_fd(int, int);/* {Progs sendfd_streams sendfd_sockets} */int send_err(int, int, const char *);/* {Prog senderr} */int serv_listen(const char *);/* {Progs servlisten_streams servlisten_sockets} */int serv_accept(int, uid_t *);/* {Progs servaccept_streams servaccept_sockets} */int cli_conn(const char *);/* {Progs cliconn_streams cliconn_sockets} */int buf_args(char *, int (*func)(int, char **));/* {Prog bufargs} */int ptym_open(char *, int);/* {Progs3 ptyopen_streams ptyopen_bsd ptyopen_linux} */int ptys_open(char *);/* {Progs3 ptyopen_streams ptyopen_bsd ptyopen_linux} */#ifdefTIOCGWINSZpid_t pty_fork(int *, char *, int, const struct termios *, const struct winsize *);/* {Prog ptyfork} */#endifintlock_reg(int, int, int, off_t, int, off_t); /* {Prog lockreg} */#defineread_lock(fd, offset, whence, len) \lock_reg((fd), F_SETLK, F_RDLCK, (offset), (whence), (len))#definereadw_lock(fd, offset, whence, len) \lock_reg((fd), F_SETLKW, F_RDLCK, (offset), (whence), (len))#definewrite_lock(fd, offset, whence, len) \lock_reg((fd), F_SETLK, F_WRLCK, (offset), (whence), (len))#definewritew_lock(fd, offset, whence, len) \lock_reg((fd), F_SETLKW, F_WRLCK, (offset), (whence), (len))#defineun_lock(fd, offset, whence, len) \lock_reg((fd), F_SETLK, F_UNLCK, (offset), (whence), (len))pid_tlock_test(int, int, off_t, int, off_t);/* {Prog locktest} */#defineis_read_lockable(fd, offset, whence, len) \(lock_test((fd), F_RDLCK, (offset), (whence), (len)) == 0)#defineis_write_lockable(fd, offset, whence, len) \(lock_test((fd), F_WRLCK, (offset), (whence), (len)) == 0)voiderr_dump(const char *, ...);/* {App misc_source} */voiderr_msg(const char *, ...);voiderr_quit(const char *, ...);voiderr_exit(int, const char *, ...);voiderr_ret(const char *, ...);voiderr_sys(const char *, ...);voidlog_msg(const char *, ...);/* {App misc_source} */voidlog_open(const char *, int, int);voidlog_quit(const char *, ...);voidlog_ret(const char *, ...);voidlog_sys(const char *, ...);voidTELL_WAIT(void);/* parent/child from {Sec race_conditions} */voidTELL_PARENT(pid_t);voidTELL_CHILD(pid_t);voidWAIT_PARENT(void);voidWAIT_CHILD(void);#endif/* _APUE_H */
之后在你的工作目录下新建一个apue目录,将apue.h移动到当前目录下。以后就在这个文件目录下开发即可,系统就会自动找到<apue.h文件了。最终结果如下图所示:
- apue.h及编程环境配置
- apue.h <<UNIX 环境高级编程>> 第二版 环境配置
- UNIX环境高级编程Apue.h文件的配置
- UNIX环境高级编程 apue.h头文件的配置
- UNIX环境高级编程 apue.h编译文件配置
- <<UNIX环境高级编程>>apue.h头文件的配置
- UNIX环境高级编程 apue.h头文件的配置
- Unix 环境高级编程第三版 配置 apue.h
- Unix 环境高级编程第三版 配置 apue.h
- Unix环境高级编程开篇-"apue.h"配置
- UNIX环境高级编程 apue.h头文件的配置
- UNIX环境高级编程 apue.h头文件的配置
- 【UNIX高级编程】关于UNIX编程环境的配置(apue.h和error.h)
- 《UNIX环境高级编程》apue.h问题
- unix环境高级编程 apue.h文件
- <UNIX环境高级编程>中的 "apue.h"
- Unix环境高级编程apue.h
- UNIX环境高级编程--“apue.h”问题
- RAC 10201 (error while loading shared libraries: libpthread.so.0)解决
- Windows环境下编译liblas库以读写Lidar文件
- python(2)-------The syntax of python
- dell装机bios问题 os install mode enable failed to detect one or more drives during post
- input事件的处理
- apue.h及编程环境配置
- python(3)------The object type of python
- InlineHook 通用
- 我排第几
- centos升级firefox
- MySql数据库基本操作方法【增】【删】【显示】【进入】
- AMF协议简介
- C++基础学习笔记----第一课补充(符号表)
- 写给想当程序员的朋友