Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/stdio Implement nofollow (l) for fopen(3).



details:   https://anonhg.NetBSD.org/src/rev/ac72241e5549
branches:  trunk
changeset: 827574:ac72241e5549
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Nov 04 02:49:55 2017 +0000

description:
Implement nofollow (l) for fopen(3).

diffstat:

 lib/libc/stdio/flags.c |  18 +++++++++++-------
 lib/libc/stdio/fopen.3 |  24 ++++++++++++++++++------
 2 files changed, 29 insertions(+), 13 deletions(-)

diffs (106 lines):

diff -r e0f9a98dbbb1 -r ac72241e5549 lib/libc/stdio/flags.c
--- a/lib/libc/stdio/flags.c    Sat Nov 04 01:52:09 2017 +0000
+++ b/lib/libc/stdio/flags.c    Sat Nov 04 02:49:55 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: flags.c,v 1.17 2012/11/15 03:50:36 christos Exp $      */
+/*     $NetBSD: flags.c,v 1.18 2017/11/04 02:49:55 christos Exp $      */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)flags.c    8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: flags.c,v 1.17 2012/11/15 03:50:36 christos Exp $");
+__RCSID("$NetBSD: flags.c,v 1.18 2017/11/04 02:49:55 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -88,8 +88,9 @@
 
        /*
         * [rwa]\+ or [rwa]b\+ means read and write 
-        * f means open only plain files,
         * e means set close on exec.
+        * f means open only plain files.
+        * l means don't follow symlinks.
         * x means exclusive open.
         */
        for (; *mode; mode++)
@@ -98,17 +99,20 @@
                        ret = __SRW;
                        m = O_RDWR;
                        break;
-               case 'f':
-                       o |= O_NONBLOCK;
+               case 'b':
                        break;
                case 'e':
                        o |= O_CLOEXEC;
                        break;
+               case 'f':
+                       o |= O_NONBLOCK;
+                       break;
+               case 'l':
+                       o |= O_NOFOLLOW;
+                       break;
                case 'x':
                        o |= O_EXCL;
                        break;
-               case 'b':
-                       break;
                default:        /* We could produce a warning here */
                        break;
                }
diff -r e0f9a98dbbb1 -r ac72241e5549 lib/libc/stdio/fopen.3
--- a/lib/libc/stdio/fopen.3    Sat Nov 04 01:52:09 2017 +0000
+++ b/lib/libc/stdio/fopen.3    Sat Nov 04 02:49:55 2017 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: fopen.3,v 1.31 2015/07/15 19:08:43 christos Exp $
+.\"    $NetBSD: fopen.3,v 1.32 2017/11/04 02:49:55 christos Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -33,7 +33,7 @@
 .\"
 .\"     @(#)fopen.3    8.1 (Berkeley) 6/4/93
 .\"
-.Dd November 14, 2012
+.Dd November 3, 2017
 .Dt FOPEN 3
 .Os
 .Sh NAME
@@ -99,10 +99,12 @@
 .It Sq e
 The letter
 .Sq e
-in the mode string sets the close-on-exec flag in the file descriptors of
-the newly opened file files; if the operation fails,
-.Fn fopen
-will fail.
+in the mode string sets the close-on-exec 
+.Pq Dv O_CLOEXEC
+flag of the file descriptor, which means that it will not be available
+after an
+.Xr exec 2
+system call.
 This is a non
 .St -ansiC
 extension.
@@ -117,6 +119,16 @@
 This is a non
 .St -ansiC
 extension.
+.It Sq l
+The letter
+.Sq l
+in the mode string turns the don't-follow-symlinks
+.Pq Dv O_NOFOLLOW
+flag of the file descriptor, which means that if the last path component
+is a symbolic link, it will not be followed.
+This is a non
+.St -ansiC
+extension.
 .It Sq x
 The letter
 .Sq x



Home | Main Index | Thread Index | Old Index