Make sure that the current executable filename has "exe" suffix on Windows.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sun, 15 Jun 2008 12:07:01 +0000 (12:07 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sun, 15 Jun 2008 12:07:01 +0000 (12:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52286 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-stub/llvm-stub.c

index 7e123cf607435946acd8a492192d75b5a925daae..91537a0b9cc7d388d6706d795fc1b35a59934da4 100644 (file)
@@ -38,6 +38,7 @@
 int main(int argc, char** argv) {
   const char *Interp = getenv("LLVMINTERP");
   const char **Args;
+  int len;
   if (Interp == 0) Interp = "lli";
 
   /* Set up the command line options to pass to the JIT. */
@@ -45,11 +46,14 @@ int main(int argc, char** argv) {
   /* argv[0] is the JIT */
   Args[0] = Interp;
 
-#ifdef __CYGWIN32__
-  /* Cygwin strips the .exe suffix off of argv[0] to "help" us.  Put it back 
-   * on.
-   */
-  argv[0] = strcat(strcpy((char*)malloc(strlen(argv[0])+5), argv[0]), ".exe");
+#ifdef LLVM_ON_WIN32
+  len = strlen(argv[0]);
+  if (len < 4 || strcmp(argv[0] + len - 4, ".exe") != 0) {
+    /* .exe suffix is stripped off of argv[0] if the executable was run on the
+     * command line without one. Put it back on.
+     */
+    argv[0] = strcat(strcpy((char*)malloc(len + 5), argv[0]), ".exe");
+  }
 #endif
 
   /* argv[1] is argv[0] + ".bc". */