Nuke use of basename/dirname where a simple strrchr can do the trick

feature/tap-sh
Baptiste Daroussin 2012-08-14 16:04:56 +02:00
parent ab48da3f33
commit 666019cfd0
2 changed files with 13 additions and 6 deletions

18
pkg.c
View File

@ -32,6 +32,12 @@
#define PKG_CONFIG_PATH_SEP_S ":" #define PKG_CONFIG_PATH_SEP_S ":"
#endif #endif
#ifdef _WIN32
#define PKG_DIR_SEP_S '\\'
#else
#define PKG_DIR_SEP_S '/'
#endif
static inline size_t static inline size_t
path_split(const char *text, char ***parv) path_split(const char *text, char ***parv)
{ {
@ -122,12 +128,11 @@ static const char *
pkg_get_parent_dir(pkg_t *pkg) pkg_get_parent_dir(pkg_t *pkg)
{ {
static char buf[PKG_BUFSIZE]; static char buf[PKG_BUFSIZE];
static char filebuf[PKG_BUFSIZE];
char *pathbuf; char *pathbuf;
strlcpy(filebuf, pkg->filename, sizeof filebuf); strlcpy(buf, pkg->filename, sizeof buf);
pathbuf = dirname(filebuf); pathbuf = strrchr(buf, PKG_DIR_SEP_S);
strlcpy(buf, pathbuf, sizeof buf); pathbuf[0] = '\0';
return buf; 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)); pkg->vars = pkg_tuple_add(pkg->vars, "pcfiledir", pkg_get_parent_dir(pkg));
/* make module id */ /* 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, '.'); idptr = strrchr(pkg->id, '.');
if (idptr) if (idptr)
*idptr = '\0'; *idptr = '\0';

View File

@ -22,7 +22,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <libgen.h>
#include <dirent.h> #include <dirent.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>