[mingw only]setProgName():
robustify by looking for the last '/' or '\\' in argv[0].
My copy of 'gdb' likes to use a mixture of the two, which causes a
fatal error when trying to debug libHSrts_p.a. Other process-invoking
apps/shells might be equally wavering when it comes to the use of slashes.
Merge to STABLE.
void
setProgName(char *argv[])
{
- char *last_slash;
-
/* Remove directory from argv[0] -- default files in current directory */
- if ((last_slash = (char *) strrchr(argv[0],
#if !defined(mingw32_HOST_OS)
- '/'
-#else
- '\\'
-#endif
- )) != NULL) {
+ char *last_slash;
+ if ( (last_slash = (char *) strrchr(argv[0], '/')) != NULL ) {
prog_name = last_slash+1;
} else {
prog_name = argv[0];
}
+#else
+ char* last_slash = argv[0] + (strlen(argv[0]) - 1);
+ while ( last_slash > argv[0] ) {
+ if ( *last_slash == '/' || *last_slash == '\\' ) {
+ prog_name = last_slash+1;
+ return;
+ }
+ last_slash--;
+ }
+ prog_name = argv[0];
+#endif
}
void