[git commit] stdio: add support for "e" flag with fopen()

Mike Frysinger vapier at gentoo.org
Sun Nov 20 07:47:50 UTC 2011


commit: http://git.uclibc.org/uClibc/commit/?id=117a32a63b837730cc97b0a233ab46e9abc6c7a7
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/master

Support this useful glibc extension for optionally setting O_CLOEXEC
on fopen streams.

Signed-off-by: Mike Frysinger <vapier at gentoo.org>
---
 extra/Configs/Config.in |    9 +++++++++
 libc/stdio/_fopen.c     |    9 ++++++++-
 2 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in
index 0f0ccfe..97aafb7 100644
--- a/extra/Configs/Config.in
+++ b/extra/Configs/Config.in
@@ -1722,6 +1722,15 @@ config UCLIBC_HAS_FOPEN_EXCLUSIVE_MODE
 
 	  Most people will answer N.
 
+config UCLIBC_HAS_FOPEN_CLOSEEXEC_MODE
+	bool "Support an fopen() 'e' flag for close-on-exec mode (glibc-compat)"
+	help
+	  Answer Y to support a glibc extension to allow passing
+	  additional 'e' flag in the mode string for fopen() to specify that
+	  the file should be open()ed with the O_CLOEXEC flag set.
+
+	  Most people will answer N.
+
 config UCLIBC_HAS_GLIBC_CUSTOM_STREAMS
 	bool "Support fmemopen(), open_memstream(), and fopencookie() (glibc-compat)"
 	help
diff --git a/libc/stdio/_fopen.c b/libc/stdio/_fopen.c
index 2db27a8..5bc61cf 100644
--- a/libc/stdio/_fopen.c
+++ b/libc/stdio/_fopen.c
@@ -69,7 +69,8 @@ FILE attribute_hidden *_stdio_fopen(intptr_t fname_or_mode,
 #warning CONSIDER: Implement glibc mmap option for readonly files?
 #warning CONSIDER: Implement a text mode using custom read/write funcs?
 #endif
-#if defined(__UCLIBC_HAS_FOPEN_EXCLUSIVE_MODE__) || defined(__UCLIBC_HAS_FOPEN_LARGEFILE_MODE__)
+#if defined(__UCLIBC_HAS_FOPEN_EXCLUSIVE_MODE__) || defined(__UCLIBC_HAS_FOPEN_LARGEFILE_MODE__) || \
+    defined(__UCLIBC_HAS_FOPEN_CLOSEEXEC_MODE__)
 
 	while (*++mode) {
 # ifdef __UCLIBC_HAS_FOPEN_EXCLUSIVE_MODE__
@@ -84,6 +85,12 @@ FILE attribute_hidden *_stdio_fopen(intptr_t fname_or_mode,
 			continue;
 		}
 # endif
+# ifdef __UCLIBC_HAS_FOPEN_CLOSEEXEC_MODE__
+		if (*mode == 'e') {		/* Close on exec (a glibc extension). */
+			open_mode |= O_CLOEXEC;
+			continue;
+		}
+# endif
  	}
 
 #endif


More information about the uClibc-cvs mailing list