在运行《UNIX环境高级编程》中的程序时会遇到apue.h包头找不到的情况,这是作者为了方便程序书写封闭了一些功能函数和错误处理等。在http://www.apuebook.com中可以下载到书的所有的实例代码,解压后为apue.2e。
进入网站,选择对应版本的资料

将 Source Code 下载

在linux下运行

tar -zxvf src.3e.tar.gz

会解压生成一个apue.3e的文件夹,将 include 文件夹下的apue.h和lib文件夹下的error.c 复制到/usr/include文件夹下,注意要用root权限~
1. su root,然后输入密码
2. 在apue.2e文件夹下执行 cp ./inlcude/apue.h /usr/include
3. 在apue.2e文件夹下执行 cp ./lib/error.c /usr/include
4. 修改apue.h文件,在文件末尾,在#endif前面加上#include “error.c”,执行vim /usr/include/apue.h,然后加上#include “error.c”就可以了

/* Our own header, to be included before all standard system headers */  #ifndef _APUE_H
#define _APUE_H  #if defined(SOLARIS)
#define _XOPEN_SOURCE   500 /* Single UNIX Specification, Version 2  for Solaris 9 */
#define CMSG_LEN(x) _CMSG_DATA_ALIGN(sizeof(struct cmsghdr)+(x))
#elif !defined(BSD)
#define _XOPEN_SOURCE   600 /* 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 */  #define MAXLINE 4096            /* max line length */  /* * Default file access permissions for new files. */
#define FILE_MODE   (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)  /* * Default permissions for new directories. */
#define DIR_MODE    (FILE_MODE | S_IXUSR | S_IXGRP | S_IXOTH)  typedef void    Sigfunc(int);   /* for signal handlers */  #if defined(SIG_IGN) && !defined(SIG_ERR)
#define SIG_ERR ((Sigfunc *)-1)
#endif  #define min(a,b)    ((a) < (b) ? (a) : (b))
#define max(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} */
#ifdef  ECHO    /* only if <termios.h> has been included */
struct termios  *tty_termios(void);     /* {Prog raw} */
#endif  void     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} */
#ifdef  TIOCGWINSZ
pid_t    pty_fork(int *, char *, int, const struct termios *,  const struct winsize *);      /* {Prog ptyfork} */
#endif  int     lock_reg(int, int, int, off_t, int, off_t); /* {Prog lockreg} */
#define read_lock(fd, offset, whence, len) \  lock_reg((fd), F_SETLK, F_RDLCK, (offset), (whence), (len))
#define readw_lock(fd, offset, whence, len) \  lock_reg((fd), F_SETLKW, F_RDLCK, (offset), (whence), (len))
#define write_lock(fd, offset, whence, len) \  lock_reg((fd), F_SETLK, F_WRLCK, (offset), (whence), (len))
#define writew_lock(fd, offset, whence, len) \  lock_reg((fd), F_SETLKW, F_WRLCK, (offset), (whence), (len))
#define un_lock(fd, offset, whence, len) \  lock_reg((fd), F_SETLK, F_UNLCK, (offset), (whence), (len))  pid_t   lock_test(int, int, off_t, int, off_t);     /* {Prog locktest} */  #define is_read_lockable(fd, offset, whence, len) \  (lock_test((fd), F_RDLCK, (offset), (whence), (len)) == 0)
#define is_write_lockable(fd, offset, whence, len) \  (lock_test((fd), F_WRLCK, (offset), (whence), (len)) == 0)  void    err_dump(const char *, ...);        /* {App misc_source} */
void    err_msg(const char *, ...);
void    err_quit(const char *, ...);
void    err_exit(int, const char *, ...);
void    err_ret(const char *, ...);
void    err_sys(const char *, ...);  void    log_msg(const char *, ...);         /* {App misc_source} */
void    log_open(const char *, int, int);
void    log_quit(const char *, ...);
void    log_ret(const char *, ...);
void    log_sys(const char *, ...);  void    TELL_WAIT(void);        /* parent/child from {Sec race_conditions} */
void    TELL_PARENT(pid_t);
void    TELL_CHILD(pid_t);
void    WAIT_PARENT(void);
void    WAIT_CHILD(void);  #include "error.c"  #endif  /* _APUE_H */  

