From 0253fddc1d6462efe8d951b89e5985d3b265d5ba Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Tue, 26 May 2020 07:41:16 -0600 Subject: [PATCH] libpkgconf: pkg: fix computation of pkgconf_pkg_t.id on Windows. Windows allows both \ and / as valid path characters. A computed path such as C:\development\libfoo\pkgconfig/foo.pc will result in a computed pkgconf_pkg_t.id of "pkgconfig/foo". Accordingly, correct the path normalization for checking for / after the \ path has been dealt with in all cases. --- libpkgconf/pkg.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libpkgconf/pkg.c b/libpkgconf/pkg.c index fd85ec8..b0c390b 100644 --- a/libpkgconf/pkg.c +++ b/libpkgconf/pkg.c @@ -381,13 +381,18 @@ pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *filename, FILE * /* make module id */ if ((idptr = strrchr(pkg->filename, PKG_DIR_SEP_S)) != NULL) idptr++; -#ifdef _WIN32 - else if ((idptr = strrchr(pkg->filename, '/')) != NULL) - idptr++; -#endif else idptr = pkg->filename; +#ifdef _WIN32 + /* On Windows, both \ and / are allowed in paths, so we have to chop both. + * strrchr() took us to the last \ in that case, so we just have to see if + * it is followed by a /. If so, lop it off. + */ + if ((idptr = strrchr(idptr, '/')) != NULL) + idptr++; +#endif + pkg->id = strdup(idptr); idptr = strrchr(pkg->id, '.'); if (idptr)