This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v3] [BZ #12836] Make fmemopen(buf,size,"w+b") binary.
- From: Roland McGrath <roland at hack dot frob dot com>
- To: OndÅej BÃlka <neleai at seznam dot cz>
- Cc: "Joseph S. Myers" <joseph at codesourcery dot com>, libc-alpha at sourceware dot org
- Date: Thu, 23 May 2013 12:09:12 -0700 (PDT)
- Subject: Re: [PATCH v3] [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>
> * libio/Makefile (tests): Updated.
> * libio/test-fmemopen-bz12836.c: New file.
Write it like this:
* libio/test-fmemopen-bz12836.c: New file.
* libio/Makefile (tests): Add it.
> 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 test-fmemopen test-fmemopen-bz12836 tst-ext tst-ext2 \
This makes the line too long.
> --- a/libio/fmemopen.c
> +++ b/libio/fmemopen.c
> @@ -201,6 +201,7 @@ fmemopen (void *buf, size_t len, const char *mode)
> {
> cookie_io_functions_t iof;
> fmemopen_cookie_t *c;
> + int i;
Use C99-style 'for (int i = ...'.
> + for (i = 0; mode[i]; i++)
No implicit Boolean coercion! "mode[i] != '\0'"
> +static char buffer[] = "foobar";
> +static char s[] = "abc";
Put these inside the function.
Don't use extra spaces to align the = like that.
> + stream = fmemopen (buffer, strlen (buffer), "w+b");
Use sizeof on constant arrays.
> + fprintf (stream, s);
> + fclose (stream);
Indentation wrong here.
> + for (i = 0 ; i < strlen (s) ; i++)
Use sizeof. No spaces before ;.
> + printf ("Disagree at position %i.\n",i);
Space after comma.
> + if (buffer[strlen (s)] == '\0')
Use sizeof.
> + printf ("Not opened in binary mode.\n");
Use puts.