forked from ariadne/pkgconf
fileio: add support for quoting to pkg_fgetline().
parent
dde296193f
commit
ee2e6054aa
31
fileio.c
31
fileio.c
|
@ -21,6 +21,7 @@ pkg_fgetline(char *line, size_t size, FILE *stream)
|
|||
{
|
||||
char *s = line;
|
||||
char *end = line + size - 1;
|
||||
bool quoted = false;
|
||||
int c = '\0', c2;
|
||||
|
||||
if (s == NULL)
|
||||
|
@ -28,9 +29,22 @@ pkg_fgetline(char *line, size_t size, FILE *stream)
|
|||
|
||||
while (s < end && (c = getc(stream)) != EOF)
|
||||
{
|
||||
if (c == '\n')
|
||||
if (c == '\\')
|
||||
{
|
||||
quoted = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
else if (c == '\n')
|
||||
{
|
||||
*s++ = c;
|
||||
|
||||
if (quoted)
|
||||
{
|
||||
quoted = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else if (c == '\r')
|
||||
|
@ -38,9 +52,24 @@ pkg_fgetline(char *line, size_t size, FILE *stream)
|
|||
*s++ = '\n';
|
||||
|
||||
if ((c2 = getc(stream)) == '\n')
|
||||
{
|
||||
if (quoted)
|
||||
{
|
||||
quoted = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
ungetc(c2, stream);
|
||||
|
||||
if (quoted)
|
||||
{
|
||||
quoted = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue