[Patch] bfd/archive.c: uses lbasename

Tristan Gingold gingold@adacore.com
Tue Jan 12 10:50:00 GMT 2010


Hi,

did I miss the obvious ?  It looks like lbasename could be used to simplify the code.

Tristan.

bfd/
2010-01-12  Tristan Gingold  <gingold@adacore.com>

	* archive.c (normalize): Use lbasename.
	(bfd_bsd_truncate_arname): Ditto.
	(bfd_gnu_truncate_arname): Ditto.


*** archive.c	11 Jan 2010 15:29:36 -0000	1.62
--- archive.c	12 Jan 2010 10:49:25 -0000
***************
*** 1312,1334 ****
  static const char *
  normalize (bfd *abfd ATTRIBUTE_UNUSED, const char *file)
  {
!   const char *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 (filename == NULL || (bslash != NULL && bslash > filename))
!       filename = bslash;
!     if (filename == NULL && file[0] != '\0' && file[1] == ':')
!       filename = file + 1;
!   }
! #endif
!   if (filename != NULL)
!     filename++;
!   else
!     filename = file;
!   return filename;
  }
  #endif
  
--- 1312,1318 ----
  static const char *
  normalize (bfd *abfd ATTRIBUTE_UNUSED, const char *file)
  {
!   return lbasename (file);
  }
  #endif
  
***************
*** 1820,1844 ****
  {
    struct ar_hdr *hdr = (struct ar_hdr *) arhdr;
    size_t length;
!   const char *filename = strrchr (pathname, '/');
    size_t maxlen = ar_maxnamelen (abfd);
  
- #ifdef HAVE_DOS_BASED_FILE_SYSTEM
-   {
-     /* We could have foo/bar\\baz, or foo\\bar, or d:bar.  */
-     char *bslash = strrchr (pathname, '\\');
-     if (filename == NULL || (bslash != NULL && bslash > filename))
-       filename = bslash;
-     if (filename == NULL && pathname[0] != '\0' && pathname[1] == ':')
-       filename = pathname + 1;
-   }
- #endif
- 
-   if (filename == NULL)
-     filename = pathname;
-   else
-     ++filename;
- 
    length = strlen (filename);
  
    if (length <= maxlen)
--- 1804,1812 ----
  {
    struct ar_hdr *hdr = (struct ar_hdr *) arhdr;
    size_t length;
!   const char *filename = lbasename (pathname);
    size_t maxlen = ar_maxnamelen (abfd);
  
    length = strlen (filename);
  
    if (length <= maxlen)
***************
*** 1868,1893 ****
  {
    struct ar_hdr *hdr = (struct ar_hdr *) arhdr;
    size_t length;
!   const char *filename = strrchr (pathname, '/');
    size_t maxlen = ar_maxnamelen (abfd);
  
- #ifdef HAVE_DOS_BASED_FILE_SYSTEM
-   {
-     /* We could have foo/bar\\baz, or foo\\bar, or d:bar.  */
-     char *bslash = strrchr (pathname, '\\');
- 
-     if (filename == NULL || (bslash != NULL && bslash > filename))
-       filename = bslash;
-     if (filename == NULL && pathname[0] != '\0' && pathname[1] == ':')
-       filename = pathname + 1;
-   }
- #endif
- 
-   if (filename == NULL)
-     filename = pathname;
-   else
-     ++filename;
- 
    length = strlen (filename);
  
    if (length <= maxlen)
--- 1836,1844 ----
  {
    struct ar_hdr *hdr = (struct ar_hdr *) arhdr;
    size_t length;
!   const char *filename = lbasename (pathname);
    size_t maxlen = ar_maxnamelen (abfd);
  
    length = strlen (filename);
  
    if (length <= maxlen)



More information about the Binutils mailing list