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.
master
Ariadne Conill 2020-05-26 07:41:16 -06:00
parent be6b382dde
commit 0253fddc1d
1 changed files with 9 additions and 4 deletions

View File

@ -381,13 +381,18 @@ pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *filename, FILE *
/* make module id */ /* make module id */
if ((idptr = strrchr(pkg->filename, PKG_DIR_SEP_S)) != NULL) if ((idptr = strrchr(pkg->filename, PKG_DIR_SEP_S)) != NULL)
idptr++; idptr++;
#ifdef _WIN32
else if ((idptr = strrchr(pkg->filename, '/')) != NULL)
idptr++;
#endif
else else
idptr = pkg->filename; 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); pkg->id = strdup(idptr);
idptr = strrchr(pkg->id, '.'); idptr = strrchr(pkg->id, '.');
if (idptr) if (idptr)