diff options
author | Dan McGee <dan@archlinux.org> | 2008-02-05 19:31:23 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2008-02-05 19:31:23 -0600 |
commit | eca30ed66accd7c1555eb94cbdea60051efcf7f3 (patch) | |
tree | 3ec7f3387dea753bb68968c66597a1aa8e091ab4 /src/pacman/util.c | |
parent | 93a3050ed9e9735352013014da52adcdf896f95f (diff) | |
parent | b29838c8250125a22016c16180e941d059d55539 (diff) |
Merge branch 'maint'
Conflicts:
contrib/gensync
contrib/updatesync
Diffstat (limited to 'src/pacman/util.c')
-rw-r--r-- | src/pacman/util.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c index 42b0c98d..2dae832f 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -187,6 +187,34 @@ char *mbasename(const char *path) return (char *)p; } +/** Parse the dirname of a program from a path. +* The path returned should be freed. +* @param path path to parse dirname from +* +* @return everything preceding the final '/' +*/ +char *mdirname(const char *path) +{ + char *ret, *last; + + /* null or empty path */ + if(path == NULL || path == '\0') { + return(strdup(".")); + } + + ret = strdup(path); + last = strrchr(ret, '/'); + + if(last != NULL) { + /* we found a '/', so terminate our string */ + *last = '\0'; + return(ret); + } + /* no slash found */ + free(ret); + return(strdup(".")); +} + /* output a string, but wrap words properly with a specified indentation */ void indentprint(const char *str, int indent) |