This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 5/6] [BZ #12685] Allow arbitrary number of modes in fopen.
- From: Ondrej Bilka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Cc: Ondrej Bilka <neleai at seznam dot cz>
- Date: Sat, 1 Jun 2013 17:11:27 +0200
- Subject: [PATCH 5/6] [BZ #12685] Allow arbitrary number of modes in fopen.
- References: <1370099488-13916-1-git-send-email-neleai at seznam dot cz>
A followup to
http://sourceware.org/ml/libc-alpha/2013-05/msg00868.html
with improved and renamed testcase.
* libio/fileops.c (_IO_new_file_fopen): Allow arbitrary number of modes.
* libio/iofdopen.c (_IO_new_fdopen): Likewise.
* libio/bug-openmodes-parsing.c: New file.
* libio/Makefile (tests): Add bug-openmodes-parsing.
---
libio/Makefile | 4 ++--
libio/bug-openmodes-parsing.c | 47 +++++++++++++++++++++++++++++++++++++++++
libio/fileops.c | 6 ++----
libio/iofdopen.c | 6 ++----
4 files changed, 53 insertions(+), 10 deletions(-)
create mode 100644 libio/bug-openmodes-parsing.c
diff --git a/libio/Makefile b/libio/Makefile
index a68b0e9..e5553de 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -56,11 +56,11 @@ tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \
tst-mmap-eofsync tst-mmap-fflushsync bug-mmap-fflush \
tst-mmap2-eofsync tst-mmap-offend bug-fopena+ bug-wfflush \
bug-ungetc2 bug-ftell bug-ungetc3 bug-ungetc4 tst-fopenloc2 \
- test-fmemopen bug-fmemopen-openmode \
tst-memstream1 tst-memstream2 \
tst-wmemstream1 tst-wmemstream2 \
bug-memstream1 bug-wmemstream1 \
- bug-fmemopen1 \
+ test-fmemopen bug-fmemopen1 bug-fmemopen-openmode \
+ bug-openmodes-parsing \
tst-setvbuf1 tst-popen1 tst-fgetwc bug-wsetpos tst-fseek \
tst-fwrite-error
ifeq (yes,$(build-shared))
diff --git a/libio/bug-openmodes-parsing.c b/libio/bug-openmodes-parsing.c
new file mode 100644
index 0000000..f55c1e9
--- /dev/null
+++ b/libio/bug-openmodes-parsing.c
@@ -0,0 +1,47 @@
+/* Test for arbitrary number of arguments in open mode.
+ Copyright (C) 2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+int
+do_test (int argc, char **argv)
+{
+ FILE *stream, *stream2;
+
+ stream = fopen ("/dev/null", "rccccccccccccccccccccc+");
+
+ if (fputs ("x", stream) == EOF)
+ {
+ printf ("Stream not opened for writting.\n");
+ return 1;
+ }
+
+ stream2 = fdopen (fileno (stream), "rccccccccccccccccccccc+");
+
+ if (fputs ("x", stream2) == EOF)
+ {
+ printf ("Stream not opened for writting.\n");
+ return 1;
+ }
+ return 0;
+}
+
+#include "../test-skeleton.c"
diff --git a/libio/fileops.c b/libio/fileops.c
index 2931e2f..ba6a5dd 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -288,12 +288,10 @@ int is32not64;
#ifdef _LIBC
last_recognized = mode;
#endif
- for (i = 1; i < 7; ++i)
+ while (*++mode != '\0' && *mode != ',')
{
- switch (*++mode)
+ switch (*mode)
{
- case '\0':
- break;
case '+':
omode = O_RDWR;
read_write &= _IO_IS_APPENDING;
diff --git a/libio/iofdopen.c b/libio/iofdopen.c
index 2f8f202..6e14276 100644
--- a/libio/iofdopen.c
+++ b/libio/iofdopen.c
@@ -75,12 +75,10 @@ const char *mode;
MAYBE_SET_EINVAL;
return NULL;
}
- for (i = 1; i < 5; ++i)
+ while (*++mode != '\0' && *mode != ',')
{
- switch (*++mode)
+ switch (*mode)
{
- case '\0':
- break;
case '+':
read_write &= _IO_IS_APPENDING;
break;
--
1.7.10.4