File lookup: wind in last occurence to the loop.

Instead of repeating the parsing stage after reaching the null
terminator, just handle it inside the loop and terminate the loop
afterwards.
feature/tap-sh
Michał Górny 2012-05-02 11:40:38 +02:00
parent 742fad9251
commit f26001c3f8
1 changed files with 4 additions and 8 deletions

12
pkg.c
View File

@ -70,7 +70,7 @@ pkg_find(const char *name)
bzero(path, BUFSIZ); bzero(path, BUFSIZ);
env_path = pkg_get_pkgconfig_path(); env_path = pkg_get_pkgconfig_path();
while (env_path[count] != '\0') while (1)
{ {
if (env_path[count] && env_path[count] != PKG_CONFIG_PATH_SEP) if (env_path[count] && env_path[count] != PKG_CONFIG_PATH_SEP)
{ {
@ -83,6 +83,8 @@ pkg_find(const char *name)
snprintf(locbuf, sizeof locbuf, "%s/%s.pc", path, name); snprintf(locbuf, sizeof locbuf, "%s/%s.pc", path, name);
if (f = fopen(locbuf, "r")) if (f = fopen(locbuf, "r"))
return parse_file(locbuf, f); return parse_file(locbuf, f);
else if (env_path[count] == '\0')
break;
bzero(path, BUFSIZ); bzero(path, BUFSIZ);
pcount = 0; pcount = 0;
@ -91,13 +93,7 @@ pkg_find(const char *name)
count++; count++;
} }
if (path[0] != '\0') return NULL;
{
snprintf(locbuf, sizeof locbuf, "%s/%s.pc", path, name);
f = fopen(locbuf, "r");
}
return parse_file(locbuf, f);
} }
/* /*