1 /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
3 * GNU Library General Public License (LGPL) version 2 or later.
5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
11 /* Given a reading stream without its end-of-file indicator set and
12 * with no buffered input or ungots, read at most 'bufsize' bytes
13 * into 'buf' (which may be the stream's __bufstart).
14 * If a read error occurs, set the stream's error indicator.
15 * If EOF is encountered, set the stream's end-of-file indicator.
17 * Returns the number of bytes read, even in EOF and error cases.
20 * Calling with bufsize == 0 is NOT permitted (unlike __stdio_WRITE).
21 * NOT THREADSAFE! Assumes stream already locked if necessary.
24 size_t attribute_hidden __stdio_READ(register FILE *stream,
25 unsigned char *buf, size_t bufsize)
29 __STDIO_STREAM_VALIDATE(stream);
30 assert(stream->__filedes >= -1);
31 assert(__STDIO_STREAM_IS_READING(stream));
32 assert(!__STDIO_STREAM_BUFFER_RAVAIL(stream)); /* Buffer must be empty. */
33 assert(!(stream->__modeflags & __FLAG_UNGOT));
36 if (!__FEOF_UNLOCKED(stream)) {
37 if (bufsize > SSIZE_MAX) {
41 #ifdef __UCLIBC_MJN3_ONLY__
45 if ((rv = __READ(stream, (char *) buf, bufsize)) <= 0) {
47 __STDIO_STREAM_SET_EOF(stream);
49 /* if (errno == EINTR) goto RETRY; */
50 __STDIO_STREAM_SET_ERROR(stream);
53 #ifdef __UCLIBC_MJN3_ONLY__
54 #warning TODO: Make custom stream read return check optional.
56 #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
58 assert(rv <= bufsize);
59 if (rv > bufsize) { /* Read more than bufsize! */