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;

View File

@@ -35,8 +35,6 @@ __RCSID("$NetBSD: fparseln.c,v 1.10 2009/10/21 01:07:45 snj Exp $");
#include <string.h>
#include <stdlib.h>
#define FLOCKFILE(fp)
#define FUNLOCKFILE(fp)
#define _DIAGASSERT(t)
static int isescaped(const char *, const char *, int);
@@ -104,7 +102,7 @@ fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
*/
nl = '\n';
FLOCKFILE(fp);
flockfile(fp);
while (cnt) {
cnt = 0;
@@ -151,7 +149,7 @@ fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
}
if ((cp = realloc(buf, len + s + 1)) == NULL) {
FUNLOCKFILE(fp);
funlockfile(fp);
free(buf);
free(ptr);
return NULL;
@@ -163,7 +161,7 @@ fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
buf[len] = '\0';
}
FUNLOCKFILE(fp);
funlockfile(fp);
free(ptr);
if ((flags & FPARSELN_UNESCALL) != 0 && esc && buf != NULL &&