- char *ptr;
-
- /* Make sure that the input and output filenames have the
- ".exe" extension...patch them up if they don't. */
- strcpy (in_filename, old_name);
- ptr = in_filename + strlen (in_filename) - 4;
- if (strcmp (ptr, ".exe"))
- strcat (in_filename, ".exe");
-
- strcpy (out_filename, new_name);
- ptr = out_filename + strlen (out_filename) - 4;
- if (strcmp (ptr, ".exe"))
+ char *p;
+ char *q;
+
+ /* Ignore old_name, and get our actual location from the OS. */
+ if (!GetModuleFileName (NULL, in_filename, MAX_PATH))
+ abort ();
+ dostounix_filename (in_filename);
+ strcpy (out_filename, in_filename);
+
+ /* Change the base of the output filename to match the requested name. */
+ if ((p = strrchr (out_filename, '/')) == NULL)
+ abort ();
+ /* The filenames have already been expanded, and will be in Unix
+ format, so it is safe to expect an absolute name. */
+ if ((q = strrchr (new_name, '/')) == NULL)
+ abort ();
+ strcpy (p, q);
+
+ /* Make sure that the output filename has the ".exe" extension...patch
+ it up if not. */
+ p = out_filename + strlen (out_filename) - 4;
+ if (strcmp (p, ".exe"))