mirror of
https://github.com/moparisthebest/pacman
synced 2024-11-15 05:45:03 -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:
parent
a7a9f37561
commit
7d7a337912
@ -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)
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user