Switch fparseln() implementation from fgetln() to getline()

This commit is contained in:
Guillem Jover 2014-12-13 21:28:36 +01:00
parent f50b197ea5
commit 53d989a223
2 changed files with 12 additions and 6 deletions

View File

@ -126,9 +126,9 @@ is returned.
The
.Fn fparseln
function uses internally
.Xr fgetln 3 ,
.Xr getline 3 ,
so all error conditions that apply to
.Xr fgetln 3 ,
.Xr getline 3 ,
apply to
.Fn fparseln .
In addition
@ -141,7 +141,7 @@ and return
.Dv NULL
if it runs out of memory.
.Sh SEE ALSO
.Xr fgetln 3
.Xr getline 3
.Sh HISTORY
The
.Fn fparseln

View File

@ -77,7 +77,8 @@ fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
{
static const char dstr[3] = { '\\', '\\', '#' };
size_t s, len;
ssize_t s;
size_t len, ptrlen;
char *buf;
char *ptr, *cp;
int cnt;
@ -87,6 +88,8 @@ fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
len = 0;
buf = NULL;
ptrlen = 0;
ptr = NULL;
cnt = 1;
if (str == NULL)
@ -97,7 +100,7 @@ fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
com = str[2];
/*
* XXX: it would be cool to be able to specify the newline character,
* but unfortunately, fgetln does not let us
* getdelim(3) does let us, but supporting it would diverge from BSDs.
*/
nl = '\n';
@ -109,7 +112,8 @@ fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
if (lineno)
(*lineno)++;
if ((ptr = fgetln(fp, &s)) == NULL)
s = getline(&ptr, &ptrlen, fp);
if (s < 0)
break;
if (s && com) { /* Check and eliminate comments */
@ -149,6 +153,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);
free(buf);
free(ptr);
return NULL;
}
buf = cp;
@ -159,6 +164,7 @@ fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
}
FUNLOCKFILE(fp);
free(ptr);
if ((flags & FPARSELN_UNESCALL) != 0 && esc && buf != NULL &&
strchr(buf, esc) != NULL) {