1 /* $MirOS: src/lib/libc/stdlib/getprogname.c,v 1.6 2008/11/08 23:03:55 tg Exp $ */
2
3 /*-
4 * Copyright (c) 2005
5 * Thorsten "mirabilos" Glaser <tg@mirbsd.org>
6 *
7 * Licensee is hereby permitted to deal in this work without restric-
8 * tion, including unlimited rights to use, publicly perform, modify,
9 * merge, distribute, sell, give away or sublicence, provided all co-
10 * pyright notices above, these terms and the disclaimer are retained
11 * in all redistributions or reproduced in accompanying documentation
12 * or other materials provided with binary redistributions.
13 *
14 * Licensor offers the work "AS IS" and WITHOUT WARRANTY of any kind,
15 * express, or implied, to the maximum extent permitted by applicable
16 * law, without malicious intent or gross negligence; in no event may
17 * licensor, an author or contributor be held liable for any indirect
18 * or other damage, or direct damage except proven a consequence of a
19 * direct error of said person and intended use of this work, loss or
20 * other issues arising in any way out of its use, even if advised of
21 * the possibility of such damage or existence of a defect.
22 */
23
24 #include <stdlib.h>
25 #include <string.h>
26
27 __RCSID("$MirOS: src/lib/libc/stdlib/getprogname.c,v 1.6 2008/11/08 23:03:55 tg Exp $");
28
29 extern char *__progname;
30
31 /*
32 * Some other OSes actually use this, but for us,
33 * the CSU is smart enough to set __progname.
34 */
35 void
setprogname(const char * s)36 setprogname(const char *s)
37 {
38 char *t;
39
40 /* Don't reset if there's already a progname set */
41 if (__predict_true(*__progname) || __predict_false(s == NULL))
42 return;
43
44 if ((t = strrchr(s, '/')) == NULL)
45 __progname = strdup(s);
46 else
47 __progname = strdup(++t);
48 }
49
50 /*
51 * This is... well.
52 */
53 const char *
getprogname(void)54 getprogname(void)
55 {
56 return (__progname);
57 }
58