ltmain.sh.patch 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. --- a/build-aux/ltmain.sh 2010-03-04 20:49:32.000000000 +0000
  2. +++ b/build-aux/ltmain.sh 2010-03-02 23:04:58.000000000 +0000
  3. @@ -3280,6 +3280,7 @@
  4. int lt_split_name_value (const char *arg, char** name, char** value);
  5. void lt_update_exe_path (const char *name, const char *value);
  6. void lt_update_lib_path (const char *name, const char *value);
  7. +char **prepare_spawn (char **argv);
  8. static const char *script_text_part1 =
  9. EOF
  10. @@ -3560,6 +3561,7 @@
  11. mingw*)
  12. cat <<"EOF"
  13. /* execv doesn't actually work on mingw as expected on unix */
  14. + newargz = prepare_spawn (newargz);
  15. rval = _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
  16. if (rval == -1)
  17. {
  18. @@ -4023,8 +4025,125 @@
  19. }
  20. }
  21. +EOF
  22. + case $host_os in
  23. + mingw*)
  24. + cat <<"EOF"
  25. +
  26. +/* Prepares an argument vector before calling spawn().
  27. + Note that spawn() does not by itself call the command interpreter
  28. + (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
  29. + ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  30. + GetVersionEx(&v);
  31. + v.dwPlatformId == VER_PLATFORM_WIN32_NT;
  32. + }) ? "cmd.exe" : "command.com").
  33. + Instead it simply concatenates the arguments, separated by ' ', and calls
  34. + CreateProcess(). We must quote the arguments since Win32 CreateProcess()
  35. + interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
  36. + special way:
  37. + - Space and tab are interpreted as delimiters. They are not treated as
  38. + delimiters if they are surrounded by double quotes: "...".
  39. + - Unescaped double quotes are removed from the input. Their only effect is
  40. + that within double quotes, space and tab are treated like normal
  41. + characters.
  42. + - Backslashes not followed by double quotes are not special.
  43. + - But 2*n+1 backslashes followed by a double quote become
  44. + n backslashes followed by a double quote (n >= 0):
  45. + \" -> "
  46. + \\\" -> \"
  47. + \\\\\" -> \\"
  48. + */
  49. +#define SHELL_SPECIAL_CHARS "\"\\ \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
  50. +#define SHELL_SPACE_CHARS " \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
  51. +char **
  52. +prepare_spawn (char **argv)
  53. +{
  54. + size_t argc;
  55. + char **new_argv;
  56. + size_t i;
  57. +
  58. + /* Count number of arguments. */
  59. + for (argc = 0; argv[argc] != NULL; argc++)
  60. + ;
  61. +
  62. + /* Allocate new argument vector. */
  63. + new_argv = XMALLOC (char *, argc + 1);
  64. +
  65. + /* Put quoted arguments into the new argument vector. */
  66. + for (i = 0; i < argc; i++)
  67. + {
  68. + const char *string = argv[i];
  69. +
  70. + if (string[0] == '\0')
  71. + new_argv[i] = xstrdup ("\"\"");
  72. + else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
  73. + {
  74. + int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
  75. + size_t length;
  76. + unsigned int backslashes;
  77. + const char *s;
  78. + char *quoted_string;
  79. + char *p;
  80. +
  81. + length = 0;
  82. + backslashes = 0;
  83. + if (quote_around)
  84. + length++;
  85. + for (s = string; *s != '\0'; s++)
  86. + {
  87. + char c = *s;
  88. + if (c == '"')
  89. + length += backslashes + 1;
  90. + length++;
  91. + if (c == '\\')
  92. + backslashes++;
  93. + else
  94. + backslashes = 0;
  95. + }
  96. + if (quote_around)
  97. + length += backslashes + 1;
  98. + quoted_string = XMALLOC (char, length + 1);
  99. + p = quoted_string;
  100. + backslashes = 0;
  101. + if (quote_around)
  102. + *p++ = '"';
  103. + for (s = string; *s != '\0'; s++)
  104. + {
  105. + char c = *s;
  106. + if (c == '"')
  107. + {
  108. + unsigned int j;
  109. + for (j = backslashes + 1; j > 0; j--)
  110. + *p++ = '\\';
  111. + }
  112. + *p++ = c;
  113. + if (c == '\\')
  114. + backslashes++;
  115. + else
  116. + backslashes = 0;
  117. + }
  118. + if (quote_around)
  119. + {
  120. + unsigned int j;
  121. + for (j = backslashes; j > 0; j--)
  122. + *p++ = '\\';
  123. + *p++ = '"';
  124. + }
  125. + *p = '\0';
  126. +
  127. + new_argv[i] = quoted_string;
  128. + }
  129. + else
  130. + new_argv[i] = (char *) string;
  131. + }
  132. + new_argv[argc] = NULL;
  133. +
  134. + return new_argv;
  135. +}
  136. EOF
  137. + ;;
  138. + esac
  139. }
  140. # end: func_emit_cwrapperexe_src