Started with system calls in C.
Goal -> To get the opening modes of a file using fcntl
Code written ->
#include<stdio.h>
#include<fcntl.h>
int main()
{
int fd , open_fl;
if((fd =open("example.txt",O_RDWR ))<0){
perror("program");
}
open_fl = fcntl(fd , F_GETFL );
printf("%d file descriptor has %d flags.\n", fd , open_fl);
return 0 ;
}
Getting Output ->
3 file descriptor has 32770 flags.
32770(decimal) -> 100002(octal)
But expected octal value is 2.
source fcntl.h code -> https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/fcntl.h
Why am i getting such an output difference?
You are getting back o100002, which is a combination of the O_RDWR (o2) and O_LARGEFILE (o100000) flags.
The manpage for open() says: