If 'w' mode is used with a provided buffer the fmemopen will try to find
the first null byte to set as maximum internal stream size. It should be
done only for append mode ('a').
Kudos for Stefan Liebler for finding this error on s390-32.
* libio/fmemopen.c (__fmemopen): Fix 'w' openmode with provided
buffer.
* stdio-common/tst-fmemopen2.c (do_test_with_buffer): Fix typo and
fail output information.
On x32, GCC 5.1 complains:
tst-fmemopen2.c: In function ‘do_test_without_buffer’:
tst-fmemopen2.c:124:15: error: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘off_t {aka long long int}’ [-Werror=format=]
printf ("FAIL: first ftello returned %ld, expected %zu\n", o, nstr);
^
tst-fmemopen2.c:135:15: error: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘off_t {aka long long int}’ [-Werror=format=]
printf ("FAIL: second ftello returned %ld, expected %zu\n", o, nbuf);
^
tst-fmemopen2.c:148:15: error: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘off_t {aka long long int}’ [-Werror=format=]
printf ("FAIL: third ftello returned %ld, expected %zu\n", o, nstr2);
^
tst-fmemopen2.c: In function ‘do_test_length_zero’:
tst-fmemopen2.c:183:15: error: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘off_t {aka long long int}’ [-Werror=format=]
printf ("FAIL: first ftello returned %ld, expected 0\n", o);
^
This patch silences GCC.
* stdio-common/tst-fmemopen2.c (do_test_without_buffer): Replace
%ld with %jd and cast to intmax_t.
(do_test_length_zero): Likewise.
This patch updates tst-fmemopen2 to check for fmemopen with NULL buffer
inputs and also refactor the code a bit.
The test relies on a POSIX compliant fmemopen implementation.
* stdio-common/tst-fmemopen2.c (do_test): Add test for NULL and zero
length buffers.
* stdio-common/tst-fmemopen.c (do_test): Refactor to use
test-skeleton.c.
2005-01-27 Jakub Jelinek <jakub@redhat.com>
* stdlib/tst-fmtmsg.c: Include stdlib.h.
* stdio-common/tst-fmemopen2.c: Include string.h.
* posix/execvp.c: Include stdbool.h.