Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "e" flag mean in fopen

Tags:

c

linux

fopen

I saw a code snippet using fopen(file_name, "r+e"). What does the e flag mean in fopen? I couldn't find any information from the linux man page.

like image 793
Jes Avatar asked Oct 19 '16 21:10

Jes


People also ask

What is the difference between open and fopen in C?

The key difference between the fopen() and the open() function in the Linux operating system is that the open() function is a low-level call, where the fopen() when called simply calls the open() function in the background and it returns a Filepointer directly.

Does fopen return a file descriptor?

The open function is the underlying primitive for the fopen and freopen functions, that create streams. Preliminary: | MT-Safe | AS-Safe | AC-Safe fd | See POSIX Safety Concepts. This function is similar to open . It returns a file descriptor which can be used to access the file named by filename .


2 Answers

On a GNU webpage I found that the e means that the "file descriptor will be closed if you use any of the exec… functions".

like image 90
Jenna Sloan Avatar answered Sep 27 '22 22:09

Jenna Sloan


It's documented in the man page on my system (release 3.54 of the Linux man-pages project).

e (since glibc 2.7)
Open the file with the O_CLOEXEC flag. See open(2) for more information. This flag is ignored for fdopen().

Scroll down; it's under "Glibc notes". This is a non-standard extension.

An online copy of the man page is here.

like image 20
Keith Thompson Avatar answered Sep 27 '22 22:09

Keith Thompson