Module Name: src Committed By: christos Date: Sat Nov 4 02:49:55 UTC 2017
Modified Files: src/lib/libc/stdio: flags.c fopen.3 Log Message: Implement nofollow (l) for fopen(3). To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/lib/libc/stdio/flags.c cvs rdiff -u -r1.31 -r1.32 src/lib/libc/stdio/fopen.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/stdio/flags.c diff -u src/lib/libc/stdio/flags.c:1.17 src/lib/libc/stdio/flags.c:1.18 --- src/lib/libc/stdio/flags.c:1.17 Wed Nov 14 22:50:36 2012 +++ src/lib/libc/stdio/flags.c Fri Nov 3 22:49:55 2017 @@ -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 @@ __sflags(const char *mode, int *optr) /* * [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 @@ __sflags(const char *mode, int *optr) 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; } Index: src/lib/libc/stdio/fopen.3 diff -u src/lib/libc/stdio/fopen.3:1.31 src/lib/libc/stdio/fopen.3:1.32 --- src/lib/libc/stdio/fopen.3:1.31 Wed Jul 15 15:08:43 2015 +++ src/lib/libc/stdio/fopen.3 Fri Nov 3 22:49:55 2017 @@ -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 @@ is ignored. .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 @@ will fail. 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