roo*_*kea 6 c manpage system-calls header-files
我正在使用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);
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试编译以下代码片段时,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;
}
Run Code Online (Sandbox Code Playgroud)
那么,types.h和stat.h可选的?他们在manpage中的目的是什么open()?
手册页用作程序员和编译器制造商的指令.
您可能不需要将它们包含在系统中.但是,手册页描述了使用这些方法的可移植方式,因此无论如何都应该包含它们.