diff options
author | Tom Lane | 2004-10-24 22:08:19 +0000 |
---|---|---|
committer | Tom Lane | 2004-10-24 22:08:19 +0000 |
commit | 39fccf0277939be2d32594325cc0a009e959271e (patch) | |
tree | c80649f08722a221ec9429d2109192afa03fe8f6 | |
parent | 0f845a9f091d4fe2c0b4d94643985cc8ce0ef119 (diff) |
On Windows, cause get_progname to strip any .EXE suffix.
Andrew Dunstan
-rw-r--r-- | src/port/path.c | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/port/path.c b/src/port/path.c index e9c5abfbc33..65fc36e674c 100644 --- a/src/port/path.c +++ b/src/port/path.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/path.c,v 1.36 2004/09/24 05:16:35 tgl Exp $ + * $PostgreSQL: pgsql/src/port/path.c,v 1.37 2004/10/24 22:08:19 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -175,15 +175,38 @@ canonicalize_path(char *path) /* - * Extracts the actual name of the program as called. + * Extracts the actual name of the program as called - + * stripped of .exe suffix if any */ const char * get_progname(const char *argv0) { + const char *nodir_name; + if (!last_dir_separator(argv0)) - return argv0; + nodir_name = argv0; else - return last_dir_separator(argv0) + 1; + nodir_name = last_dir_separator(argv0) + 1; + +#if defined(__CYGWIN__) || defined(WIN32) + /* strip .exe suffix, regardless of case */ + if (strlen(nodir_name) > 4 && + stricmp(nodir_name + (strlen(nodir_name) - 4), EXE) == 0) + { + char *progname; + + progname = strdup(nodir_name); + if (progname == NULL) + { + fprintf(stderr, "%s: out of memory\n", nodir_name); + exit(1); + } + progname[strlen(progname) - 4] = '\0'; + nodir_name = progname; + } +#endif + + return nodir_name; } |