You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/06/07 17:22:35 UTC

[incubator-nuttx] 04/05: libc/stdio: Support 'e'(O_CLOEXEC) in lib_mode2oflags

This is an automated email from the ASF dual-hosted git repository.

pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit df0e9da1bad308c78d87169f04ceba147e8f2889
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Thu Jun 2 14:30:50 2022 +0800

    libc/stdio: Support 'e'(O_CLOEXEC) in lib_mode2oflags
    
    follow BSD and Linux convention:
    https://man.openbsd.org/fopen
    https://www.man7.org/linux/man-pages/man3/fopen.3.html
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 libs/libc/stdio/lib_fopen.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/libs/libc/stdio/lib_fopen.c b/libs/libc/stdio/lib_fopen.c
index 9798654735..537a92abca 100644
--- a/libs/libc/stdio/lib_fopen.c
+++ b/libs/libc/stdio/lib_fopen.c
@@ -49,7 +49,7 @@
 #define MODE_NONE 0        /* No access mode determined */
 #define MODE_MASK (MODE_R | MODE_W | MODE_A)
 
-#define FLAG_KEEP (O_BINARY | O_EXCL)
+#define FLAG_KEEP (O_BINARY | O_CLOEXEC | O_EXCL)
 
 /****************************************************************************
  * Public Functions
@@ -263,6 +263,21 @@ int lib_mode2oflags(FAR const char *mode)
               }
             break;
 
+          /* Open for close on execute */
+
+          case 'e' :
+            if ((state & MODE_MASK) != MODE_NONE)
+              {
+                /* The file will be closed on execute */
+
+                oflags |= O_CLOEXEC;
+              }
+            else
+              {
+                goto errout;
+              }
+            break;
+
           /* Open for exclusive access ("{r|w|a|b|+}x") */
 
           case 'x' :