From 6c0fcd575e223b5c583af8b14e0b47ac3c2cd567 Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Sun, 20 Jun 2010 00:24:35 +0000 Subject: [PATCH] lib: getproname: only return last path component --- lib/libc/other/getprogname.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/libc/other/getprogname.c b/lib/libc/other/getprogname.c index c9b52ae8c..9eed738d3 100644 --- a/lib/libc/other/getprogname.c +++ b/lib/libc/other/getprogname.c @@ -42,6 +42,7 @@ __RCSID("$NetBSD: getprogname.c,v 1.3 2003/07/26 19:24:42 salo Exp $"); #include "namespace.h" #include +#include 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]; - return NULL; + pn = __prognamep[0]; + else + return NULL; + + if((component=strrchr(pn, '/'))) + return component+1; + return pn; }