vtools_genesis 1
vtools_genesis 2
vtools_genesis 3 #include "progname.h"
vtools_genesis 4
vtools_genesis 5 #include <stdio.h>
vtools_genesis 6 #include <stdlib.h>
vtools_genesis 7 #include <string.h>
vtools_genesis 8
vtools_genesis 9
vtools_genesis 10
vtools_genesis 11 initialized by |main()|. */
vtools_genesis 12 const char *program_name = NULL;
vtools_genesis 13
vtools_genesis 14
vtools_genesis 15 allocated with indefinite extent, and must not be modified after
vtools_genesis 16 this call. */
vtools_genesis 17 void
vtools_genesis 18 set_program_name(const char *argv0) {
vtools_genesis 19
vtools_genesis 20 prefixed with "lt-" (depends on the platform). It also makes
vtools_genesis 21 |argv[0]| absolute. But the name of the temporary executable
vtools_genesis 22 is a detail that should not be visible to the end user and to
vtools_genesis 23 the test suite. Remove this |"<dirname>/.libs/"| or
vtools_genesis 24 |"<dirname>/.libs/lt-"| prefix here. */
vtools_genesis 25 const char *slash;
vtools_genesis 26 const char *base;
vtools_genesis 27
vtools_genesis 28
vtools_genesis 29 non-|NULL| |argv[0]|. */
vtools_genesis 30 if (argv0 == NULL) {
vtools_genesis 31
vtools_genesis 32 it. */
vtools_genesis 33 fputs("A NULL argv[0] was passed through an exec system call.\n",
vtools_genesis 34 stderr);
vtools_genesis 35 abort();
vtools_genesis 36 }
vtools_genesis 37
vtools_genesis 38 slash = strrchr(argv0, '/');
vtools_genesis 39 base = (slash != NULL ? slash + 1 : argv0);
vtools_genesis 40 if (base - argv0 >= 7 && strncmp(base - 7, "/.libs/", 7) == 0) {
vtools_genesis 41 argv0 = base;
vtools_genesis 42 if (strncmp(base, "lt-", 3) == 0) {
vtools_genesis 43 argv0 = base + 3;
vtools_genesis 44
vtools_genesis 45 variable |program_invocation_short_name|. */
vtools_genesis 46 #if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
vtools_genesis 47 program_invocation_short_name = (char *) argv0;
vtools_genesis 48 #endif
vtools_genesis 49 }
vtools_genesis 50 }
vtools_genesis 51
vtools_genesis 52
vtools_genesis 53 when the user runs
vtools_genesis 54
vtools_genesis 55 |/some/hidden/place/bin/cp foo foo|
vtools_genesis 56
vtools_genesis 57 he should get the error message
vtools_genesis 58
vtools_genesis 59 |/some/hidden/place/bin/cp: `foo' and `foo' are the same file|
vtools_genesis 60
vtools_genesis 61 not
vtools_genesis 62
vtools_genesis 63 | cp: `foo' and `foo' are the same file|
vtools_genesis 64 */
vtools_genesis 65
vtools_genesis 66 program_name = argv0;
vtools_genesis 67
vtools_genesis 68
vtools_genesis 69 uses the variable |program_invocation_name|, not
vtools_genesis 70 |program_name|. So set this variable as well. */
vtools_genesis 71 #if HAVE_DECL_PROGRAM_INVOCATION_NAME
vtools_genesis 72 program_invocation_name = (char *) argv0;
vtools_genesis 73 #endif
vtools_genesis 74 }
vtools_genesis 75
vtools_genesis 76 const char *
vtools_genesis 77 get_program_name(void) {
vtools_genesis 78 return program_name;
vtools_genesis 79 }