Looking at the man page for fopen
I cannot get a definite answer to this question.
FILE *fopen(const char *path, const char *mode);
I understand that fopen
returns a file pointer to a stream but is a file descriptor created as a byproduct? I am trying to make sure that I include the flag FD_CLOEXEC
on every instance a file descriptor is created. If a file descriptor is in fact created from fopen
what is the best way to use fnctl()
when there is no "fd" to use as input.
Thanks.
File descriptors are an index into a file-descriptor table stored by the kernel. The kernel creates a file-descriptor in response to an open call and associates the file-descriptor with some abstraction of an underlying file-like object; be that an actual hardware device, or a file-system or something else entirely.
The fopen() function opens the file specified by filename and associates a stream with it. The mode variable is a character string specifying the type of access requested for the file. The mode variable contains one positional parameter followed by optional keyword parameters.
a. Open a text file in append mode for writing at the end of the file. The fopen() function creates the file if it does not exist and is not a logical file.
The fopen() method in C is a library function that is used to open a file to perform various operations which include reading, writing etc. along with various modes.
On Unix (which I assume you're using because you're mentioning fcntl
) it does open a file descriptor, as fopen(3)
eventually calls open(2).
You can get that file descriptor via fileno(3)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With