]> git.saurik.com Git - apple/libc.git/blob - gen/FreeBSD/setprogname.c
Libc-1353.11.2.tar.gz
[apple/libc.git] / gen / FreeBSD / setprogname.c
1 #include <sys/cdefs.h>
2 __FBSDID("$FreeBSD: src/lib/libc/gen/setprogname.c,v 1.8 2002/03/29 22:43:41 markm Exp $");
3
4 #include <stdlib.h>
5 #include <string.h>
6 #include <sys/param.h>
7 #include <sys/sysctl.h>
8 #include <crt_externs.h>
9 #define __progname (*_NSGetProgname())
10
11 #include "libc_private.h"
12
13 void
14 setprogname(const char *progname)
15 {
16 const char *p;
17 char buf[2*MAXCOMLEN+1];
18 int mib[2];
19
20 p = strrchr(progname, '/');
21 if (p != NULL)
22 __progname = (char *)(p = p + 1);
23 else
24 __progname = (char *)(p = progname);
25
26 strlcpy(&buf[0], (char *)(p), sizeof(buf));
27
28 mib[0] = CTL_KERN;
29 mib[1] = KERN_PROCNAME;
30
31 /* ignore errors as this is not a hard error */
32 sysctl(mib, 2, NULL, NULL, &buf[0], strlen(buf));
33 }