This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: DOS/Windows patches, take 2



These are the patches for the binutils subdirectory:

2000-05-14  Eli Zaretskii  <eliz@is.elta.co.il>

	* ar.c: Include filenames.h.
	(normalize) [HAVE_DOS_BASED_FILE_SYSTEM]: Support backslashes
	and drive letters in file names.
	(main): Support backslashes and drive letters in argv[0].  Drop
	the .exe suffix, if any, in argv[0] if is_ranlib is negative.  Use
	FILENAME_CMP instead of strcmp to compare file names.
	(open_inarch) [__GO32__]: Don't ifdef errno != ENOENT test for
	DJGPP v2.
	(do_quick_append) [__GO32__]: Ditto.
	(get_pos_bfd, delete_members, move_members, replace_members):
	Compare file names with FILENAME_CMP.

	* bucomm.c: Include filenames.h.
	(make_tempname) [HAVE_DOS_BASED_FILE_SYSTEM]: Support mixed
	forward/backward slashes and drive letters in file names.

	* ieee.c (ieee_start_compilation_unit, ieee_add_bb11): Support
	mixed forward/backward slashes and drive letters in file names.

	* objdump.c (display_target_list, display_info_table): Call
	bfd_close_all_done when done with each target.

	* strings.c (O_BINARY, setmode, SET_BINARY): Define.
	(main) [SET_BINARY]: Use SET_BINARY to switch stdin into binary
	mode.

	* objcopy.c: Include filenames.h.
	(main) [HAVE_DOS_BASED_FILE_SYSTEM]: Drop the .exe suffix
	before comparing to "strip".
	Use FILENAME_CMP to compare file names.

	* arsup.c: Include filenames.h.
	(map_over_list, ar_delete, ar_replace, ar_extract): Use
	FILENAME_CMP to compare file names.
	(ar_open): Prepend "tmp-" instead of appending "-tmp", to create
	the temporary file name.

	* configure.in: Check for setmode.


*** ./binutils/ar.c.orig	Sun Apr 16 09:39:00 2000
--- ./binutils/ar.c	Fri May 12 18:38:40 2000
*************** Foundation, Inc., 59 Temple Place - Suit
*** 32,37 ****
--- 32,38 ----
  #include "aout/ar.h"
  #include "libbfd.h"
  #include "arsup.h"
+ #include "filenames.h"
  #include <sys/stat.h>
  
  #ifdef __GO32___
