我们在写Linux应用程序槐启时,有时候记不清某个系统函数的头文件,往往要么百度,要么查源码,这样做都不方便,费时费力。
其实,可以用一个命令搞定:man。
比如,我要查sleep函数的头文件,在终端下敲命令: man sleep ,输出信息:
并没有发现头文件!但是,请看红框里的内容,意思是当前显示的只是sleep手册的第1页,还有第3页绝此可以参考,继续输命令 man 3 sleep ,输出信息:
看红框中的内容,是不就看到sleep函数的头文件及函数原型铅宏如定义了!
查看read函数头文件,同样的,输入 man read ,直接可以查到:
是不是很方便啊!!!
调用好没 stat(),fstat(), lstat(), 等函数时,需要包含 #include <sys/stat.h>头文件,它包含了要用到一些数据类型,结构类型。例如:dev_t st_dev ID of device containing file
ino_t st_ino file serial number
mode_tst_modemode of file (see below)
nlink_t st_nlink number of links to the file
uid_t st_uid user ID of file
gid_t st_gid group ID of file
dev_t st_rdevdevice ID (if file is character or block special)
off_t st_sizefile size in bytes (if file is a regular file)
time_tst_atime time of last access
time_tst_mtime time of last data modification
time_tst_ctime time of last status change
用法:包含头文件:
#include <sys/types.h>
#include <sys/stat.h>
程蠢袜禅序里,需要时可调用下列函数,下面是函数原型
intchmod(const char *, mode_t)
intfchmod(int, mode_t)
intfstat(int, struct stat *)
intlstat(const char *, struct stat *)
intmkdir(const char *, mode_t)
intmkfifo(const char *, mode_t)
intmknod(const char *, mode_t, dev_t)
intstat(const char *, struct stat *)
int main(){
具带尘体的调用语句和程序可写在这里
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)