From 39fccf0277939be2d32594325cc0a009e959271e Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 24 Oct 2004 22:08:19 +0000 Subject: [PATCH] On Windows, cause get_progname to strip any .EXE suffix. Andrew Dunstan --- src/port/path.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/port/path.c b/src/port/path.c index e9c5abfbc3..65fc36e674 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; } -- 2.40.0