From de153e7f50baa4ea7fac013f3b77b3a4fe314664 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 31 Oct 2000 05:20:53 +0000 Subject: Update. * stdio-common/Makefile (tests): Add tst-fmemopen. * stdio-common/tst-fmemopen.c: New file. Test case by Ben Collins . * libio/iofopncook.c (_IO_cookie_seek): Correct test for error. * libio/fmemopen.c (fmemopen_read): Return 0 at end of buffer. (fmemopen_write): Set errno at end of buffer. --- libio/fmemopen.c | 10 +++++++--- libio/iofopncook.c | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'libio') diff --git a/libio/fmemopen.c b/libio/fmemopen.c index 92df2e4..99670b5 100644 --- a/libio/fmemopen.c +++ b/libio/fmemopen.c @@ -69,6 +69,7 @@ * so I don't need the stream to add null characters on its own.) */ +#include #include #include #include @@ -96,7 +97,7 @@ fmemopen_read (void *cookie, char *b, size_t s) if (c->pos + s > c->size) { if (c->pos == c->size) - return -1; + return 0; s = c->size - c->pos; } @@ -123,7 +124,10 @@ fmemopen_write (void *cookie, const char *b, size_t s) if (c->pos + s + addnullc > c->size) { if (c->pos + addnullc == c->size) - return -1; + { + __set_errno (ENOSPC); + return -1; + } s = c->size - c->pos - addnullc; } @@ -142,7 +146,7 @@ fmemopen_write (void *cookie, const char *b, size_t s) int -fmemopen_seek (void *cookie, _IO_off64_t * p, int w) +fmemopen_seek (void *cookie, _IO_off64_t *p, int w) { _IO_off64_t np; fmemopen_cookie_t *c; diff --git a/libio/iofopncook.c b/libio/iofopncook.c index c016cfb..52e025b 100644 --- a/libio/iofopncook.c +++ b/libio/iofopncook.c @@ -76,7 +76,8 @@ _IO_cookie_seek (fp, offset, dir) return ((cfile->__io_functions.seek == NULL || (cfile->__io_functions.seek (cfile->__cookie, &offset, dir) - == (_IO_off64_t) -1)) + == -1) + || offset == (_IO_off64_t) -1) ? _IO_pos_BAD : offset); } -- cgit v1.1