apue.h的获取与使用

来源:互联网 发布:java compare的用法 编辑:程序博客网 时间:2024/06/06 23:51
 

初学《UNIX环境高级编程》的朋友都会遇到一个问题,运行里面的实例(download: http://www.apuebook.com/)时就出现问题,提示 "错误:apue.h:没有那个文件或目录". apue.h是作者自定义的一个头文件,包括程序所需的常用头文件及出错处理函数。所以因该将它放入系统头文件中(Linux下是 /usr/include),这样gcc编译器就可以找到它了。

 先去那个网站downlowd apue 的 tar.gz包,然后解压至电脑中的某个目录,比如我的是在/home/user/下,然后进入解压目录apue.2e,修改 Make.defines.linux中的WKDIR=/home/xxx/apue.2e,为WKDIR=/home/user/apue.2e,这就是我们将要make的工作目录,然后再进入std目录,用vi打开linux.mk,将里面的nawk全部改为awk,可以使用这个命令 :%s/nawk/awk/g (注意前面有冒号)

 然后 make

 然后按下面的步骤做

 1. 超级用户权限登入 #cd /usr/include

 2. 将apue.h和error.c两个文件copy到该目录下。(apue.h位于 your_apue_path/inlcude ; error.c位于your_apue_path/lib )

 以我的了路径为例:

 #cp /home/ucfree/apue.2e/inlcude/apue.h .

 #cp /home/ucfree/apue.2e/lib/error.c . (实现apue.h中的出错处理函数)

 3. 编辑apue.h

 #vi apue.h

 在最后一行 #endif 前面添加一行 #include "error.c"

 :wq 保存,退出.

 

 这样你就可以运行下载的apue程序了.

 

 

STDIN_FILENO and STDOUT_FILENO are part of the POSIX standard defined in<unistd.h>.

 

the end-of-file character (usually Control-D).

 

 

getchar() is equivalent to getc(stdin). Never use gets(), use fgets() instead. A '/0' is stored after the last character in the buffer.

 

 

ferror() 它的一般调用形式为 ferroe(fp);如果ferror返回值为0(假),表示未出错。在执行fopen函数时,ferror函数的初始值自动置为0。

 

There are three primary functions for process control: fork,exec, and waitpid.

 

The call wait(&status) is equivalent to:

           waitpid(-1, &status, 0);

 

 

In figure1.7, deal with '/n'. Replace it with '/0'

 

abort()没有错误提示,c++中不释放任何变量。

exit(1)有错误提示,c++中不释放auto变量。

 

The header <sys/types.h> defines some implementation-dependent data types, called theprimitive system data types.

 

caddr_t  core address (Section 14.9)

clock_t  counter of clock ticks (process time) (Section 1.10)

comp_t  compressed clock ticks (Section 8.14)

dev_t  device numbers (major and minor) (Section 4.23)

fd_set  file descriptor sets (Section 14.5.1)

fpos_t  file position (Section 5.10)

gid_t  numeric group IDs

ino_t  i-node numbers (Section 4.14)

mode_t  file type, file creation mode (Section 4.5)

nlink_t  link counts for directory entries (Section 4.14)

off_t  file sizes and offsets (signed) (lseek,Section 3.6)

pid_t  process IDs and process group IDs (signed) (Sections 8.2 and 9.4)

ptrdiff_t  result of subtracting two pointers (signed)

rlim_t  resource limits (Section 7.11)

sig_atomic_t  data type that can be accessed atomically (Section 10.15)

sigset_t  signal set (Section 10.11)

size_t  sizes of objects (such as strings) (unsigned) (Section 3.7)

ssize_t  functions that return a count of bytes (signed) (read,write, Section 3.7)

time_t  counter of seconds of calendar time (Section 1.10)

uid_t  numeric user IDs

wchar_t  can represent all distinct character codes

原创粉丝点击