1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-22 15:58:50 -05:00

pacman/util.c: add mdirname function

This function mirrors mbasename and will be used by the 'owns' machinery.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2008-02-05 18:49:13 -06:00
parent a7a9f37561
commit 7d7a337912
2 changed files with 29 additions and 0 deletions

View File

@ -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)

View File

@ -41,6 +41,7 @@ int getcols();
int makepath(const char *path);
int rmrf(const char *path);
char *mbasename(const char *path);
char *mdirname(const char *path);
void indentprint(const char *str, int indent);
char *strtoupper(char *str);
char *strtrim(char *str);