]> git.saurik.com Git - apple/libc.git/blob - gen/FreeBSD/setprogname.c.patch
Libc-594.9.5.tar.gz
[apple/libc.git] / gen / FreeBSD / setprogname.c.patch
1 --- setprogname.c.orig 2008-01-31 02:47:06.000000000 -0800
2 +++ setprogname.c 2008-01-31 03:07:50.000000000 -0800
3 @@ -3,6 +3,10 @@
4
5 #include <stdlib.h>
6 #include <string.h>
7 +#include <sys/param.h>
8 +#include <sys/sysctl.h>
9 +#include <crt_externs.h>
10 +#define __progname (*_NSGetProgname())
11
12 #include "libc_private.h"
13
14 @@ -10,10 +14,20 @@
15 setprogname(const char *progname)
16 {
17 const char *p;
18 -
19 + char buf[2*MAXCOMLEN+1];
20 + int mib[2];
21 +
22 p = strrchr(progname, '/');
23 if (p != NULL)
24 - __progname = p + 1;
25 + __progname = (char *)(p + 1);
26 else
27 - __progname = progname;
28 + __progname = (char *)(p = progname);
29 +
30 + strlcpy(&buf[0], (char *)(p), sizeof(buf));
31 +
32 + mib[0] = CTL_KERN;
33 + mib[1] = KERN_PROCNAME;
34 +
35 + /* ignore errors as this is not a hard error */
36 + sysctl(mib, 2, NULL, NULL, &buf[0], strlen(buf));
37 }