diff options
Diffstat (limited to 'lib/libc/stdio/fmemopen.c')
-rw-r--r-- | lib/libc/stdio/fmemopen.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/libc/stdio/fmemopen.c b/lib/libc/stdio/fmemopen.c index 581a91e..ebd3596 100644 --- a/lib/libc/stdio/fmemopen.c +++ b/lib/libc/stdio/fmemopen.c @@ -57,6 +57,14 @@ fmemopen(void * __restrict buf, size_t size, const char * __restrict mode) int flags, rc; /* + * POSIX says we shall return EINVAL if size is 0. + */ + if (size == 0) { + errno = EINVAL; + return (NULL); + } + + /* * Retrieve the flags as used by open(2) from the mode argument, and * validate them. */ @@ -119,14 +127,7 @@ fmemopen(void * __restrict buf, size_t size, const char * __restrict mode) */ switch (mode[0]) { case 'a': - if (ck->bin) { - /* - * This isn't useful, since the buffer isn't allowed - * to grow. - */ - ck->off = ck->len = size; - } else - ck->off = ck->len = strnlen(ck->buf, ck->size); + ck->off = ck->len = strnlen(ck->buf, ck->size); break; case 'r': ck->len = size; |