]> git.saurik.com Git - apple/libc.git/blame - gen/FreeBSD/setprogname.c
Libc-1272.200.26.tar.gz
[apple/libc.git] / gen / FreeBSD / setprogname.c
CommitLineData
9385eb3d
A
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>
ad3c9f2a
A
6#include <sys/param.h>
7#include <sys/sysctl.h>
8#include <crt_externs.h>
9#define __progname (*_NSGetProgname())
9385eb3d
A
10
11#include "libc_private.h"
12
13void
14setprogname(const char *progname)
15{
16 const char *p;
ad3c9f2a
A
17 char buf[2*MAXCOMLEN+1];
18 int mib[2];
19
9385eb3d
A
20 p = strrchr(progname, '/');
21 if (p != NULL)
ad3c9f2a 22 __progname = (char *)(p = p + 1);
9385eb3d 23 else
ad3c9f2a
A
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));
9385eb3d 33}