home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Win32 Under the API
/
ProgrammingWin32UnderTheApiPatVillani.iso
/
patches
/
binutils-2_9_4.diff
next >
Wrap
Text File
|
2000-01-26
|
21KB
|
634 lines
Index: binutils-2.9.4/bfd/ChangeLog
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin/bfd/ChangeLog,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -3 -p -r1.1.1.1 -r1.3
--- binutils-2.9.4/bfd/ChangeLog 1999/02/19 05:36:00 1.1.1.1
+++ binutils-2.9.4/bfd/ChangeLog 1999/11/07 10:29:06 1.3
@@ -1,3 +1,23 @@
+Sun Nov 7 04:27:07 1999 Mumit Khan <khan@xraylith.wisc.edu>
+
+ * libbfd.c (__mingw_fseek): New function to work around Win9x
+ f/lseek bug.
+ (__mingw_fwrite): Likewise.
+ (__mingw_is_win9x): New helper function.
+
+Fri Aug 6 23:41:35 1999 Mumit Khan <khan@xraylith.wisc.edu>
+
+ * section.c (SEC_SHARED): Define.
+ * bfd-in2.h: Rebuild.
+ * coffcode.h (sec_to_styp_flags): Handle SEC_SHARED.
+ (styp_to_sec_flags): Likewise.
+ * peicode.h (coff_swap_scnhdr_out): Likewise.
+
+Sat Jun 26 21:09:44 1999 Mumit Khan <khan@xraylith.wisc.edu>
+
+ * peicode.h (coff_swap_scnhdr_out): Mark user-defined writable
+ sections as writable.
+
Wed Sep 16 10:34:13 1998 Nick Clifton <nickc@cygnus.com>
* elf32-v850.c (v850_elf_symbol_processing): Move symbols in
Index: binutils-2.9.4/bfd/bfd-in2.h
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin/bfd/bfd-in2.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -p -r1.1.1.1 -r1.2
--- binutils-2.9.4/bfd/bfd-in2.h 1999/02/19 05:36:01 1.1.1.1
+++ binutils-2.9.4/bfd/bfd-in2.h 1999/11/07 10:26:12 1.2
@@ -978,6 +978,9 @@ typedef struct sec
/* This section should not be subject to garbage collection. */
#define SEC_KEEP 0x1000000
+ /* This section contains "shared" data. Only used on PE-coff. */
+#define SEC_SHARED 0x4000000
+
/* End of section flags. */
/* Some internal packed boolean fields. */
Index: binutils-2.9.4/bfd/coffcode.h
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin/bfd/coffcode.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -p -r1.1.1.1 -r1.2
--- binutils-2.9.4/bfd/coffcode.h 1999/02/19 05:36:02 1.1.1.1
+++ binutils-2.9.4/bfd/coffcode.h 1999/11/07 10:26:12 1.2
@@ -443,6 +443,8 @@ sec_to_styp_flags (sec_name, sec_flags)
#ifdef COFF_WITH_PE
if (sec_flags & SEC_LINK_ONCE)
styp_flags |= IMAGE_SCN_LNK_COMDAT;
+ if (sec_flags & SEC_SHARED)
+ styp_flags |= IMAGE_SCN_MEM_SHARED;
#endif
return (styp_flags);
@@ -576,6 +578,9 @@ styp_to_sec_flags (abfd, hdr, name)
#ifdef COFF_WITH_PE
if (styp_flags & IMAGE_SCN_LNK_REMOVE)
sec_flags |= SEC_EXCLUDE;
+
+ if (styp_flags & IMAGE_SCN_MEM_SHARED)
+ sec_flags |= SEC_SHARED;
if (styp_flags & IMAGE_SCN_LNK_COMDAT)
{
Index: binutils-2.9.4/bfd/libbfd.c
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin/bfd/libbfd.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -p -r1.1.1.1 -r1.2
--- binutils-2.9.4/bfd/libbfd.c 1999/02/19 05:36:04 1.1.1.1
+++ binutils-2.9.4/bfd/libbfd.c 1999/11/07 10:29:06 1.2
@@ -518,6 +518,124 @@ bfd_get_file_window (abfd, offset, size,
#endif /* USE_MMAP */
+#ifdef __MINGW32__
+
+/* The following is a complete hack, and will be removed to the runtime
+ in the future. */
+
+/*
+ * Workaround for limitations on win9x where a file contents are
+ * not zero'd out if you seek past the end and then write. */
+
+#include <windows.h>
+
+#ifdef __GNUC__
+# define INLINE __inline__
+#endif
+
+#define ZEROBLOCKSIZE 512
+static int __mingw_fseek_called;
+
+static INLINE int
+__mingw_is_win9x ()
+{
+ static DWORD os_platform_id = -1;
+
+ if (os_platform_id == -1)
+ {
+ OSVERSIONINFO os_version_info;
+ memset (&os_version_info, 0, sizeof (OSVERSIONINFO));
+ os_version_info.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
+ GetVersionEx (&os_version_info);
+
+ os_platform_id = os_version_info.dwPlatformId;
+ }
+
+ /* Don't even bother to check for Win32s. */
+ return os_platform_id == VER_PLATFORM_WIN32_WINDOWS;
+}
+
+/* The fseek in Win9x runtime does not zero out the file if seeking past
+ the end; if you don't want random stuff from your disk included in your
+ output DLL/executable, use this version instead. On WinNT/Win2k, it
+ just calls runtime fseek().
+
+ CHECK/FIXME: Does this work for both text and binary modes?? */
+
+static int
+INLINE
+__mingw_fseek (FILE *fp, long offset, int whence)
+{
+#undef fseek
+ __mingw_fseek_called = 1;
+ return fseek (fp, offset, whence);
+}
+
+static int
+__mingw_fwrite (const void *buffer, size_t size, size_t count, FILE *fp)
+{
+#undef fwrite
+
+ if (__mingw_is_win9x () && __mingw_fseek_called)
+ {
+ DWORD actual_length, current_position;
+ __mingw_fseek_called = 0;
+
+ fflush (fp);
+ actual_length = GetFileSize ((HANDLE) _get_osfhandle (fileno (fp)),
+ NULL);
+ current_position = SetFilePointer ((HANDLE) _get_osfhandle (fileno (fp)),
+ 0, 0, FILE_CURRENT);
+#ifdef DEBUG
+ printf ("__mingw_fseek: current %ld, actual %ld\n",
+ current_position, actual_length);
+#endif /* DEBUG */
+ if (current_position > actual_length)
+ {
+ static char __mingw_zeros[ZEROBLOCKSIZE];
+ long numleft;
+
+ SetFilePointer ((HANDLE) _get_osfhandle (fileno (fp)),
+ 0, 0, FILE_END);
+ numleft = current_position - actual_length;
+
+#ifdef DEBUG
+ printf ("__mingw_fseek: Seeking %ld bytes past end\n", numleft);
+#endif /* DEBUG */
+ while (numleft > 0)
+ {
+ DWORD nzeros = (numleft > ZEROBLOCKSIZE)
+ ? ZEROBLOCKSIZE : numleft;
+ DWORD written;
+ if (! WriteFile ((HANDLE) _get_osfhandle (fileno (fp)),
+ __mingw_zeros, nzeros, &written, NULL))
+ {
+ /* Best we can hope for, or at least DJ says so. */
+ SetFilePointer ((HANDLE) _get_osfhandle (fileno (fp)),
+ 0, 0, FILE_BEGIN);
+ return -1;
+ }
+ if (written < nzeros)
+ {
+ /* Likewise. */
+ SetFilePointer ((HANDLE) _get_osfhandle (fileno (fp)),
+ 0, 0, FILE_BEGIN);
+ return -1;
+ }
+
+ numleft -= written;
+ }
+ FlushFileBuffers ((HANDLE) _get_osfhandle (fileno (fp)));
+ }
+ }
+ return fwrite (buffer, size, count, fp);
+}
+
+#define fseek __mingw_fseek
+#define fwrite __mingw_fwrite
+
+#endif /* __MINGW32__ */
+
bfd_size_type
bfd_write (ptr, size, nitems, abfd)
CONST PTR ptr;
Index: binutils-2.9.4/bfd/peicode.h
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin/bfd/peicode.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -p -r1.1.1.1 -r1.2
--- binutils-2.9.4/bfd/peicode.h 1999/02/19 05:36:04 1.1.1.1
+++ binutils-2.9.4/bfd/peicode.h 1999/11/07 10:26:12 1.2
@@ -1184,7 +1184,13 @@ coff_swap_scnhdr_out (abfd, in, out)
else if (strcmp (scnhdr_int->s_name, ".rsrc") == 0)
flags |= IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_SHARED;
else
- flags |= IMAGE_SCN_MEM_READ;
+ {
+ flags |= IMAGE_SCN_MEM_READ;
+ if (! (flags & SEC_READONLY))
+ flags |= IMAGE_SCN_MEM_WRITE;
+ if (flags & SEC_SHARED)
+ flags |= IMAGE_SCN_MEM_SHARED;
+ }
bfd_h_put_32(abfd, flags, (bfd_byte *) scnhdr_ext->s_flags);
}
Index: binutils-2.9.4/bfd/section.c
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin/bfd/section.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -p -r1.1.1.1 -r1.2
--- binutils-2.9.4/bfd/section.c 1999/02/19 05:36:04 1.1.1.1
+++ binutils-2.9.4/bfd/section.c 1999/11/07 10:26:12 1.2
@@ -307,6 +307,9 @@ CODE_FRAGMENT
. {* This section should not be subject to garbage collection. *}
.#define SEC_KEEP 0x1000000
.
+. {* This section contains "shared" data. Only used on PE-coff. *}
+.#define SEC_SHARED 0x4000000
+.
. {* End of section flags. *}
.
. {* Some internal packed boolean fields. *}
Index: binutils-2.9.4/binutils/ChangeLog
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin/binutils/ChangeLog,v
retrieving revision 1.1.1.1
retrieving revision 1.4
diff -u -3 -p -r1.1.1.1 -r1.4
--- binutils-2.9.4/binutils/ChangeLog 1999/02/19 05:36:04 1.1.1.1
+++ binutils-2.9.4/binutils/ChangeLog 1999/10/26 20:09:25 1.4
@@ -1,3 +1,20 @@
+Sat Aug 28 12:43:04 1999 Mumit Khan <khan@xraylith.wisc.edu>
+
+ * dlltool.c (scan_drectve_symbols): Handle type tags in exported
+ symbols.
+ (scan_filtered_symbols): Likewise.
+
+1999-02-17 DJ Delorie <dj@cygnus.com>
+
+ * resbin.c (res_to_bin_versioninfo): Instead of entering a value
+ length of zero in a version info string, enter the appropriate
+ length.
+
+Sun Aug 29 16:51:36 1999 Mumit Khan <khan@xraylith.wisc.edu>
+
+ * dllwrap.c (long_options): Add -mno-cygwin flag.
+ (main): Handle -mno-cygwin flag.
+
Fri Oct 30 15:14:49 1998 Geoffrey Noer <noer@cygnus.com>
* dllwrap.c: change all references to cygwin32_ to cygwin_
Index: binutils-2.9.4/binutils/dlltool.c
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin/binutils/dlltool.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -p -r1.1.1.1 -r1.2
--- binutils-2.9.4/binutils/dlltool.c 1999/02/19 05:36:05 1.1.1.1
+++ binutils-2.9.4/binutils/dlltool.c 1999/10/26 20:09:25 1.2
@@ -1083,7 +1083,9 @@ scan_drectve_symbols (abfd)
inform (_("Sucking in info from .drective section in %s\n"),
bfd_get_filename (abfd));
- /* Search for -export: strings */
+ /* Search for -export: strings. The exported symbols can optionally
+ have type tags (eg., -export:foo,data), so handle those as well.
+ Currently only data tag is supported. */
p = buf;
e = buf + size;
while (p < e)
@@ -1093,25 +1095,36 @@ scan_drectve_symbols (abfd)
{
char * name;
char * c;
+ flagword flags = BSF_FUNCTION;
p += 8;
name = p;
- while (p < e && *p != ' ' && *p != '-')
+ while (p < e && *p != ',' && *p != ' ' && *p != '-')
p++;
c = xmalloc (p - name + 1);
memcpy (c, name, p - name);
c[p - name] = 0;
+ if (p < e && *p == ',') /* found type tag. */
+ {
+ char *tag_start = ++p;
+ while (p < e && *p != ' ' && *p != '-')
+ p++;
+ if (strncmp (tag_start, "data", 4) == 0)
+ flags &= ~BSF_FUNCTION;
+ }
+
/* FIXME: The 5th arg is for the `constant' field.
What should it be? Not that it matters since it's not
currently useful. */
- def_exports (c, 0, -1, 0, 0, 0);
+ def_exports (c, 0, -1, 0, 0, ! (flags & BSF_FUNCTION));
if (add_stdcall_alias && strchr (c, '@'))
{
char *exported_name = xstrdup (c);
char *atsym = strchr (exported_name, '@');
*atsym = '\0';
+ /* Note: stdcall alias symbols can never be data. */
def_exports (exported_name, xstrdup (c), -1, 0, 0, 0);
}
}
@@ -1153,13 +1166,15 @@ scan_filtered_symbols (abfd, minisyms, s
if (bfd_get_symbol_leading_char (abfd) == symbol_name[0])
++symbol_name;
- def_exports (xstrdup (symbol_name) , 0, -1, 0, 0, 0);
+ def_exports (xstrdup (symbol_name) , 0, -1, 0, 0,
+ ! (sym->flags & BSF_FUNCTION));
if (add_stdcall_alias && strchr (symbol_name, '@'))
{
char *exported_name = xstrdup (symbol_name);
char *atsym = strchr (exported_name, '@');
*atsym = '\0';
+ /* Note: stdcall alias symbols can never be data. */
def_exports (exported_name, xstrdup (symbol_name), -1, 0, 0, 0);
}
}
Index: binutils-2.9.4/binutils/dllwrap.c
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin/binutils/dllwrap.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -p -r1.1.1.1 -r1.2
--- binutils-2.9.4/binutils/dllwrap.c 1999/02/19 05:36:05 1.1.1.1
+++ binutils-2.9.4/binutils/dllwrap.c 1999/08/29 21:52:49 1.2
@@ -379,9 +379,10 @@ usage (file, status)
#define OPTION_ENTRY (OPTION_DLLTOOL_NAME + 1)
#define OPTION_IMAGE_BASE (OPTION_ENTRY + 1)
#define OPTION_TARGET (OPTION_IMAGE_BASE + 1)
+#define OPTION_MNO_CYGWIN (OPTION_TARGET + 1)
/* DLLTOOL options. */
-#define OPTION_NODELETE (OPTION_TARGET + 1)
+#define OPTION_NODELETE (OPTION_MNO_CYGWIN + 1)
#define OPTION_DLLNAME (OPTION_NODELETE + 1)
#define OPTION_NO_IDATA4 (OPTION_DLLNAME + 1)
#define OPTION_NO_IDATA5 (OPTION_NO_IDATA4 + 1)
@@ -417,6 +418,7 @@ static const struct option long_options[
{"entry", required_argument, NULL, 'e'},
{"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
{"target", required_argument, NULL, OPTION_TARGET},
+ {"mno-cygwin", no_argument, NULL, OPTION_MNO_CYGWIN},
/* dlltool options. */
{"no-delete", no_argument, NULL, 'n'},
@@ -565,6 +567,10 @@ main (argc, argv)
break;
case OPTION_TARGET:
target = optarg;
+ break;
+ case OPTION_MNO_CYGWIN:
+ target = "i386-mingw32";
+ driver_arg = 1;
break;
case OPTION_BASE_FILE:
base_file_name = optarg;
Index: binutils-2.9.4/binutils/resbin.c
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin/binutils/resbin.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -p -r1.1.1.1 -r1.2
--- binutils-2.9.4/binutils/resbin.c 1999/02/19 05:36:05 1.1.1.1
+++ binutils-2.9.4/binutils/resbin.c 1999/08/29 21:53:40 1.2
@@ -2257,7 +2257,6 @@ res_to_bin_versioninfo (versioninfo, big
vslen += 6;
vsslen = 6;
- put_16 (big_endian, 0, vssd->data + 2);
put_16 (big_endian, 1, vssd->data + 4);
*pp = vssd;
@@ -2277,6 +2276,7 @@ res_to_bin_versioninfo (versioninfo, big
vsslen += length - hold;
*pp = unicode_to_bin (vs->value, big_endian);
+ put_16 (big_endian, (*pp)->length / 2, vssd->data + 2);
length += (*pp)->length;
vilen += (*pp)->length;
vslen += (*pp)->length;
Index: binutils-2.9.4/gas/ChangeLog
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin/gas/ChangeLog,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -p -r1.1.1.1 -r1.2
--- binutils-2.9.4/gas/ChangeLog 1999/02/19 05:35:58 1.1.1.1
+++ binutils-2.9.4/gas/ChangeLog 1999/11/07 10:24:58 1.2
@@ -1,3 +1,13 @@
+Fri Aug 6 23:44:22 1999 Mumit Khan <khan@xraylith.wisc.edu>
+
+ * config/obj-coff.c (obj_coff_section): Handle 's' (shared) section
+ flag.
+
+Sat Jun 26 21:09:44 1999 Mumit Khan <khan@xraylith.wisc.edu>
+
+ * config/obj-coff.c (obj_coff_section): Mark writable sections
+ as data.
+
Mon Aug 10 15:39:56 1998 Richard Henderson <rth@cygnus.com>
* config/tc-alpha.c (tc_gen_reloc): Bias WEAK symbols just as
Index: binutils-2.9.4/gas/config/obj-coff.c
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin/gas/config/obj-coff.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -p -r1.1.1.1 -r1.2
--- binutils-2.9.4/gas/config/obj-coff.c 1999/02/19 05:35:58 1.1.1.1
+++ binutils-2.9.4/gas/config/obj-coff.c 1999/11/07 10:24:59 1.2
@@ -1133,6 +1133,7 @@ coff_frob_file_after_relocs ()
* 'd' (apparently m88k for data)
* 'x' for text
* 'r' for read-only data
+ * 's' for shared data (pe-coff)
* But if the argument is not a quoted string, treat it as a
* subsegment number.
*/
@@ -1187,9 +1188,10 @@ obj_coff_section (ignore)
case 'b': flags |= SEC_ALLOC; flags &=~ SEC_LOAD; break;
case 'n': flags &=~ SEC_LOAD; break;
case 'd':
- case 'w': flags &=~ SEC_READONLY; break;
+ case 'w': flags |= SEC_DATA; flags &=~ SEC_READONLY; break;
case 'x': flags |= SEC_CODE; break;
case 'r': flags |= SEC_READONLY; break;
+ case 's': flags |= SEC_SHARED; break;
case 'i': /* STYP_INFO */
case 'l': /* STYP_LIB */
Index: binutils-2.9.4/libiberty/ChangeLog
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin/libiberty/ChangeLog,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -p -r1.1.1.1 -r1.2
--- binutils-2.9.4/libiberty/ChangeLog 1999/02/19 05:35:56 1.1.1.1
+++ binutils-2.9.4/libiberty/ChangeLog 1999/11/07 10:24:38 1.2
@@ -1,3 +1,15 @@
+Fri Nov 5 03:55:13 1999 Mumit Khan <khan@xraylith.wisc.edu>
+
+ * pexecute.c (fix_argv): Handle embedded whitespace in args.
+
+Mon Aug 30 18:09:42 1999 Mumit Khan <khan@xraylith.wisc.edu>
+
+ * basename.c (DIR_SEPARATOR): New macro.
+ (DIR_SEPARATOR_2): Likewise.
+ (HAVE_DOS_BASED_FILESYSTEM): Likewise.
+ (IS_DIR_SEPARATOR): Likewise.
+ (main): Handle MSDOS style pathname.
+
Wed Nov 18 08:52:26 1998 Christopher Faylor <cgf@cygnus.com>
* pexecute.c: Reorganize WIN32 case to accomodate Cygwin
Index: binutils-2.9.4/libiberty/basename.c
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin/libiberty/basename.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -p -r1.1.1.1 -r1.2
--- binutils-2.9.4/libiberty/basename.c 1999/02/19 05:35:56 1.1.1.1
+++ binutils-2.9.4/libiberty/basename.c 1999/11/07 10:24:38 1.2
@@ -14,24 +14,53 @@ DESCRIPTION
last component of the pathname ("ls.c" in this case).
BUGS
- Presumes a UNIX style path with UNIX style separators.
+ Presumes a UNIX or DOS/Windows style path with UNIX or DOS/Windows
+ style separators.
*/
#include "ansidecl.h"
#include "libiberty.h"
+#include <ctype.h>
+#ifndef DIR_SEPARATOR
+#define DIR_SEPARATOR '/'
+#endif
+
+#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \
+ defined (__OS2__)
+#define HAVE_DOS_BASED_FILE_SYSTEM
+#ifndef DIR_SEPARATOR_2
+#define DIR_SEPARATOR_2 '\\'
+#endif
+#endif
+
+/* Define IS_DIR_SEPARATOR. */
+#ifndef DIR_SEPARATOR_2
+# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
+#else /* DIR_SEPARATOR_2 */
+# define IS_DIR_SEPARATOR(ch) \
+ (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
+#endif /* DIR_SEPARATOR_2 */
+
char *
basename (name)
const char *name;
{
- const char *base = name;
+ const char *base;
- while (*name)
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+ /* Skip over the disk name in MSDOS pathnames. */
+ if (isalpha (name[0]) && name[1] == ':')
+ name += 2;
+#endif
+
+ for (base = name; *name; name++)
{
- if (*name++ == '/')
+ if (IS_DIR_SEPARATOR (*name))
{
- base = name;
+ base = name + 1;
}
}
return (char *) base;
}
+
Index: binutils-2.9.4/libiberty/pexecute.c
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin/libiberty/pexecute.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -p -r1.1.1.1 -r1.2
--- binutils-2.9.4/libiberty/pexecute.c 1999/02/19 05:35:56 1.1.1.1
+++ binutils-2.9.4/libiberty/pexecute.c 1999/11/07 10:24:38 1.2
@@ -242,30 +242,44 @@ fix_argv (argvec)
{
int i;
- for (i = 1; argvec[i] != 0; i++)
+ for (i = 0; argvec[i] != 0; i++)
{
- int len, j;
- char *temp, *newtemp;
-
- temp = argvec[i];
- len = strlen (temp);
- for (j = 0; j < len; j++)
+ if (strpbrk (argvec[i], " \t"))
{
- if (temp[j] == '"')
- {
- newtemp = xmalloc (len + 2);
- strncpy (newtemp, temp, j);
- newtemp [j] = '\\';
- strncpy (&newtemp [j+1], &temp [j], len-j);
- newtemp [len+1] = 0;
- temp = newtemp;
- len++;
- j++;
- }
- }
+ int len, trailing_backslash;
+ char *temp, *newtemp;
+
+ len = strlen (argvec[i]);
+ trailing_backslash = 0;
+
+ /* There is an added complication when an arg with embedded white
+ space ends in a backslash (such as in the case of -iprefix arg
+ passed to cpp). The resulting quoted strings gets misinterpreted
+ by the command interpreter -- it thinks that the ending quote
+ is escaped by the trailing backslash and things get confused.
+ We handle this case by escaping the trailing backslash, provided
+ it was not escaped in the first place. */
+ if (len > 1
+ && argvec[i][len-1] == '\\'
+ && argvec[i][len-2] != '\\')
+ {
+ trailing_backslash = 1;
+ ++len; /* to escape the final backslash. */
+ }
+
+ len += 2; /* and for the enclosing quotes. */
+
+ temp = xmalloc (len + 1);
+ temp[0] = '"';
+ strcpy (temp + 1, argvec[i]);
+ if (trailing_backslash)
+ temp[len-2] = '\\';
+ temp[len-1] = '"';
+ temp[len] = '\0';
- argvec[i] = temp;
- }
+ argvec[i] = temp;
+ }
+ }
return (const char * const *) argvec;
}