在Ubuntu上无法通过fcntl设置O_SYNC

如题,看如下测试代码:

#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/fcntl.h> #include <stdlib.h> int main(int argc, char *argv[]) { int fd=open("data", O_RDWR|O_CREAT, 0777); if(fd<0) { perror("open error!/n"); exit(-1); } int var =fcntl(fd, F_GETFL); var|=O_SYNC; int ret=fcntl(fd, F_SETFL); if(ret<0) { perror("fcntl"); exit(-1); } var=fcntl(fd, F_GETFL); if(var&O_SYNC) { printf("O_SYNC/n"); } close(fd); return 0; } 

 

看看man手册的说明:

F_SETFL (long)

              Set the file status flags to the value specified by arg.  File access mode (O_RDONLY, O_WRONLY, O_RDWR) and

              file creation flags (i.e., O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC) in arg are ignored.  On Linux  this  command

              can only change the O_APPEND, O_ASYNC, O_DIRECT, O_NOATIME, and O_NONBLOCK flags.

 

你可能感兴趣的:(linux,ubuntu,File,command,测试,Access)