Support .pc file without a trailing newline #70

Closed
dumbbell wants to merge 1 commits from support-non-newline-terminated-pc-file into master
4 changed files with 22 additions and 4 deletions

View File

@ -83,10 +83,18 @@ pkg_fgetline(char *line, size_t size, FILE *stream)
}
*s = '\0';
if (c == EOF && (s == line || ferror(stream)))
return NULL;
*s = '\0';
/* Remove newline character. */
if (s > line && *(--s) == '\n') {
*s = '\0';
if (s > line && *(--s) == '\r')
*s = '\0';
}
return line;
}

2
pkg.c
View File

@ -212,8 +212,6 @@ pkg_new_from_file(const char *filename, FILE *f, unsigned int flags)
{
char op, *p, *key, *value;
readbuf[strlen(readbuf) - 1] = '\0';
p = readbuf;
while (*p && (isalpha(*p) || isdigit(*p) || *p == '_' || *p == '.'))
p++;

View File

@ -0,0 +1,10 @@
prefix=/usr
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include
Name: no-trailing-newline
Description: A testing pkg-config file
Version: 1.2.3
Libs: -L${libdir}/no-trailing-newline -lno-trailing-newline
Cflags: -I${includedir}/no-trailing-newline

View File

@ -122,6 +122,8 @@ run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --static --libs-only-l private-
# 4) tests for parser bugs
run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs dos-lineendings" \
'-L/usr/lib/dos-lineendings -ldos-lineendings'
run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --cflags no-trailing-newline" \
'-I/usr/include/no-trailing-newline'
run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs argv-parse" \
'-llib-2 -lpthread'
run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --exists -foo; echo \$?" \