【发布时间】:2015-04-20 22:39:54
【问题描述】:
我正在使用 x86_64 GNU/Linux 和 gcc。man -s2 open 的概要部分说:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
int creat(const char *pathname, mode_t mode);
现在,当我尝试编译以下代码 sn-p 时,gcc 不会引发警告/错误。
#include <stdio.h>
#include <fcntl.h>
int main(int argc, char **argv)
{
int fd;
fd = open("foo.txt", O_RDWR, 0777);
if(fd == -1)
perror("open");
fd = creat("foo.txt", 0777);
if(fd == -1)
perror("creat");
close(fd);
return 0;
}
那么types.h 和stat.h 是可选的吗?它们在open() 的联机帮助页中有什么用途?
【问题讨论】:
-
检查
fcntl.h-- 我假设它包括types.h和stat.h -
它包括
<bits/types.h>和<bits/stat.h>。但是我还是不明白为什么<sys/types.h>和<sys/stat.h>在man -s2 open里面。 -
既然你没有说明,你是用
-Wall编译的吗?如果没有,请执行此操作并检查是否有警告。
标签: c header-files system-calls manpage