头文件一般位于usr/include目录下,各个子类的头文件位于include子目录下
不知道某个“库函数”需要哪些头文件,使用“man 函数”即可查看
在应用程序源文件中包含 <sys/types.h> 以访问 _LP64 和 _ILP32 的定义。此头文件还包含适当时应使用的多个基本派生类型。尤其是以下类型更为重要:
clock_t 表示系统时间(以时钟周期为单位)。
dev_t 用于设备号。
off_t 用于文件大小和偏移量。
ptrdiff_t 是一种带符号整型,用于对两个指针执行减法运算后所得的结果。
size_t 反映内存中对象的大小(以字节为单位)。
ssize_t 供返回字节计数或错误提示的函数使用。
time_t 以秒为单位计时。
所有这些类型在 ILP32 编译环境中保持为 32 位值,并会在 LP64 编译环境中增长为 64 位值。
//
包含的头文件stat.h在系统目录的sys目录下
stat.h头文件,轻松获取文件属性
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
};
#include <linux/kernel.h> 驱动要写入内核,与内核相关的头文件
#include <linux/fs.h> 文件系统头文件
#include <linux/init.h> 初始化头文件
#include <linux/delay.h> 延时头文件
#include <asm/irq.h> 与处理器相关的中断
#include <linux/interrupt.h> 操作系统中断
#include <asm/uaccess.h> 与处理器相关的入口
//#include <asm/arch/regs-gpio.h> 与处理器相关的IO口操作
#include <mach/regs-gpio.h> 同上
//#include <asm/hardware.h> 与处理器相关的硬件
#include <mach/hardware.h> 同上
#include <linux/device.h> 设备驱动文件
#include <linux/poll.h> 轮询文件
#include <linux/gpio.h> 操作系统相关的IO口文件
#include <stdio.h> 标准输入输出
#include <stdlib.h> 标准库
#include <unistd.h>
#include <sys/ioctl.h> IO控制
以下6个是提供的函数中所需的头文件
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>