1*2fe8fb19SBen Gras /* $NetBSD: setprogname.c,v 1.3 2003/07/26 19:24:44 salo Exp $ */
2*2fe8fb19SBen Gras
3*2fe8fb19SBen Gras /*
4*2fe8fb19SBen Gras * Copyright (c) 2001 Christopher G. Demetriou
5*2fe8fb19SBen Gras * All rights reserved.
6*2fe8fb19SBen Gras *
7*2fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without
8*2fe8fb19SBen Gras * modification, are permitted provided that the following conditions
9*2fe8fb19SBen Gras * are met:
10*2fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright
11*2fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer.
12*2fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright
13*2fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the
14*2fe8fb19SBen Gras * documentation and/or other materials provided with the distribution.
15*2fe8fb19SBen Gras * 3. All advertising materials mentioning features or use of this software
16*2fe8fb19SBen Gras * must display the following acknowledgement:
17*2fe8fb19SBen Gras * This product includes software developed for the
18*2fe8fb19SBen Gras * NetBSD Project. See http://www.NetBSD.org/ for
19*2fe8fb19SBen Gras * information about NetBSD.
20*2fe8fb19SBen Gras * 4. The name of the author may not be used to endorse or promote products
21*2fe8fb19SBen Gras * derived from this software without specific prior written permission.
22*2fe8fb19SBen Gras *
23*2fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24*2fe8fb19SBen Gras * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25*2fe8fb19SBen Gras * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26*2fe8fb19SBen Gras * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27*2fe8fb19SBen Gras * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28*2fe8fb19SBen Gras * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29*2fe8fb19SBen Gras * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30*2fe8fb19SBen Gras * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31*2fe8fb19SBen Gras * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32*2fe8fb19SBen Gras * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33*2fe8fb19SBen Gras *
34*2fe8fb19SBen Gras * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
35*2fe8fb19SBen Gras */
36*2fe8fb19SBen Gras
37*2fe8fb19SBen Gras #include <sys/cdefs.h>
38*2fe8fb19SBen Gras #if defined(LIBC_SCCS) && !defined(lint)
39*2fe8fb19SBen Gras __RCSID("$NetBSD: setprogname.c,v 1.3 2003/07/26 19:24:44 salo Exp $");
40*2fe8fb19SBen Gras #endif /* LIBC_SCCS and not lint */
41*2fe8fb19SBen Gras
42*2fe8fb19SBen Gras /* In NetBSD, the program name is set by crt0. It can't be overridden. */
43*2fe8fb19SBen Gras #undef REALLY_SET_PROGNAME
44*2fe8fb19SBen Gras
45*2fe8fb19SBen Gras #include <stdlib.h>
46*2fe8fb19SBen Gras
47*2fe8fb19SBen Gras #ifdef REALLY_SET_PROGNAME
48*2fe8fb19SBen Gras #include <string.h>
49*2fe8fb19SBen Gras
50*2fe8fb19SBen Gras extern const char *__progname;
51*2fe8fb19SBen Gras #endif
52*2fe8fb19SBen Gras
53*2fe8fb19SBen Gras /*ARGSUSED*/
54*2fe8fb19SBen Gras void
setprogname(const char * progname)55*2fe8fb19SBen Gras setprogname(const char *progname)
56*2fe8fb19SBen Gras {
57*2fe8fb19SBen Gras
58*2fe8fb19SBen Gras #ifdef REALLY_SET_PROGNAME
59*2fe8fb19SBen Gras __progname = strrchr(progname, '/');
60*2fe8fb19SBen Gras if (__progname == NULL)
61*2fe8fb19SBen Gras __progname = progname;
62*2fe8fb19SBen Gras else
63*2fe8fb19SBen Gras __progname++;
64*2fe8fb19SBen Gras #endif
65*2fe8fb19SBen Gras }
66