| OLD | NEW |
| 1 /* BFD library -- caching of file descriptors. | 1 /* BFD library -- caching of file descriptors. |
| 2 | 2 |
| 3 Copyright 1990, 1991, 1992, 1993, 1994, 1996, 2000, 2001, 2002, | 3 Copyright 1990, 1991, 1992, 1993, 1994, 1996, 2000, 2001, 2002, |
| 4 2003, 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc. | 4 2003, 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc. |
| 5 | 5 |
| 6 Hacked by Steve Chamberlain of Cygnus Support (steve@cygnus.com). | 6 Hacked by Steve Chamberlain of Cygnus Support (steve@cygnus.com). |
| 7 | 7 |
| 8 This file is part of BFD, the Binary File Descriptor library. | 8 This file is part of BFD, the Binary File Descriptor library. |
| 9 | 9 |
| 10 This program is free software; you can redistribute it and/or modify | 10 This program is free software; you can redistribute it and/or modify |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 avoid running out of file descriptors. It will return NULL | 191 avoid running out of file descriptors. It will return NULL |
| 192 if it is unable to (re)open the @var{abfd}. */ | 192 if it is unable to (re)open the @var{abfd}. */ |
| 193 | 193 |
| 194 static FILE * | 194 static FILE * |
| 195 bfd_cache_lookup_worker (bfd *abfd, enum cache_flag flag) | 195 bfd_cache_lookup_worker (bfd *abfd, enum cache_flag flag) |
| 196 { | 196 { |
| 197 bfd *orig_bfd = abfd; | 197 bfd *orig_bfd = abfd; |
| 198 if ((abfd->flags & BFD_IN_MEMORY) != 0) | 198 if ((abfd->flags & BFD_IN_MEMORY) != 0) |
| 199 abort (); | 199 abort (); |
| 200 | 200 |
| 201 if (abfd->my_archive) | 201 while (abfd->my_archive) |
| 202 abfd = abfd->my_archive; | 202 abfd = abfd->my_archive; |
| 203 | 203 |
| 204 if (abfd->iostream != NULL) | 204 if (abfd->iostream != NULL) |
| 205 { | 205 { |
| 206 /* Move the file to the start of the cache. */ | 206 /* Move the file to the start of the cache. */ |
| 207 if (abfd != bfd_last_cache) | 207 if (abfd != bfd_last_cache) |
| 208 { | 208 { |
| 209 snip (abfd); | 209 snip (abfd); |
| 210 insert (abfd); | 210 insert (abfd); |
| 211 } | 211 } |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 if (open_files >= BFD_CACHE_MAX_OPEN) | 556 if (open_files >= BFD_CACHE_MAX_OPEN) |
| 557 { | 557 { |
| 558 if (! close_one ()) | 558 if (! close_one ()) |
| 559 return NULL; | 559 return NULL; |
| 560 } | 560 } |
| 561 | 561 |
| 562 switch (abfd->direction) | 562 switch (abfd->direction) |
| 563 { | 563 { |
| 564 case read_direction: | 564 case read_direction: |
| 565 case no_direction: | 565 case no_direction: |
| 566 abfd->iostream = (PTR) real_fopen (abfd->filename, FOPEN_RB); | 566 abfd->iostream = real_fopen (abfd->filename, FOPEN_RB); |
| 567 break; | 567 break; |
| 568 case both_direction: | 568 case both_direction: |
| 569 case write_direction: | 569 case write_direction: |
| 570 if (abfd->opened_once) | 570 if (abfd->opened_once) |
| 571 { | 571 { |
| 572 » abfd->iostream = (PTR) real_fopen (abfd->filename, FOPEN_RUB); | 572 » abfd->iostream = real_fopen (abfd->filename, FOPEN_RUB); |
| 573 if (abfd->iostream == NULL) | 573 if (abfd->iostream == NULL) |
| 574 » abfd->iostream = (PTR) real_fopen (abfd->filename, FOPEN_WUB); | 574 » abfd->iostream = real_fopen (abfd->filename, FOPEN_WUB); |
| 575 } | 575 } |
| 576 else | 576 else |
| 577 { | 577 { |
| 578 /* Create the file. | 578 /* Create the file. |
| 579 | 579 |
| 580 Some operating systems won't let us overwrite a running | 580 Some operating systems won't let us overwrite a running |
| 581 binary. For them, we want to unlink the file first. | 581 binary. For them, we want to unlink the file first. |
| 582 | 582 |
| 583 However, gcc 2.95 will create temporary files using | 583 However, gcc 2.95 will create temporary files using |
| 584 O_EXCL and tight permissions to prevent other users from | 584 O_EXCL and tight permissions to prevent other users from |
| 585 substituting other .o files during the compilation. gcc | 585 substituting other .o files during the compilation. gcc |
| 586 will then tell the assembler to use the newly created | 586 will then tell the assembler to use the newly created |
| 587 file as an output file. If we unlink the file here, we | 587 file as an output file. If we unlink the file here, we |
| 588 open a brief window when another user could still | 588 open a brief window when another user could still |
| 589 substitute a file. | 589 substitute a file. |
| 590 | 590 |
| 591 So we unlink the output file if and only if it has | 591 So we unlink the output file if and only if it has |
| 592 non-zero size. */ | 592 non-zero size. */ |
| 593 #ifndef __MSDOS__ | 593 #ifndef __MSDOS__ |
| 594 /* Don't do this for MSDOS: it doesn't care about overwriting | 594 /* Don't do this for MSDOS: it doesn't care about overwriting |
| 595 a running binary, but if this file is already open by | 595 a running binary, but if this file is already open by |
| 596 another BFD, we will be in deep trouble if we delete an | 596 another BFD, we will be in deep trouble if we delete an |
| 597 open file. In fact, objdump does just that if invoked with | 597 open file. In fact, objdump does just that if invoked with |
| 598 the --info option. */ | 598 the --info option. */ |
| 599 struct stat s; | 599 struct stat s; |
| 600 | 600 |
| 601 if (stat (abfd->filename, &s) == 0 && s.st_size != 0) | 601 if (stat (abfd->filename, &s) == 0 && s.st_size != 0) |
| 602 unlink_if_ordinary (abfd->filename); | 602 unlink_if_ordinary (abfd->filename); |
| 603 #endif | 603 #endif |
| 604 » abfd->iostream = (PTR) real_fopen (abfd->filename, FOPEN_WUB); | 604 » abfd->iostream = real_fopen (abfd->filename, FOPEN_WUB); |
| 605 abfd->opened_once = TRUE; | 605 abfd->opened_once = TRUE; |
| 606 } | 606 } |
| 607 break; | 607 break; |
| 608 } | 608 } |
| 609 | 609 |
| 610 if (abfd->iostream == NULL) | 610 if (abfd->iostream == NULL) |
| 611 bfd_set_error (bfd_error_system_call); | 611 bfd_set_error (bfd_error_system_call); |
| 612 else | 612 else |
| 613 { | 613 { |
| 614 if (! bfd_cache_init (abfd)) | 614 if (! bfd_cache_init (abfd)) |
| 615 return NULL; | 615 return NULL; |
| 616 } | 616 } |
| 617 | 617 |
| 618 return (FILE *) abfd->iostream; | 618 return (FILE *) abfd->iostream; |
| 619 } | 619 } |
| OLD | NEW |