From 42837a5b3c79bbd445cd797a684f997ed0448d41 Mon Sep 17 00:00:00 2001 From: christos Date: Thu, 15 Nov 2012 03:50:36 +0000 Subject: [PATCH] Add 'x' to the mode bits to specify O_EXCL, like glibc. --- lib/libc/stdio/flags.c | 8 ++++++-- lib/libc/stdio/fopen.3 | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/libc/stdio/flags.c b/lib/libc/stdio/flags.c index 1892d02e5e81..eac46f9a41ae 100644 --- a/lib/libc/stdio/flags.c +++ b/lib/libc/stdio/flags.c @@ -1,4 +1,4 @@ -/* $NetBSD: flags.c,v 1.16 2012/03/15 18:22:30 christos Exp $ */ +/* $NetBSD: flags.c,v 1.17 2012/11/15 03:50:36 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.16 2012/03/15 18:22:30 christos Exp $"); +__RCSID("$NetBSD: flags.c,v 1.17 2012/11/15 03:50:36 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -90,6 +90,7 @@ __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. + * x means exclusive open. */ for (; *mode; mode++) switch (*mode) { @@ -103,6 +104,9 @@ __sflags(const char *mode, int *optr) case 'e': o |= O_CLOEXEC; break; + case 'x': + o |= O_EXCL; + break; case 'b': break; default: /* We could produce a warning here */ diff --git a/lib/libc/stdio/fopen.3 b/lib/libc/stdio/fopen.3 index ec6db64356ae..d74b904065d3 100644 --- a/lib/libc/stdio/fopen.3 +++ b/lib/libc/stdio/fopen.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: fopen.3,v 1.28 2012/07/02 20:02:43 wiz Exp $ +.\" $NetBSD: fopen.3,v 1.29 2012/11/15 03:50:36 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 July 18, 2011 +.Dd November 14, 2012 .Dt FOPEN 3 .Os .Sh NAME @@ -117,6 +117,12 @@ will fail. This is a non .St -ansiC extension. +.It Sq x +The letter +.Sq x +in the mode turns on exclusive open mode to the file ( +.Dv O_EXCL ) +which means that the file will not be created if it already exists. .El .Pp Any created files will have mode