Просмотр исходного кода

stdio: make an open_memstream byte-oriented, as POSIX requires

POSIX: "The stream associated with a call to open_memstream() shall be
byte-oriented."  fopencookie() leaves a new stream unoriented, so fwide(f, 0)
answered 0 instead of a negative value and the first wide operation could have
turned the stream wide.

__STDIO_STREAM_SET_NARROW() is a no-op when UCLIBC_HAS_WCHAR is off, where
there is no orientation to set, so no guard is needed.

fmemopen() is deliberately left alone: its POSIX page says nothing about
orientation.

Found by tst-fmemopen in uclibc-ng-test, which now walks the whole
open_memstream description.

Signed-off-by: Ramin Moussavi <lordrasmus@gmail.com>
ramin 3 дней назад
Родитель
Сommit
fe22402bbd
1 измененных файлов с 4 добавлено и 0 удалено
  1. 4 0
      libc/stdio/open_memstream.c

+ 4 - 0
libc/stdio/open_memstream.c

@@ -188,6 +188,10 @@ FILE *open_memstream(char **bufloc, size_t *sizeloc)
 		 * nothing currently in the FILE's write buffer. */
 
 		if (fp != NULL) {
+			/* POSIX: "The stream associated with a call to
+			 * open_memstream() shall be byte-oriented."  fopencookie()
+			 * leaves it unoriented. */
+			__STDIO_STREAM_SET_NARROW(fp);
 			__STDIO_STREAM_VALIDATE(fp);
 			return fp;
 		}