1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-10-28 23:34:53 +03:00

libio: Implement internal function __libc_readline_unlocked

This is a variant of fgets which fails with ERANGE if the
buffer is too small, and the buffer length is given as an
argument of type size_t.

This function will be useful for implementing NSS file reading
operations.  Compared to a direct implementation using the public API,
it avoids an lseek system call in case the line terminator can be
found in the internal read buffer.
This commit is contained in:
Florian Weimer
2018-07-06 16:53:48 +02:00
parent 397c54c1af
commit 3f5e3f5d06
10 changed files with 471 additions and 9 deletions

View File

@@ -127,6 +127,19 @@ extern int __fxprintf (FILE *__fp, const char *__fmt, ...)
extern int __fxprintf_nocancel (FILE *__fp, const char *__fmt, ...)
__attribute__ ((__format__ (__printf__, 2, 3))) attribute_hidden;
/* Read the next line from FP into BUFFER, of LENGTH bytes. LINE will
include the line terminator and a NUL terminator. On success,
return the length of the line, including the line terminator, but
excluding the NUL termintor. On EOF, return zero and write a NUL
terminator. On error, return -1 and set errno. If the total byte
count (line and both terminators) exceeds LENGTH, return -1 and set
errno to ERANGE (but do not mark the stream as failed).
The behavior is undefined if FP is not seekable, or if the stream
is already in an error state. */
ssize_t __libc_readline_unlocked (FILE *fp, char *buffer, size_t length);
libc_hidden_proto (__libc_readline_unlocked);
extern const char *const _sys_errlist_internal[] attribute_hidden;
extern int _sys_nerr_internal attribute_hidden;
@@ -170,6 +183,10 @@ libc_hidden_proto (fwrite)
libc_hidden_proto (fseek)
extern __typeof (ftello) __ftello;
libc_hidden_proto (__ftello)
extern __typeof (fseeko64) __fseeko64;
libc_hidden_proto (__fseeko64)
extern __typeof (ftello64) __ftello64;
libc_hidden_proto (__ftello64)
libc_hidden_proto (fflush)
libc_hidden_proto (fflush_unlocked)
extern __typeof (fflush_unlocked) __fflush_unlocked;