This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v4] [BZ #12836] Make fmemopen(buf,size,"w+b") binary.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: "Joseph S. Myers" <joseph at codesourcery dot com>, libc-alpha at sourceware dot org
- Date: Mon, 27 May 2013 13:31:49 +0200
- Subject: Re: [PATCH v4] [BZ #12836] Make fmemopen(buf,size,"w+b") binary.
- References: <20130509161648 dot GA31713 at domone dot kolej dot mff dot cuni dot cz> <Pine dot LNX dot 4 dot 64 dot 1305091636200 dot 25142 at digraph dot polyomino dot org dot uk> <20130514115947 dot GA7284 at domone dot kolej dot mff dot cuni dot cz> <20130520082527 dot GB32195 at domone dot kolej dot mff dot cuni dot cz> <20130523190913 dot 04DBA2C09E at topped-with-meat dot com> <20130524091603 dot GA10400 at domone dot kolej dot mff dot cuni dot cz>
ping
On Fri, May 24, 2013 at 11:16:03AM +0200, OndÅej BÃlka wrote:
> Added comments except
>
> On Thu, May 23, 2013 at 12:09:12PM -0700, Roland McGrath wrote:
> > > + for (i = 0 ; i < strlen (s) ; i++)
> >
> > Use sizeof. No spaces before ;.
> Here strlen is rigth in case that in future tests s contains 0.
>
> > > + printf ("Not opened in binary mode.\n");
> >
> > Use puts.
> Why?
>
>
> * libio/fmemopen.c (fmemopen): Make mode "w+b" binary.
> * libio/Makefile (tests): Add it.
> * libio/test-fmemopen-bz12836.c: New file.
>
> ---
> libio/Makefile | 3 +-
> libio/fmemopen.c | 5 +++-
> libio/test-fmemopen-bz12836.c | 50 +++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 56 insertions(+), 2 deletions(-)
> create mode 100644 libio/test-fmemopen-bz12836.c
>
> diff --git a/libio/Makefile b/libio/Makefile
> index e15cd40..9a373f2 100644
> --- a/libio/Makefile
> +++ b/libio/Makefile
> @@ -49,13 +49,14 @@ routines := \
> include ../Makeconfig
>
> tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \
> - tst_wprintf2 tst-widetext test-fmemopen tst-ext tst-ext2 \
> + tst_wprintf2 tst-widetext tst-ext tst-ext2 \
> tst-fgetws tst-ungetwc1 tst-ungetwc2 tst-swscanf tst-sscanf \
> tst-mmap-setvbuf bug-ungetwc1 bug-ungetwc2 tst-atime tst-eof \
> tst-freopen bug-rewind bug-rewind2 bug-ungetc bug-fseek \
> 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 test-fmemopen-bz12836 \
> tst-memstream1 tst-memstream2 \
> tst-wmemstream1 tst-wmemstream2 \
> bug-memstream1 bug-wmemstream1 \
> diff --git a/libio/fmemopen.c b/libio/fmemopen.c
> index 02c764f..813e677 100644
> --- a/libio/fmemopen.c
> +++ b/libio/fmemopen.c
> @@ -249,7 +249,10 @@ fmemopen (void *buf, size_t len, const char *mode)
> else
> c->pos = 0;
>
> - c->binmode = mode[0] != '\0' && mode[1] == 'b';
> + c->binmode = 0;
> + for (int i = 0; mode[i] != '\0'; i++)
> + if (mode[i] == 'b')
> + c->binmode = 1;
>
> iof.read = fmemopen_read;
> iof.write = fmemopen_write;
> diff --git a/libio/test-fmemopen-bz12836.c b/libio/test-fmemopen-bz12836.c
> new file mode 100644
> index 0000000..c346a36
> --- /dev/null
> +++ b/libio/test-fmemopen-bz12836.c
> @@ -0,0 +1,50 @@
> +/* Test for binary mode see bug 12836.
> + 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>
> +
> +int
> +do_test (void)
> +{
> + FILE *stream;
> + char buffer[] = "foobar";
> + char s[] = "abc";
> +
> + stream = fmemopen (buffer, sizeof (buffer), "w+b");
> + fprintf (stream, s);
> + fclose (stream);
> +
> + for (int i = 0; i < strlen (s) ; i++)
> + if (buffer[i] != s[i])
> + {
> + printf ("Disagree at position %i.\n", i);
> + return 1;
> + }
> +
> + if (buffer[strlen (s)] == '\0')
> + {
> + printf ("Not opened in binary mode.\n");
> + return 1;
> + }
> +
> + return 0;
> +}
> +
> +#include "../test-skeleton.c"
> --
> 1.7.4.4
--
Server depressed, needs Prozac
- References:
- [PATCH] [BZ #12836] Make fmemopen(buf,size,"w+b") binary.
- Re: [PATCH] [BZ #12836] Make fmemopen(buf,size,"w+b") binary.
- [PATCH v2] [BZ #12836] Make fmemopen(buf,size,"w+b") binary.
- Re: [PATCH v3] [BZ #12836] Make fmemopen(buf,size,"w+b") binary.
- Re: [PATCH v3] [BZ #12836] Make fmemopen(buf,size,"w+b") binary.
- Re: [PATCH v4] [BZ #12836] Make fmemopen(buf,size,"w+b") binary.