]> git.saurik.com Git - apple/libc.git/blame - gen/FreeBSD/setprogname.c.patch
Libc-763.12.tar.gz
[apple/libc.git] / gen / FreeBSD / setprogname.c.patch
CommitLineData
1f2f436a
A
1--- setprogname.c.orig 2009-11-07 14:51:38.000000000 -0800
2+++ setprogname.c 2009-11-07 14:51:39.000000000 -0800
3@@ -3,6 +3,10 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/set
9385eb3d
A
4
5 #include <stdlib.h>
6 #include <string.h>
eb1cde05
A
7+#include <sys/param.h>
8+#include <sys/sysctl.h>
9385eb3d
A
9+#include <crt_externs.h>
10+#define __progname (*_NSGetProgname())
11
12 #include "libc_private.h"
13
1f2f436a 14@@ -10,10 +14,20 @@ void
eb1cde05
A
15 setprogname(const char *progname)
16 {
17 const char *p;
18-
19+ char buf[2*MAXCOMLEN+1];
20+ int mib[2];
21+
9385eb3d
A
22 p = strrchr(progname, '/');
23 if (p != NULL)
24- __progname = p + 1;
1f2f436a 25+ __progname = (char *)(p = p + 1);
9385eb3d
A
26 else
27- __progname = progname;
eb1cde05
A
28+ __progname = (char *)(p = progname);
29+
224c7076 30+ strlcpy(&buf[0], (char *)(p), sizeof(buf));
eb1cde05
A
31+
32+ mib[0] = CTL_KERN;
33+ mib[1] = KERN_PROCNAME;
34+
35+ /* ignore errors as this is not a hard error */
34e8f829 36+ sysctl(mib, 2, NULL, NULL, &buf[0], strlen(buf));
9385eb3d 37 }