From 666019cfd06ba2d4be3920a7ee61a4772d567117 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Tue, 14 Aug 2012 16:04:56 +0200 Subject: [PATCH] Nuke use of basename/dirname where a simple strrchr can do the trick --- pkg.c | 18 +++++++++++++----- stdinc.h | 1 - 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg.c b/pkg.c index 4d0dc68..b53f145 100644 --- a/pkg.c +++ b/pkg.c @@ -32,6 +32,12 @@ #define PKG_CONFIG_PATH_SEP_S ":" #endif +#ifdef _WIN32 +#define PKG_DIR_SEP_S '\\' +#else +#define PKG_DIR_SEP_S '/' +#endif + static inline size_t path_split(const char *text, char ***parv) { @@ -122,12 +128,11 @@ static const char * pkg_get_parent_dir(pkg_t *pkg) { static char buf[PKG_BUFSIZE]; - static char filebuf[PKG_BUFSIZE]; char *pathbuf; - strlcpy(filebuf, pkg->filename, sizeof filebuf); - pathbuf = dirname(filebuf); - strlcpy(buf, pathbuf, sizeof buf); + strlcpy(buf, pkg->filename, sizeof buf); + pathbuf = strrchr(buf, PKG_DIR_SEP_S); + pathbuf[0] = '\0'; return buf; } @@ -149,7 +154,10 @@ pkg_new_from_file(const char *filename, FILE *f) pkg->vars = pkg_tuple_add(pkg->vars, "pcfiledir", pkg_get_parent_dir(pkg)); /* make module id */ - pkg->id = strdup(basename(pkg->filename)); + idptr = strrchr(pkg->filename, PKG_DIR_SEP_S); + idptr++; + + pkg->id = strdup(idptr); idptr = strrchr(pkg->id, '.'); if (idptr) *idptr = '\0'; diff --git a/stdinc.h b/stdinc.h index f8a7537..e44f190 100644 --- a/stdinc.h +++ b/stdinc.h @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include