Move mbasename from pacman.c to util.c
This function can be useful in other places. Signed-off-by: Chantry Xavier <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
7d37d9278d
commit
11133da587
3 changed files with 23 additions and 22 deletions
|
@ -229,28 +229,6 @@ static void cleanup(int signum)
|
||||||
exit(signum);
|
exit(signum);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Parse the basename of a program from a path.
|
|
||||||
* Grabbed from the uClibc source.
|
|
||||||
* @param path path to parse basename from
|
|
||||||
*
|
|
||||||
* @return everything following the final '/'
|
|
||||||
*/
|
|
||||||
static char *mbasename(const char *path)
|
|
||||||
{
|
|
||||||
const char *s;
|
|
||||||
const char *p;
|
|
||||||
|
|
||||||
p = s = path;
|
|
||||||
|
|
||||||
while (*s) {
|
|
||||||
if (*s++ == '/') {
|
|
||||||
p = s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (char *)p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Parse command-line arguments for each operation.
|
/** Parse command-line arguments for each operation.
|
||||||
* @param argc argc
|
* @param argc argc
|
||||||
* @param argv argv
|
* @param argv argv
|
||||||
|
|
|
@ -167,6 +167,28 @@ int rmrf(const char *path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Parse the basename of a program from a path.
|
||||||
|
* Grabbed from the uClibc source.
|
||||||
|
* @param path path to parse basename from
|
||||||
|
*
|
||||||
|
* @return everything following the final '/'
|
||||||
|
*/
|
||||||
|
char *mbasename(const char *path)
|
||||||
|
{
|
||||||
|
const char *s;
|
||||||
|
const char *p;
|
||||||
|
|
||||||
|
p = s = path;
|
||||||
|
|
||||||
|
while (*s) {
|
||||||
|
if (*s++ == '/') {
|
||||||
|
p = s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (char *)p;
|
||||||
|
}
|
||||||
|
|
||||||
/* output a string, but wrap words properly with a specified indentation
|
/* output a string, but wrap words properly with a specified indentation
|
||||||
*/
|
*/
|
||||||
void indentprint(const char *str, int indent)
|
void indentprint(const char *str, int indent)
|
||||||
|
|
|
@ -42,6 +42,7 @@ int needs_transaction();
|
||||||
int getcols();
|
int getcols();
|
||||||
int makepath(const char *path);
|
int makepath(const char *path);
|
||||||
int rmrf(const char *path);
|
int rmrf(const char *path);
|
||||||
|
char *mbasename(const char *path);
|
||||||
void indentprint(const char *str, int indent);
|
void indentprint(const char *str, int indent);
|
||||||
char *strtoupper(char *str);
|
char *strtoupper(char *str);
|
||||||
char *strtrim(char *str);
|
char *strtrim(char *str);
|
||||||
|
|
Loading…
Add table
Reference in a new issue