From 1369f558c69d29bba2fd756ba4f6c2ab350cf23f Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 13 Jan 2017 20:04:38 -0600 Subject: [PATCH] path: add new pkgconf_path_relocate() API which is a stub when path relocation is not needed --- libpkgconf/libpkgconf.h | 1 + libpkgconf/path.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/libpkgconf/libpkgconf.h b/libpkgconf/libpkgconf.h index 9c1e80d..f2e6abf 100644 --- a/libpkgconf/libpkgconf.h +++ b/libpkgconf/libpkgconf.h @@ -277,5 +277,6 @@ size_t pkgconf_path_split(const char *text, pkgconf_list_t *dirlist, bool filter size_t pkgconf_path_build_from_environ(const char *environ, const char *fallback, pkgconf_list_t *dirlist, bool filter); bool pkgconf_path_match_list(const char *path, const pkgconf_list_t *dirlist); void pkgconf_path_free(pkgconf_list_t *dirlist); +bool pkgconf_path_relocate(char *buf, size_t buflen); #endif diff --git a/libpkgconf/path.c b/libpkgconf/path.c index 60950bd..08b514b 100644 --- a/libpkgconf/path.c +++ b/libpkgconf/path.c @@ -16,6 +16,10 @@ #include #include +#ifdef HAVE_CYGWIN_CONV_PATH +# include +#endif + #ifdef HAVE_SYS_STAT_H # include # define PKGCONF_CACHE_INODES @@ -214,3 +218,32 @@ pkgconf_path_free(pkgconf_list_t *dirlist) free(pnode); } } + +bool +pkgconf_path_relocate(char *buf, size_t buflen) +{ +#ifdef HAVE_CYGWIN_CONV_PATH + ssize_t size; + char *tmpbuf, *ti; + + size = cygwin_conv_path(CCP_POSIX_TO_WIN_A, buf, NULL, 0); + if (size < 0 || (size_t) size > buflen) + return false; + + tmpbuf = malloc(size); + if (cygwin_conv_path(CCP_POSIX_TO_WIN_A, buf, tmpbuf, size)) + return false; + + pkgconf_strlcpy(buf, tmpbuf, buflen); + free(tmpbuf); + + /* rewrite any backslash arguments for best compatibility */ + for (ti = buf; *ti != '\0'; ti++) + { + if (*ti == '\\') + *ti = '/'; + } +#endif + + return true; +}