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
>= -2);
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
) {
42 if ((rv
= __READ(stream
, (char *) buf
, bufsize
)) <= 0) {
44 __STDIO_STREAM_SET_EOF(stream
);
46 /* if (errno == EINTR) goto RETRY; */
47 __STDIO_STREAM_SET_ERROR(stream
);
50 #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
52 assert(rv
<= bufsize
);
53 if (rv
> bufsize
) { /* Read more than bufsize! */