APUE 头文件 "apue.h" 中包含的头文件解释

来源:互联网 发布:系统部署和网络拓扑图 编辑:程序博客网 时间:2024/05/16 19:13

重读 APUE,这次的任务是要弄清楚一些细节问题,首先就是所包含的头文件

#include <sys/types.h>#include <sys/stat.h>#include <sys/termios.h>#include <sys/ioctl.h>#include <stdio.h>#include <stdlib.h>#include <stddef.h>#include <string.h>#include <signal.h>

sys/types.h
1. clock_t 表示系统时间(以时钟周期为单位)
typedef long clock_t; /* relative time in a specified resolution */
2. dev_t 用于设备号
typedef ulong_t dev_t; /* expanded device type */
3. time_t 以秒为单位计时
typedef long time_t; /* time of day in seconds */
4. size_t 反映内存中对象的大小(以字节为单位)
5. ssize_t 供返回字节计数或错误提示的函数使用
typedef long ssize_t; /* size of something in bytes or -1 */
6. pid_t 进程ID和进程组ID
typedef int pid_t; /* process id type */
7. fd_set 文件描述符集

sys/stat.h
文件注释中说明:data returned by stat() function

int stat(const char *restrict pathname,struct stat *restrict buf);int fstat(int fields,struct stat *buf);int lstat(const char *restrict pathname,struct stat *restrict buf);

一旦给出pathname,stat函数就返回与此命名文件有关的信息结构,fstat函数获取已在描述符fields上打开文件的有关信息。
lstat函数类似于stat.但是当命名的文件是一个符号链接时,lstat返回该符号链接的有关信息,而不是由该符号链接引用文件的信息。第二个参数buf是指针,它指向一个我们必须提供的结构,这些函数填写由buf指向的结构。该结构的实际定义可能随实现有所不同.

struct stat{    mode_t st_mode; //文件类型和权限信息    ino_t st_ino; //i结点标识    dev_t st_dev; //device number (file system)    dev_t st_rdev; //device number for special files    nlink_t st_nlink; //符号链接数    uid_t st_uid; //用户ID    gid_t st_gid; //ID    off_t st_size; //size in bytes,for regular files    time_t st_st_atime; //最后一次访问的时间    time_t st_mtime; //文件内容最后一次被更改的时间    time_t st_ctime; //文件结构最后一次被更改的时间    blksize_t st_blksize; //best I/O block size    blkcnt_t st_blocks; //number of disk blocks allocated};

stat系列函数返回的不是结构体指针,而是成功 0,出错 -1,通过第二个参数 buf 返回 stat 结构体,并通过这个结构体获得该文件的一个快照信息。

sys/termios.h
这个文件在 “apue.h” 中的注释就是 for winsize 控制窗口的大小,这个文件的描述是用于终端 IO。暂用不上,不过以后编写复杂的控制台终端应用也许会用到,所以留坑待填。

sys/ioctl.h
这个在设备驱动中见到过,其他领域没有用过,同样以后会用到,留坑待填

stdlib.h
这个是标准库头文件,其中包含诸多函数和类型
1. size_t
This is the unsigned integral type and is the result of the sizeof keyword.
即 sizeof 关键字返回的表示对象在内存中大小的类型(字节为单位)
2. wchar_t
This is an integer type of the size of a wide character constant.
表示宽字节常量,如UNICODE编码中的字符
3. div_t
This is the structure returned by the div function.
4.ldiv_t
This is the structure returned by the ldiv function.

以及一些常用的函数如常用的函数如malloc()、calloc()、realloc()、free()、system()、atoi()、atol()、rand()、srand()、exit()等等

定义的常量如
1. NULL
This macro is the value of a null pointer constant.
2. EXIT_FAILURE
This is the value for the exit function to return in case of failure.
3. EXIT_SUCCESS
This is the value for the exit function to return in case of success.
4. RAND_MAX
This macro is the maximum value returned by the rand function.
随机数函数所能返回的最大值
5. MB_CUR_MAX
This macro is the maximum number of bytes in a multi-byte character set which cannot be larger than MB_LEN_MAX.

这里的 atof(), atoi(), atol(), strtod(), strtol(), qsort() 等函数值得日后再来复习

stddef.h
注释中写为了使用 offsetof 函数

unistd.h
对于类 Unix 系统,unistd.h 中所定义的接口通常都是大量针对系统调用的封装(英语:wrapper functions),如 fork、pipe 以及各种 I/O 原语(read、write、close 等等)。

0 0
原创粉丝点击