From 716fb98edd3ccd4e66da8de8f973e83a299dba7d Mon Sep 17 00:00:00 2001 From: Ricardo Branco Date: Sun, 31 Mar 2024 10:06:11 +0200 Subject: [PATCH] basename --- bsd/kinfo_getargv.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bsd/kinfo_getargv.c b/bsd/kinfo_getargv.c index 6ace737..5afe648 100644 --- a/bsd/kinfo_getargv.c +++ b/bsd/kinfo_getargv.c @@ -7,12 +7,21 @@ #include #endif +#include #include #include #include "extern.h" static char *kinfo_getpathname(pid_t); +static char *xbasename(const char *s); + +static char * +xbasename(const char *s) { + char *t = strrchr(s, '/'); + printf("xxx\n"); + return ++t; +} static char * kinfo_getpathname(pid_t pid) @@ -92,8 +101,11 @@ kinfo_getargv(pid_t pid) if (buf[0] != '/') { argv[0] = kinfo_getpathname(pid); if (argv[0] != NULL) { - off += strlen(buf) + 1; - i++; + if (!strcmp(xbasename(buf), xbasename(argv[0]))) { + off += strlen(buf) + 1; + i++; + } else + free(argv[0]); } } #endif