X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=bfd%2Fbfdio.c;h=463b3879c52ba6beac47190f8eb0810b0c330e65;hb=1845e254645efbc02248345ccdb557d265dd8ae1;hp=bba8d896d3a7849a8fd7449dec923b72a11458b0;hpb=ca859a893931d6fad8b35cf2c20afd43422a59fe;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/bfdio.c b/bfd/bfdio.c index bba8d896d3..463b3879c5 100644 --- a/bfd/bfdio.c +++ b/bfd/bfdio.c @@ -1,6 +1,6 @@ /* Low-level I/O routines for BFDs. - Copyright (C) 1990-2020 Free Software Foundation, Inc. + Copyright (C) 1990-2021 Free Software Foundation, Inc. Written by Cygnus Support. @@ -116,21 +116,40 @@ _bfd_real_fopen (const char *filename, const char *modes) } #elif defined (_WIN32) - size_t filelen = strlen (filename) + 1; + size_t filelen; + + /* PR 25713: Handle extra long path names. + For relative paths, convert them to absolute, in case that version is too long. */ + if (! IS_ABSOLUTE_PATH (filename) && (strstr (filename, ".o") != NULL)) + { + char cwd[1024]; + + getcwd (cwd, sizeof (cwd)); + filelen = strlen (cwd) + 1; + strncat (cwd, "\\", sizeof (cwd) - filelen); + ++ filelen; + strncat (cwd, filename, sizeof (cwd) - filelen); + + filename = cwd; + } + + filelen = strlen (filename) + 1; if (filelen > MAX_PATH - 1) { FILE * file; - char * fullpath = (char *) malloc (filelen + 8); + char * fullpath; int i; + fullpath = (char *) malloc (filelen + 8); + /* Add a Microsoft recommended prefix that will allow the extra-long path to work. */ strcpy (fullpath, "\\\\?\\"); strcat (fullpath, filename); /* Convert any UNIX style path separators into the DOS form. */ - for (i = 0, fullpath[i]; i++) + for (i = 0; fullpath[i]; i++) { if (IS_UNIX_DIR_SEPARATOR (fullpath[i])) fullpath[i] = '\\'; @@ -493,12 +512,17 @@ bfd_get_file_size (bfd *abfd) && !bfd_is_thin_archive (abfd->my_archive)) { struct areltdata *adata = (struct areltdata *) abfd->arelt_data; - archive_size = adata->parsed_size; - /* If the archive is compressed we can't compare against file size. */ - if (memcmp (((struct ar_hdr *) adata->arch_header)->ar_fmag, - "Z\012", 2) == 0) - return archive_size; - abfd = abfd->my_archive; + if (adata != NULL) + { + archive_size = adata->parsed_size; + /* If the archive is compressed we can't compare against + file size. */ + if (adata->arch_header != NULL + && memcmp (((struct ar_hdr *) adata->arch_header)->ar_fmag, + "Z\012", 2) == 0) + return archive_size; + abfd = abfd->my_archive; + } } file_size = bfd_get_size (abfd); @@ -662,8 +686,7 @@ memory_bclose (struct bfd *abfd) { struct bfd_in_memory *bim = (struct bfd_in_memory *) abfd->iostream; - if (bim->buffer != NULL) - free (bim->buffer); + free (bim->buffer); free (bim); abfd->iostream = NULL;