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:
Guillem Jover
2015-09-23 07:10:18 +02:00
parent ee26e59e72
commit 0982dcd98b
2 changed files with 8 additions and 5 deletions

View File

@@ -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;