How to catch file mode?
问题 I have to catch modes below: "rb" , "r+b" and "wb" . I tried to execute code (compiled) of this: #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int main() { FILE *file = fopen("data.bin", "r"); if (!file){ perror(""); return -1; } int fd = fileno(file); if (fcntl(fd, F_GETFL) == O_RDONLY){ printf("read only\n"); } // printf("%d\n", O_APPEND); fclose(file); return 0; } But gotten nothing printed. fcntl() returns integers like 32768, but I need macros from