mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-10-23 16:48:09 +02:00
Lock the file streams in fgetln() and fparseln()
The fparseln() function had the NetBSD uppercase macros stubbed out, so replace them with the actual stdio ones. The fgetln() function was missing any locking at all.
This commit is contained in:
@@ -50,6 +50,8 @@ fgetln(FILE *stream, size_t *len)
|
||||
struct filebuf *fb;
|
||||
ssize_t nread;
|
||||
|
||||
flockfile(stream);
|
||||
|
||||
/* Try to diminish the possibility of several fgetln() calls being
|
||||
* used on different streams, by using a pool of buffers per file. */
|
||||
fb = &fb_pool[fb_pool_cur];
|
||||
@@ -61,6 +63,9 @@ fgetln(FILE *stream, size_t *len)
|
||||
fb->fp = stream;
|
||||
|
||||
nread = getline(&fb->buf, &fb->len, stream);
|
||||
|
||||
funlockfile(stream);
|
||||
|
||||
/* Note: the getdelim/getline API ensures nread != 0. */
|
||||
if (nread == -1) {
|
||||
*len = 0;
|
||||
|
Reference in New Issue
Block a user