int fd = open("float.txt", O_CREAT | O_WRONLY, 0600);
我知道0600与权限有关,但它究竟是如何工作的?
使用O_CREAT标志时,您需要使用3 param版本的open
:
int open(const char * pathname,int flags);
int open(const char * pathname,int flags,mode_t mode);
mode参数指定在创建新文件时应用的文件模式位。当在flags中指定O_CREAT或O_TMPFILE时,必须提供此参数;如果既未指定O_CREAT也未指定O_TMPFILE,则忽略mode。
试试这个:
int fd = open("float.txt", O_CREAT | O_WRONLY, S_IRUSR|S_IWUSR);