path: add new pkgconf_path_relocate() API which is a stub when path

relocation is not needed
feature/tap-sh
William Pitcock 2017-01-13 20:04:38 -06:00
parent 7f6a185977
commit 1369f558c6
2 changed files with 34 additions and 0 deletions

View File

@ -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); 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); bool pkgconf_path_match_list(const char *path, const pkgconf_list_t *dirlist);
void pkgconf_path_free(pkgconf_list_t *dirlist); void pkgconf_path_free(pkgconf_list_t *dirlist);
bool pkgconf_path_relocate(char *buf, size_t buflen);
#endif #endif

View File

@ -16,6 +16,10 @@
#include <libpkgconf/libpkgconf.h> #include <libpkgconf/libpkgconf.h>
#include <libpkgconf/config.h> #include <libpkgconf/config.h>
#ifdef HAVE_CYGWIN_CONV_PATH
# include <sys/cygwin.h>
#endif
#ifdef HAVE_SYS_STAT_H #ifdef HAVE_SYS_STAT_H
# include <sys/stat.h> # include <sys/stat.h>
# define PKGCONF_CACHE_INODES # define PKGCONF_CACHE_INODES
@ -214,3 +218,32 @@ pkgconf_path_free(pkgconf_list_t *dirlist)
free(pnode); 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;
}