我在gcc中使用x86_64 GNU / Linux。
内容简介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);
现在,当我尝试编译以下代码片段时,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()
什么作用?
手册页可作为对程序员和编译器制造商的指导。
您可能不需要在系统中包括它们。但是,手册页描述了一种使用这些方法的可移植方式,因此无论如何都应包括它们。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句