Unix——学习《Unix环境高级编程》找不到“apue.h”方法相关推荐

  1. UNIX 环境高级编程(一) apue.h 文件与apue.3e的安装

    apue:Advanced Programming in the UNIX Environment, 本文关注第三版(3e) 1. apue.3e 的安装 APUE.3e 安装(基于ubuntu12. ...

  2. linux环境编程 学习,学习linux环境高级编程首先学习的是文件的操作。因为有.pdf...

    学习linux环境高级编程首先学习的是文件的操作.因为有 学习 Linux 环境高级编程,首先学习的是文件的操作.因为有一句很有趣的话"Linux 下一切皆文件".所以掌握了文件操 ...

  3. UNIX 环境高级编程(五)—— unistd.h

    1. POSIX POSIX 表示可移植操作系统接口(Portable Operating System Interface ,缩写为 POSIX ),POSIX 标准定义了操作系统应该为应用程序提供 ...

  4. UNIX 环境高级编程(四)—— dirent.h

    dirent.h 是 POSIX.1 标准定义的 unix 类目录操作的头文件,包含了许多 UNIX 系统服务的函数原型,例如 opendir 函数.readdir 函数. 1. 基本函数接口 1.1 ...

  5. Unix环境高级编程 centos中配置apue编译环境

    首先保证操作系统中已经安装好了gcc, 将apue.2e解压后拷贝到linux操作系统中,然后输入 [root@localhost apue.2e]# cd lib 进入apue.2e的lib文件夹, ...

  6. UNIX环境高级编程笔记之文件I/O

    一.总结 在写之前,先唠几句,<UNIX环境高级编程>,简称APUE,这本书简直是本神书,像我这种小白,基本上每看完一章都是"哇"这种很吃惊的表情.其实大概三年前,那会 ...

  7. 5w字总结 Unix系统编程学习笔记(面试向)(Unix环境高级编程/Unix环境程序设计)

    文章目录 一.计算 C语言的数据表示与处理 计算 C语言的基本运算操作 内存表和符号表 类型转换 函数类型的分析 指令 复合指令 句法 函数 函数激活(Activation Record) 函数激活定 ...

  8. 《Unix环境高级编程》学习笔记:从点到面

    以前在课堂上学习过<Unix初级教程(第四版)>,对于Unix有了一点了解.由于以后使用的需要,要对它进行比较深入的学习,为此需要阅读不少的书籍,这本<Unix环境高级编程>便 ...

  9. 《UNIX 环境高级编程》学习笔记—— 标准I/O库

    UNIX环境高级编程--标准I/O库 流和 FILE 对象 标准输入.标准输出和标准错误 缓冲 打开流 读和写流 每次一行 I/O 二进制 I/O 定位流 格式化 I/O 临时文件 内存流 流和 FI ...

最新文章

  1. Hadoop版本:CDH, HDP, MapR
  2. 阿里百川与极客邦科技达成战略合作 Weex宣布开源
  3. Java将网络地址对应的图片转成本地的图片
  4. SpringBoot_web开发-【实验】-登陆拦截器
  5. 40.Node.js Web 模块
  6. local service system账户_systemd.service学习和使用总结
  7. ios 后台唤醒应用_苹果不用背锅了!微信被杀后台是因为“耍流氓”?用户该听谁的?...
  8. 少编码多思考:代码越多 问题越多
  9. 3des 解密 java_◆JAVA加密解密-3DES
  10. 逆袭?或将掌舵万亿SaaS巨头的Taylor竟是“天选之人”
  11. 通俗易懂的Android root 原理
  12. Distribute Strategy--翻译学习
  13. 使用Python获取股市融资融券数据并绘制曲线
  14. subclipse 下载地址
  15. mac开机启动mysql_新Mac 开机启动MySQL/MongoDB/Redis 等服务
  16. mac 安装 qt5 for tsmuxer
  17. 在外企工作三年的高手 给大家一些英语学习得建议和忠告
  18. php网络通讯,Linux_网络通讯--efax,功能说明:收发传真。 语  - phpStudy
  19. android复制短信到sim,Android开发之关于复制短信到SIM卡的分析.docx
  20. Win7安装系统,无猫腻

热门文章

  1. 06_Influxdb+Grafana绘图基础
  2. python 上传excel_简历批量合并Python+VBA小工具
  3. Mybatis(20)注解实现二级缓存
  4. bootstrapV4.6.0实现标签页(改造v3.3.7)- 代码篇
  5. highCharts文档与演示效果的使用 - 文档(应用型)解读
  6. 零基础,快速安装dedeCMS 搭建网站 - 总结大全
  7. mfc指示灯报警显示_常用汽车仪表指示灯大全,看完再也不用担心不认识了
  8. ubuntu共享文件夹文件看不到_实验08:轻松搭建文件夹共享
  9. PHP二开 三语言( 中文、英语、马来语) 自动抢单系统源码
  10. 信恒支付源码-第四方支付源码