请问以 0|O_CREAT|O_EXCL ,方式建立的文件, 再次打开时, 为何返回失败呢 ? 谢谢 。
代码如下
#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <stdio.h>#include <unistd.h>#include <limits.h>int main( int arg_num, char *arg[] ){// int fd = open("/home/dm/exercise/file1d2",0|O_CREAT|O_EXCL); int fd = open(*arg, 0); int max = sysconf(_SC_MQ_OPEN_MAX); max = sysconf(_SC_OPEN_MAX); if (fd == -1) { printf("open fail \n"); return 1; } printf("open ok %d", fd); printf("\n\n"); return 0;}//int open (const char *name, int flags);//int open (const char *name, int flags, mode_t mode);