1. sys/types.h
定义了常见的数据类型,如pid_t, time_t, off_t等
2. limits.h
3. fcntl.h
文件相关库文件,与unistd.h配合使用,如定义了open函数
范例:
ssize_t size;
int fd;
char s[] = "linux programmer \n", buffer[80];
fd = open("/Users/yuanchangjun/html/hello_c/src/test", O_WRONLY | O_CREAT | O_EXCL);
if (fd == -1) {
perror("open:");
exit(0);
}
size = write(fd, s, sizeof(s));
if (size == -1) {
perror("write:");
exit(0);
}
close(fd);
4.sys/stat.h
获取文件相关信息的库文件,提供stat、fstat等函数
范例:
struct stat finfo;
int fd;
stat("/Users/yuanchangjun/html/hello_c/src/test", &finfo);
printf("size:%lld", finfo.st_size);
if (S_ISREG(finfo.st_mode) == 1) {
printf("is file");
}else if(S_ISDIR(finfo.st_mode) == 1) {
printf("is dir");
}