linux #include <systypes.h> 为什么有些头文件需要加SYS 有些不用加

linux #include <systypes.h> 为什么有些头文件需要加SYS 有些不用加,第1张

这要看你的 gcc 编译时命令行的参数了。

印象里是 -I/xxx/xxx/xxx 来设定头文件地址。

gcc 会固乱顷世定在这里以及他的默认头文件目录进行搜索(印象里默认是 /usr/include ,可以编译时进行设置,不光这一个的)。

如果你的头文件在这几个哗肢目录的子目录中,那就必须乎局设定 sys/ 这个目录前缀,不然 gcc 不会“聪明”的去子目录里查找(这么查找是会出乱子的)。

这个 types.h 有很多 devel 都提供,sys/types.h 应该是 glibc 提供的那个吧?

调用好没 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(){

具带尘体的调用语句和程序可写在这里

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/8221900.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存