]> granicus.if.org Git - postgresql/commitdiff
On Windows, cause get_progname to strip any .EXE suffix.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 24 Oct 2004 22:08:19 +0000 (22:08 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 24 Oct 2004 22:08:19 +0000 (22:08 +0000)
Andrew Dunstan

src/port/path.c

index e9c5abfbc33d3a42746de2e2e3d2eebe8765344f..65fc36e674cca5dde7411bc9ad430fed67d93bf2 100644 (file)
@@ -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;
 }