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

pull/36/head
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 ":"
#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';

View File

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