1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Program name management.
4 Copyright (C) 2001-2003, 2005-2010 Free Software Foundation, Inc.
5 Written by Bruno Haible <bruno@clisp.org>, 2001.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #undef ENABLE_RELOCATABLE /* avoid defining set_program_name as a macro */
27 #include <errno.h> /* get program_invocation_name declaration */
33 /* String containing name the program is called with.
34 To be initialized by main(). */
35 const char *program_name = NULL;
37 /* Set program_name, based on argv[0].
38 argv0 must be a string allocated with indefinite extent, and must not be
39 modified after this call. */
41 set_program_name (const char *argv0)
43 /* libtool creates a temporary executable whose name is sometimes prefixed
44 with "lt-" (depends on the platform). It also makes argv[0] absolute.
45 But the name of the temporary executable is a detail that should not be
46 visible to the end user and to the test suite.
47 Remove this "<dirname>/.libs/" or "<dirname>/.libs/lt-" prefix here. */
51 /* Sanity check. POSIX requires the invoking process to pass a non-NULL
55 /* It's a bug in the invoking program. Help diagnosing it. */
56 fputs ("A NULL argv[0] was passed through an exec system call.\n",
61 slash = strrchr (argv0, '/');
62 base = (slash != NULL ? slash + 1 : argv0);
63 if (base - argv0 >= 7 && strncmp (base - 7, "/.libs/", 7) == 0)
66 if (strncmp (base, "lt-", 3) == 0)
69 /* On glibc systems, remove the "lt-" prefix from the variable
70 program_invocation_short_name. */
71 #if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
72 program_invocation_short_name = (char *) argv0;
77 /* But don't strip off a leading <dirname>/ in general, because when the user
79 /some/hidden/place/bin/cp foo foo
80 he should get the error message
81 /some/hidden/place/bin/cp: `foo' and `foo' are the same file
83 cp: `foo' and `foo' are the same file
88 /* On glibc systems, the error() function comes from libc and uses the
89 variable program_invocation_name, not program_name. So set this variable
91 #if HAVE_DECL_PROGRAM_INVOCATION_NAME
92 program_invocation_name = (char *) argv0;