summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/flags.c
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2011-10-21 06:35:58 +0000
committerdas <das@FreeBSD.org>2011-10-21 06:35:58 +0000
commit5f3b825f8d2f35ea764a3796ebb4a6e7c925111b (patch)
tree3befe32981ce5ae53b6fdbfe943a6e3e6d57a29a /lib/libc/stdio/flags.c
parente1b8286792be5d45abb83ece624e9059ae4f3285 (diff)
downloadFreeBSD-src-5f3b825f8d2f35ea764a3796ebb4a6e7c925111b.zip
FreeBSD-src-5f3b825f8d2f35ea764a3796ebb4a6e7c925111b.tar.gz
Add support for the 'x' mode option in fopen() as specified in the C1X
draft standard. The option is equivalent to O_EXCL. MFC after: 1 month
Diffstat (limited to 'lib/libc/stdio/flags.c')
-rw-r--r--lib/libc/stdio/flags.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/libc/stdio/flags.c b/lib/libc/stdio/flags.c
index 729b4d5..0b6b075 100644
--- a/lib/libc/stdio/flags.c
+++ b/lib/libc/stdio/flags.c
@@ -80,11 +80,30 @@ __sflags(mode, optr)
return (0);
}
- /* [rwa]\+ or [rwa]b\+ means read and write */
- if (*mode == '+' || (*mode == 'b' && mode[1] == '+')) {
+ /* 'b' (binary) is ignored */
+ if (*mode == 'b')
+ mode++;
+
+ /* [rwa][b]\+ means read and write */
+ if (*mode == '+') {
+ mode++;
ret = __SRW;
m = O_RDWR;
}
+
+ /* 'b' (binary) can appear here, too -- and is ignored again */
+ if (*mode == 'b')
+ mode++;
+
+ /* 'x' means exclusive (fail if the file exists) */
+ if (*mode == 'x') {
+ if (m == O_RDONLY) {
+ errno = EINVAL;
+ return (0);
+ }
+ o |= O_EXCL;
+ }
+
*optr = m | o;
return (ret);
}
OpenPOWER on IntegriCloud