diff options
| author | christos <christos@NetBSD.org> | 2012-03-27 15:05:42 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2012-03-27 15:05:42 +0000 |
| commit | baad00d0c072d37cba2aa3aad2bcbb15c7b00d0e (patch) | |
| tree | 1ef0b1202c3bc828d646eb3f4204ad1ed3f19ceb /lib/libc/stdio/stdio.c | |
| parent | bae5d65144ba6010d073c3de6c63a476d6f792cf (diff) | |
- widen the internal read and write calls to match the syscalls
- add funopen2() which provides access to flush() and the wider calls.
- make use of the new flush call in fmemopen()
Diffstat (limited to 'lib/libc/stdio/stdio.c')
| -rw-r--r-- | lib/libc/stdio/stdio.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/lib/libc/stdio/stdio.c b/lib/libc/stdio/stdio.c index 72a0a0bde3d..bf5bb095bbc 100644 --- a/lib/libc/stdio/stdio.c +++ b/lib/libc/stdio/stdio.c @@ -1,4 +1,4 @@ -/* $NetBSD: stdio.c,v 1.20 2012/03/20 01:42:59 christos Exp $ */ +/* $NetBSD: stdio.c,v 1.21 2012/03/27 15:05:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)stdio.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: stdio.c,v 1.20 2012/03/20 01:42:59 christos Exp $"); +__RCSID("$NetBSD: stdio.c,v 1.21 2012/03/27 15:05:42 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -56,37 +56,40 @@ __RCSID("$NetBSD: stdio.c,v 1.20 2012/03/20 01:42:59 christos Exp $"); * Small standard I/O/seek/close functions. * These maintain the `known seek offset' for seek optimisation. */ -int -__sread(void *cookie, char *buf, int n) +ssize_t +__sread(void *cookie, void *buf, size_t n) { FILE *fp = cookie; ssize_t ret; - _DIAGASSERT(fp != NULL); + _DIAGASSERT(cookie != NULL); + _DIAGASSERT(cookie == fp->_cookie); _DIAGASSERT(buf != NULL); - ret = read(__sfileno(fp), buf, (size_t)n); + ret = read(__sfileno(fp), buf, n); /* if the read succeeded, update the current offset */ if (ret >= 0) fp->_offset += ret; else fp->_flags &= ~__SOFF; /* paranoia */ - return (int)ret; + return ret; } -int -__swrite(void *cookie, char const *buf, int n) +ssize_t +__swrite(void *cookie, const void *buf, size_t n) { FILE *fp = cookie; _DIAGASSERT(cookie != NULL); + _DIAGASSERT(cookie == fp->_cookie); _DIAGASSERT(buf != NULL); if (fp->_flags & __SAPP) - (void) lseek(__sfileno(fp), (off_t)0, SEEK_END); + if (lseek(__sfileno(fp), (off_t)0, SEEK_END) == (off_t)-1) + return -1; fp->_flags &= ~__SOFF; /* in case FAPPEND mode is set */ - return (int)write(__sfileno(fp), buf, (size_t)n); + return write(__sfileno(fp), buf, n); } off_t @@ -95,10 +98,11 @@ __sseek(void *cookie, off_t offset, int whence) FILE *fp = cookie; off_t ret; - _DIAGASSERT(fp != NULL); + _DIAGASSERT(cookie != NULL); + _DIAGASSERT(cookie == fp->_cookie); ret = lseek(__sfileno(fp), offset, whence); - if (ret == -1L) + if (ret == (off_t)-1L) fp->_flags &= ~__SOFF; else { fp->_flags |= __SOFF; @@ -110,8 +114,10 @@ __sseek(void *cookie, off_t offset, int whence) int __sclose(void *cookie) { + FILE *fp = cookie; _DIAGASSERT(cookie != NULL); + _DIAGASSERT(cookie == fp->_cookie); - return close(__sfileno((FILE *)cookie)); + return close(__sfileno(fp)); } |