*************** map_over_members (arch, function, files,
*** 215,221 ****
  	      bfd_stat_arch_elt (head, &buf);
  	    }
  	  if ((head->filename != NULL) &&
! 	      (!strcmp (normalize (*files, arch), head->filename)))
  	    {
  	      ++match_count;
  	      if (counted_name_mode
--- 216,222 ----
  	      bfd_stat_arch_elt (head, &buf);
  	    }
  	  if ((head->filename != NULL) &&
! 	      (!FILENAME_CMP (normalize (*files, arch), head->filename)))
  	    {
  	      ++match_count;
  	      if (counted_name_mode
*************** normalize (file, abfd)
*** 302,307 ****
--- 303,317 ----
      return file;
  
    filename = strrchr (file, '/');
+ #ifdef HAVE_DOS_BASED_FILE_SYSTEM
+   { /* We could have foo/bar\\baz, or foo\\bar, or d:bar.  */
+     char *bslash = strrchr (file, '\\');
+     if (bslash && bslash > filename)
+       filename = bslash;
+     if (filename == NULL && file[0] != '\0' && file[1] == ':')
+ 	filename = file + 1;
+   }
+ #endif
    if (filename != (char *) NULL)
      filename++;
    else
*************** main (argc, argv)
*** 377,388 ****
        char *temp;
  
        temp = strrchr (program_name, '/');
        if (temp == NULL)
  	temp = program_name;
        else
  	++temp;
        if (strlen (temp) >= 6
! 	  && strcmp (temp + strlen (temp) - 6, "ranlib") == 0)
  	is_ranlib = 1;
        else
  	is_ranlib = 0;
--- 387,407 ----
        char *temp;
  
        temp = strrchr (program_name, '/');
+ #ifdef HAVE_DOS_BASED_FILE_SYSTEM
+ 	{ /* We could have foo/bar\\baz, or foo\\bar, or d:bar.  */
+ 	  char *bslash = strrchr (program_name, '\\');
+   if (bslash && bslash > temp)
+ 	    temp = bslash;
+ 	  if (temp == NULL && program_name[0] != '\0' && program_name[1] == ':')
+ 	    temp = program_name + 1;
+ 	}
+ #endif
        if (temp == NULL)
  	temp = program_name;
        else
  	++temp;
        if (strlen (temp) >= 6
! 	  && FILENAME_CMP (temp + strlen (temp) - 6, "ranlib") == 0)
  	is_ranlib = 1;
        else
  	is_ranlib = 0;
*************** open_inarch (archive_filename, file)
*** 697,708 ****
  
    if (stat (archive_filename, &sbuf) != 0)
      {
! #ifndef __GO32__
  
  /* KLUDGE ALERT! Temporary fix until I figger why
   * stat() is wrong ... think it's buried in GO32's IDT
!  * - Jax
!  */
        if (errno != ENOENT)
  	bfd_fatal (archive_filename);
  #endif
--- 716,731 ----
  
    if (stat (archive_filename, &sbuf) != 0)
      {
! #if !defined(__GO32__) || defined(__DJGPP__)
! 
!       /* FIXME: I don't understand why this fragment was ifndef'ed
! 	 away for __GO32__; perhaps it was in the days of DJGPP v1.x.
! 	 stat() works just fine in v2.x, so I think this should be
! 	 removed.  For now, I enable it for DJGPP v2. -- EZ.  */
  
  /* KLUDGE ALERT! Temporary fix until I figger why
   * stat() is wrong ... think it's buried in GO32's IDT
!  * - Jax */
        if (errno != ENOENT)
  	bfd_fatal (archive_filename);
  #endif
*************** do_quick_append (archive_filename, files
*** 932,938 ****
    if (stat (archive_filename, &sbuf) != 0)
      {
  
! #ifndef __GO32__
  
  /* KLUDGE ALERT! Temporary fix until I figger why
   * stat() is wrong ... think it's buried in GO32's IDT
--- 955,969 ----
    if (stat (archive_filename, &sbuf) != 0)
      {
  
! #if !defined(__GO32__) || defined(__DJGPP__)
! 
!       /* FIXME: I don't understand why this fragment was ifndef'ed
! 	 away for __GO32__; perhaps it was in the days of DJGPP v1.x.
! 	 stat() works just fine in v2.x, so I think this should be
! 	 removed.  For now, I enable it for DJGPP v2.
! 
! 	 (And yes, I know this is all unused, but somebody, someday,
! 	 might wish to resurrect this again... -- EZ.  */
  
  /* KLUDGE ALERT! Temporary fix until I figger why
   * stat() is wrong ... think it's buried in GO32's IDT
*************** get_pos_bfd (contents, default_pos, defa
*** 1107,1113 ****
    else
      {
        for (; *after_bfd; after_bfd = &(*after_bfd)->next)
! 	if (strcmp ((*after_bfd)->filename, realposname) == 0)
  	  {
  	    if (realpos == pos_after)
  	      after_bfd = &(*after_bfd)->next;
--- 1138,1144 ----
    else
      {
        for (; *after_bfd; after_bfd = &(*after_bfd)->next)
! 	if (FILENAME_CMP ((*after_bfd)->filename, realposname) == 0)
  	  {
  	    if (realpos == pos_after)
  	      after_bfd = &(*after_bfd)->next;
*************** delete_members (arch, files_to_delete)
*** 1147,1153 ****
        current_ptr_ptr = &(arch->next);
        while (*current_ptr_ptr)
  	{
! 	  if (strcmp (normalize (*files_to_delete, arch),
  		      (*current_ptr_ptr)->filename) == 0)
  	    {
  	      ++match_count;
--- 1178,1184 ----
        current_ptr_ptr = &(arch->next);
        while (*current_ptr_ptr)
  	{
! 	  if (FILENAME_CMP (normalize (*files_to_delete, arch),
  		      (*current_ptr_ptr)->filename) == 0)
  	    {
  	      ++match_count;
*************** move_members (arch, files_to_move)
*** 1204,1211 ****
        while (*current_ptr_ptr)
  	{
  	  bfd *current_ptr = *current_ptr_ptr;
! 	  if (strcmp (normalize (*files_to_move, arch),
! 		      current_ptr->filename) == 0)
  	    {
  	      /* Move this file to the end of the list - first cut from
  		 where it is.  */
--- 1235,1242 ----
        while (*current_ptr_ptr)
  	{
  	  bfd *current_ptr = *current_ptr_ptr;
! 	  if (FILENAME_CMP (normalize (*files_to_move, arch),
! 			    current_ptr->filename) == 0)
  	    {
  	      /* Move this file to the end of the list - first cut from
  		 where it is.  */
*************** replace_members (arch, files_to_move, qu
*** 1260,1267 ****
  
  	      /* For compatibility with existing ar programs, we
  		 permit the same file to be added multiple times.  */
! 	      if (strcmp (normalize (*files_to_move, arch),
! 			  normalize (current->filename, arch)) == 0
  		  && current->arelt_data != NULL)
  		{
  		  if (newer_only)
--- 1291,1298 ----
  
  	      /* For compatibility with existing ar programs, we
  		 permit the same file to be added multiple times.  */
! 	      if (FILENAME_CMP (normalize (*files_to_move, arch),
! 				normalize (current->filename, arch)) == 0
  		  && current->arelt_data != NULL)
  		{
  		  if (newer_only)
*** ./binutils/arsup.c.orig	Sun Jul 11 16:02:16 1999
--- ./binutils/arsup.c	Fri May 12 18:38:40 2000
*************** style librarian command syntax + 1 word 
*** 31,36 ****
--- 31,37 ----
  #include "arsup.h"
  #include "libiberty.h"
  #include "bucomm.h"
+ #include "filenames.h"
  
  static void map_over_list
    PARAMS ((bfd *, void (*function) (bfd *, bfd *), struct list *));
*************** map_over_list (arch, function, list)
*** 76,82 ****
  	  for (head = arch->next; head; head = head->next) 
  	    {
  	      if (head->filename != NULL
! 		  && strcmp (ptr->name, head->filename) == 0)
  		{
  		  found = true;
  		  function (head, prev);
--- 77,83 ----
  	  for (head = arch->next; head; head = head->next) 
  	    {
  	      if (head->filename != NULL
! 		  && FILENAME_CMP (ptr->name, head->filename) == 0)
  		{
  		  found = true;
  		  function (head, prev);
*************** DEFUN(ar_open,(name, t),
*** 160,166 ****
  {
    char *tname = (char *) xmalloc (strlen (name) + 10);
    real_name = name;
!   sprintf(tname, "%s-tmp", name);
    obfd = bfd_openw(tname, NULL);
  
    if (!obfd) {
--- 161,169 ----
  {
    char *tname = (char *) xmalloc (strlen (name) + 10);
    real_name = name;
!   /* Prepend tmp- to the beginning, to avoid file-name clashes after
!      truncation on filesystems with limited namespaces (DOS).  */
!   sprintf(tname, "tmp-%s", name);
    obfd = bfd_openw(tname, NULL);
  
    if (!obfd) {
*************** DEFUN(ar_delete, (list),
*** 289,295 ****
        bfd **prev = &(obfd->archive_head);
        int found = 0;
        while (member) {
! 	if (strcmp(member->filename, list->name) == 0) {
  	  *prev = member->next;
  	  found = 1;
  	}
--- 292,298 ----
        bfd **prev = &(obfd->archive_head);
        int found = 0;
        while (member) {
! 	if (FILENAME_CMP(member->filename, list->name) == 0) {
  	  *prev = member->next;
  	  found = 1;
  	}
*************** DEFUN(ar_replace, (list),
*** 346,352 ****
        int found = 0;
        while (member) 
        {
! 	if (strcmp(member->filename, list->name) == 0) 
  	{
  	  /* Found the one to replace */
  	  bfd *abfd = bfd_openr(list->name, 0);
--- 349,355 ----
        int found = 0;
        while (member) 
        {
! 	if (FILENAME_CMP(member->filename, list->name) == 0) 
  	{
  	  /* Found the one to replace */
  	  bfd *abfd = bfd_openr(list->name, 0);
*************** DEFUN(ar_extract,(list),
*** 437,443 ****
        int found = 0;
        while (member && !found) 
        {
! 	if (strcmp(member->filename, list->name) == 0) 
  	{
  	  extract_file(member);
  	  found = 1;
--- 440,446 ----
        int found = 0;
        while (member && !found) 
        {
! 	if (FILENAME_CMP(member->filename, list->name) == 0) 
  	{
  	  extract_file(member);
  	  found = 1;
*** ./binutils/bucomm.c.orig	Sun Apr 16 09:39:00 2000
--- ./binutils/bucomm.c	Fri May 12 18:38:40 2000
***************
*** 25,30 ****
--- 25,31 ----
  #include "bfd.h"
  #include "libiberty.h"
  #include "bucomm.h"
+ #include "filenames.h"
  
  #include <sys/stat.h>
  #include <time.h>		/* ctime, maybe time_t */
*************** make_tempname (filename)
*** 214,222 ****
    char *tmpname;
    char *slash = strrchr (filename, '/');
  
! #if defined (__DJGPP__) || defined (__GO32__) || defined (_WIN32)
!   if (slash == NULL)
!     slash = strrchr (filename, '\\');
  #endif
  
    if (slash != (char *) NULL)
--- 215,228 ----
    char *tmpname;
    char *slash = strrchr (filename, '/');
  
! #ifdef HAVE_DOS_BASED_FILE_SYSTEM
!   { /* We could have foo/bar\\baz, or foo\\bar, or d:bar.  */
!     char *bslash = strrchr (filename, '\\');
!     if (bslash && bslash > slash)
!       slash = bslash;
!     if (slash == NULL && filename[0] != '\0' && filename[1] == ':')
!       slash = filename + 1;
!   }
  #endif
  
    if (slash != (char *) NULL)
*************** make_tempname (filename)
*** 225,232 ****
  
        c = *slash;
        *slash = 0;
!       tmpname = xmalloc (strlen (filename) + sizeof (template) + 1);
        strcpy (tmpname, filename);
        strcat (tmpname, "/");
        strcat (tmpname, template);
        mktemp (tmpname);
--- 231,245 ----
  
        c = *slash;
        *slash = 0;
!       tmpname = xmalloc (strlen (filename) + sizeof (template) + 2);
        strcpy (tmpname, filename);
+ #ifdef HAVE_DOS_BASED_FILE_SYSTEM
+       /* If tmpname is "X:", appending a slash will make it a root
+ 	 directory on drive X, which is NOT the same as the current
+ 	 directory on drive X.  */
+       if (tmpname[1] == ':' && tmpname[2] == '\0')
+ 	strcat (tmpname, ".");
+ #endif
        strcat (tmpname, "/");
        strcat (tmpname, template);
        mktemp (tmpname);
*** ./binutils/config.in.orig	Tue Jun 22 18:50:16 1999
--- ./binutils/config.in	Fri May 12 18:44:44 2000
***************
*** 82,87 ****
--- 82,90 ----
  /* Define if you have the setlocale function.  */
  #undef HAVE_SETLOCALE
  
+ /* Define if you have the setmode function.  */
+ #undef HAVE_SETMODE
+ 
  /* Define if you have the stpcpy function.  */
  #undef HAVE_STPCPY
  
*** ./binutils/configure.in.orig	Sun Apr 16 09:39:02 2000
--- ./binutils/configure.in	Fri May 12 18:38:42 2000
*************** AC_SUBST(DEMANGLER_NAME)
*** 96,102 ****
  AC_CHECK_HEADERS(string.h strings.h stdlib.h unistd.h fcntl.h sys/file.h)
  AC_HEADER_SYS_WAIT
  AC_FUNC_ALLOCA
! AC_CHECK_FUNCS(sbrk utimes)
  
  # Some systems have frexp only in -lm, not in -lc.
  AC_SEARCH_LIBS(frexp, m)
--- 96,102 ----
  AC_CHECK_HEADERS(string.h strings.h stdlib.h unistd.h fcntl.h sys/file.h)
  AC_HEADER_SYS_WAIT
  AC_FUNC_ALLOCA
! AC_CHECK_FUNCS(sbrk utimes setmode)
  
  # Some systems have frexp only in -lm, not in -lc.
  AC_SEARCH_LIBS(frexp, m)
*** ./binutils/ieee.c.orig	Fri Jan 14 18:10:20 2000
--- ./binutils/ieee.c	Fri May 12 18:38:40 2000
***************
*** 30,35 ****
--- 30,36 ----
  #include "libiberty.h"
  #include "debug.h"
  #include "budbg.h"
+ #include "filenames.h"
  
  /* This structure holds an entry on the block stack.  */
  
*************** ieee_start_compilation_unit (p, filename
*** 4938,4949 ****
    info->filename = filename;
    modname = strrchr (filename, '/');
    if (modname != NULL)
!     ++modname;
    else
      {
        modname = strrchr (filename, '\\');
        if (modname != NULL)
  	++modname;
        else
  	modname = filename;
      }
--- 4939,4961 ----
    info->filename = filename;
    modname = strrchr (filename, '/');
    if (modname != NULL)
!     {
!       const char *backslash;
! 
!       ++modname;
!       /* We could have a mixed forward-/back-slash case.  */
!       if ((backslash = strrchr (modname, '\\')) != NULL)
! 	modname = backslash + 1;
!     }
    else
      {
        modname = strrchr (filename, '\\');
        if (modname != NULL)
  	++modname;
+ #ifdef HAVE_DOS_BASED_FILE_SYSTEM
+       else if (filename[0] && filename[1] == ':')
+ 	modname = filename + 2;
+ #endif
        else
  	modname = filename;
      }
*************** ieee_add_bb11 (info, sec, low, high)
*** 5201,5212 ****
        filename = bfd_get_filename (info->abfd);
        modname = strrchr (filename, '/');
        if (modname != NULL)
! 	++modname;
        else
  	{
  	  modname = strrchr (filename, '\\');
  	  if (modname != NULL)
  	    ++modname;
  	  else
  	    modname = filename;
  	}
--- 5213,5235 ----
        filename = bfd_get_filename (info->abfd);
        modname = strrchr (filename, '/');
        if (modname != NULL)
! 	{
! 	  const char *backslash;
! 
! 	  ++modname;
! 	  /* We could have a mixed forward-/back-slash case.  */
! 	  if ((backslash = strrchr (modname, '\\')) != NULL)
! 	    modname = backslash + 1;
! 	}
        else
  	{
  	  modname = strrchr (filename, '\\');
  	  if (modname != NULL)
  	    ++modname;
+ #ifdef HAVE_DOS_BASED_FILE_SYSTEM
+ 	  else if (filename[0] && filename[1] == ':')
+ 	    modname = filename + 2;
+ #endif
  	  else
  	    modname = filename;
  	}
*** ./binutils/objcopy.c.orig	Tue May  9 15:31:22 2000
--- ./binutils/objcopy.c	Fri May 12 18:38:42 2000
***************
*** 25,30 ****
--- 25,31 ----
  #include "getopt.h"
  #include "libiberty.h"
  #include "budbg.h"
+ #include "filenames.h"
  #include <sys/stat.h>
  
  /* A list of symbols to explicitly strip out, or to keep.  A linked
*************** main (argc, argv)
*** 2248,2254 ****
    if (is_strip < 0)
      {
        int i = strlen (program_name);
!       is_strip = (i >= 5 && strcmp (program_name + i - 5, "strip") == 0);
      }
  
    if (is_strip)
--- 2249,2263 ----
    if (is_strip < 0)
      {
        int i = strlen (program_name);
! #ifdef HAVE_DOS_BASED_FILE_SYSTEM
!       /* Drop the .exe suffix, if any.  */
!       if (i > 4 && IS_SAME_PATH (program_name + i - 4, ".exe") == 0)
! 	{
! 	  program_name[i - 4] = '\0';
! 	  i -= 4;
! 	}
! #endif
!       is_strip = (i >= 5 && IS_SAME_PATH (program_name + i - 5, "strip") == 0);
      }
  
    if (is_strip)
*** ./binutils/objdump.c.orig	Wed Apr 19 16:28:26 2000
--- ./binutils/objdump.c	Fri May 12 18:38:42 2000
*************** display_target_list ()
*** 2653,2658 ****
--- 2653,2659 ----
  	{
  	  if (bfd_get_error () != bfd_error_invalid_operation)
  	    nonfatal (p->name);
+ 	  bfd_close_all_done (abfd);
  	  continue;
  	}
  
*************** display_target_list ()
*** 2660,2665 ****
--- 2661,2670 ----
  	if (bfd_set_arch_mach (abfd, (enum bfd_architecture) a, 0))
  	  printf ("  %s\n",
  		  bfd_printable_arch_mach ((enum bfd_architecture) a, 0));
+       /* We are going to unlink the file below, so make sure it's not
+ 	 left open, for those systems that don't like it when an open
+ 	 file is unlinked.  */
+       bfd_close_all_done (abfd);
      }
    unlink (dummy_name);
    free (dummy_name);
*************** display_info_table (first, last)
*** 2727,2732 ****
--- 2732,2742 ----
  		  putchar ('-');
  		putchar (' ');
  	      }
+ 	    /* We are going to unlink the file below, so make sure it's
+ 	       not left open, for those systems that don't like it when
+ 	       an open file is unlinked.  */
+ 	    if (abfd != NULL)
+ 	      bfd_close_all_done (abfd);
  	  }
  	putchar ('\n');
        }
*** ./binutils/strings.c.orig	Sun Apr 16 09:39:02 2000
--- ./binutils/strings.c	Fri May 12 18:43:34 2000
***************
*** 59,64 ****
--- 59,81 ----
  #include "bucomm.h"
  #include "libiberty.h"
  
+ /* Some platforms need to put stdin into binary mode, to read
+     binary files.  */
+ #ifdef HAVE_SETMODE
+ #ifndef O_BINARY
+ #ifdef _O_BINARY
+ #define O_BINARY _O_BINARY
+ #define setmode _setmode
+ #else
+ #define O_BINARY 0
+ #endif
+ #endif
+ #if O_BINARY
+ #include <io.h>
+ #define SET_BINARY(f) do { if (!isatty(f)) setmode(f,O_BINARY); } while (0)
+ #endif
+ #endif
+ 
  #ifdef isascii
  #define isgraphic(c) (isascii (c) && isprint (c))
  #else
*************** main (argc, argv)
*** 218,223 ****
--- 235,243 ----
    if (optind >= argc)
      {
        datasection_only = false;
+ #ifdef SET_BINARY
+       SET_BINARY (fileno (stdin));
+ #endif
        print_strings ("{standard input}", stdin, 0, 0, 0, (char *) NULL);
        files_given = true;
      }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]