lib: getproname: only return last path component
This commit is contained in:
parent
3cc5e1add4
commit
6c0fcd575e
1 changed files with 9 additions and 2 deletions
|
@ -42,6 +42,7 @@ __RCSID("$NetBSD: getprogname.c,v 1.3 2003/07/26 19:24:42 salo Exp $");
|
|||
#include "namespace.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
extern const char **__prognamep; /* Copy of argv[]. */
|
||||
extern int __argc; /* Copy of argc. */
|
||||
|
@ -49,7 +50,13 @@ extern int __argc; /* Copy of argc. */
|
|||
const char *
|
||||
getprogname(void)
|
||||
{
|
||||
const char *pn = NULL, *component;
|
||||
if(__argc > 0 && __prognamep)
|
||||
return __prognamep[0];
|
||||
pn = __prognamep[0];
|
||||
else
|
||||
return NULL;
|
||||
|
||||
if((component=strrchr(pn, '/')))
|
||||
return component+1;
|
||||
return pn;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue