]> Zhao Yanbai Git Server - minix.git/commitdiff
lib: getproname: only return last path component
authorBen Gras <ben@minix3.org>
Sun, 20 Jun 2010 00:24:35 +0000 (00:24 +0000)
committerBen Gras <ben@minix3.org>
Sun, 20 Jun 2010 00:24:35 +0000 (00:24 +0000)
lib/libc/other/getprogname.c

index c9b52ae8c9e45445f9ab4b4490a84258f44b6397..9eed738d3bd821bc87ce16deef888e28a01fccbb 100644 (file)
@@ -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];
-       return NULL;
+               pn = __prognamep[0];
+       else
+               return NULL;
+
+       if((component=strrchr(pn, '/')))
+               return component+1;
+       return pn;
 }