Я хочу, чтобы флаги fd были открыты раньше в C.
Но я использую ссылку fcntl(fd,F_GETFD,0)
на справочной странице fcntl, она всегда возвращает мне 1.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#define XSZ(x) (int)(sizeof(x)*2)
int main()
{
int ret;
static const char str [] = "hello c program!\n";
int fd = open("test.txt", O_RDWR | O_APPEND | O_CREAT, 0777);
if(fd < 0)
{
perror("open");
return -1;
}
printf("fd = %d\n", fd);
ret = fcntl(fd, F_GETFD, 0);
printf("flag:%d\n",ret);
write(fd, str, strlen(str)-1);
return 0;
}
Он всегда печатает:
fd = 3
flag:1
То, что я думал, это сумма O_RDWR | O_APPEND | O_CREAT