From 9a393eb20e57838c027925e884c5cb6ed16ad6e1 Mon Sep 17 00:00:00 2001 From: sof Date: Tue, 15 Mar 2005 23:44:06 +0000 Subject: [PATCH] [project @ 2005-03-15 23:44:06 by sof] [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. --- ghc/rts/RtsFlags.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ghc/rts/RtsFlags.c b/ghc/rts/RtsFlags.c index 37c22d1..e880c1d 100644 --- a/ghc/rts/RtsFlags.c +++ b/ghc/rts/RtsFlags.c @@ -2188,20 +2188,25 @@ bad_option(const char *s) 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 -- 1.7.10.4