From f26001c3f8fbea3233e1b2d3303590c12d0d3337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Wed, 2 May 2012 11:40:38 +0200 Subject: [PATCH] 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. --- pkg.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg.c b/pkg.c index c190d66..cdba222 100644 --- a/pkg.c +++ b/pkg.c @@ -70,7 +70,7 @@ pkg_find(const char *name) bzero(path, BUFSIZ); env_path = pkg_get_pkgconfig_path(); - while (env_path[count] != '\0') + while (1) { 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); if (f = fopen(locbuf, "r")) return parse_file(locbuf, f); + else if (env_path[count] == '\0') + break; bzero(path, BUFSIZ); pcount = 0; @@ -91,13 +93,7 @@ pkg_find(const char *name) count++; } - if (path[0] != '\0') - { - snprintf(locbuf, sizeof locbuf, "%s/%s.pc", path, name); - f = fopen(locbuf, "r"); - } - - return parse_file(locbuf, f); + return NULL; } /*