| OLD | NEW |
| 1 /* opncls.c -- open and close a BFD. | 1 /* opncls.c -- open and close a BFD. |
| 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, | 2 Copyright 1990-2013 Free Software Foundation, Inc. |
| 3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 | |
| 4 Free Software Foundation, Inc. | |
| 5 | 3 |
| 6 Written by Cygnus Support. | 4 Written by Cygnus Support. |
| 7 | 5 |
| 8 This file is part of BFD, the Binary File Descriptor library. | 6 This file is part of BFD, the Binary File Descriptor library. |
| 9 | 7 |
| 10 This program is free software; you can redistribute it and/or modify | 8 This program is free software; you can redistribute it and/or modify |
| 11 it under the terms of the GNU General Public License as published by | 9 it under the terms of the GNU General Public License as published by |
| 12 the Free Software Foundation; either version 3 of the License, or | 10 the Free Software Foundation; either version 3 of the License, or |
| 13 (at your option) any later version. | 11 (at your option) any later version. |
| 14 | 12 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 nbfd->memory = objalloc_create (); | 73 nbfd->memory = objalloc_create (); |
| 76 if (nbfd->memory == NULL) | 74 if (nbfd->memory == NULL) |
| 77 { | 75 { |
| 78 bfd_set_error (bfd_error_no_memory); | 76 bfd_set_error (bfd_error_no_memory); |
| 79 free (nbfd); | 77 free (nbfd); |
| 80 return NULL; | 78 return NULL; |
| 81 } | 79 } |
| 82 | 80 |
| 83 nbfd->arch_info = &bfd_default_arch_struct; | 81 nbfd->arch_info = &bfd_default_arch_struct; |
| 84 | 82 |
| 85 nbfd->direction = no_direction; | |
| 86 nbfd->iostream = NULL; | |
| 87 nbfd->where = 0; | |
| 88 if (!bfd_hash_table_init_n (& nbfd->section_htab, bfd_section_hash_newfunc, | 83 if (!bfd_hash_table_init_n (& nbfd->section_htab, bfd_section_hash_newfunc, |
| 89 » » » sizeof (struct section_hash_entry), 251)) | 84 » » » sizeof (struct section_hash_entry), 13)) |
| 90 { | 85 { |
| 91 free (nbfd); | 86 free (nbfd); |
| 92 return NULL; | 87 return NULL; |
| 93 } | 88 } |
| 94 nbfd->sections = NULL; | |
| 95 nbfd->section_last = NULL; | |
| 96 nbfd->format = bfd_unknown; | |
| 97 nbfd->my_archive = NULL; | |
| 98 nbfd->origin = 0; | |
| 99 nbfd->opened_once = FALSE; | |
| 100 nbfd->output_has_begun = FALSE; | |
| 101 nbfd->section_count = 0; | |
| 102 nbfd->usrdata = NULL; | |
| 103 nbfd->cacheable = FALSE; | |
| 104 nbfd->flags = BFD_NO_FLAGS; | |
| 105 nbfd->mtime_set = FALSE; | |
| 106 | 89 |
| 107 return nbfd; | 90 return nbfd; |
| 108 } | 91 } |
| 109 | 92 |
| 93 static const struct bfd_iovec opncls_iovec; |
| 94 |
| 110 /* Allocate a new BFD as a member of archive OBFD. */ | 95 /* Allocate a new BFD as a member of archive OBFD. */ |
| 111 | 96 |
| 112 bfd * | 97 bfd * |
| 113 _bfd_new_bfd_contained_in (bfd *obfd) | 98 _bfd_new_bfd_contained_in (bfd *obfd) |
| 114 { | 99 { |
| 115 bfd *nbfd; | 100 bfd *nbfd; |
| 116 | 101 |
| 117 nbfd = _bfd_new_bfd (); | 102 nbfd = _bfd_new_bfd (); |
| 118 if (nbfd == NULL) | 103 if (nbfd == NULL) |
| 119 return NULL; | 104 return NULL; |
| 120 nbfd->xvec = obfd->xvec; | 105 nbfd->xvec = obfd->xvec; |
| 121 nbfd->iovec = obfd->iovec; | 106 nbfd->iovec = obfd->iovec; |
| 107 if (obfd->iovec == &opncls_iovec) |
| 108 nbfd->iostream = obfd->iostream; |
| 122 nbfd->my_archive = obfd; | 109 nbfd->my_archive = obfd; |
| 123 nbfd->direction = read_direction; | 110 nbfd->direction = read_direction; |
| 124 nbfd->target_defaulted = obfd->target_defaulted; | 111 nbfd->target_defaulted = obfd->target_defaulted; |
| 125 return nbfd; | 112 return nbfd; |
| 126 } | 113 } |
| 127 | 114 |
| 128 /* Delete a BFD. */ | 115 /* Delete a BFD. */ |
| 129 | 116 |
| 130 void | 117 static void |
| 131 _bfd_delete_bfd (bfd *abfd) | 118 _bfd_delete_bfd (bfd *abfd) |
| 132 { | 119 { |
| 133 if (abfd->memory) | 120 if (abfd->memory) |
| 134 { | 121 { |
| 135 bfd_hash_table_free (&abfd->section_htab); | 122 bfd_hash_table_free (&abfd->section_htab); |
| 136 objalloc_free ((struct objalloc *) abfd->memory); | 123 objalloc_free ((struct objalloc *) abfd->memory); |
| 137 } | 124 } |
| 125 |
| 126 free (abfd->arelt_data); |
| 138 free (abfd); | 127 free (abfd); |
| 139 } | 128 } |
| 140 | 129 |
| 141 /* Free objalloc memory. */ | 130 /* Free objalloc memory. */ |
| 142 | 131 |
| 143 bfd_boolean | 132 bfd_boolean |
| 144 _bfd_free_cached_info (bfd *abfd) | 133 _bfd_free_cached_info (bfd *abfd) |
| 145 { | 134 { |
| 146 if (abfd->memory) | 135 if (abfd->memory) |
| 147 { | 136 { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 173 | 162 |
| 174 SYNOPSIS | 163 SYNOPSIS |
| 175 bfd *bfd_fopen (const char *filename, const char *target, | 164 bfd *bfd_fopen (const char *filename, const char *target, |
| 176 const char *mode, int fd); | 165 const char *mode, int fd); |
| 177 | 166 |
| 178 DESCRIPTION | 167 DESCRIPTION |
| 179 Open the file @var{filename} with the target @var{target}. | 168 Open the file @var{filename} with the target @var{target}. |
| 180 Return a pointer to the created BFD. If @var{fd} is not -1, | 169 Return a pointer to the created BFD. If @var{fd} is not -1, |
| 181 then <<fdopen>> is used to open the file; otherwise, <<fopen>> | 170 then <<fdopen>> is used to open the file; otherwise, <<fopen>> |
| 182 is used. @var{mode} is passed directly to <<fopen>> or | 171 is used. @var{mode} is passed directly to <<fopen>> or |
| 183 » <<fdopen>>. | 172 » <<fdopen>>. |
| 184 | 173 |
| 185 Calls <<bfd_find_target>>, so @var{target} is interpreted as by | 174 Calls <<bfd_find_target>>, so @var{target} is interpreted as by |
| 186 that function. | 175 that function. |
| 187 | 176 |
| 188 The new BFD is marked as cacheable iff @var{fd} is -1. | 177 The new BFD is marked as cacheable iff @var{fd} is -1. |
| 189 | 178 |
| 190 If <<NULL>> is returned then an error has occured. Possible errors | 179 If <<NULL>> is returned then an error has occured. Possible errors |
| 191 are <<bfd_error_no_memory>>, <<bfd_error_invalid_target>> or | 180 are <<bfd_error_no_memory>>, <<bfd_error_invalid_target>> or |
| 192 <<system_call>> error. | 181 <<system_call>> error. |
| 193 | 182 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 209 } | 198 } |
| 210 | 199 |
| 211 target_vec = bfd_find_target (target, nbfd); | 200 target_vec = bfd_find_target (target, nbfd); |
| 212 if (target_vec == NULL) | 201 if (target_vec == NULL) |
| 213 { | 202 { |
| 214 if (fd != -1) | 203 if (fd != -1) |
| 215 close (fd); | 204 close (fd); |
| 216 _bfd_delete_bfd (nbfd); | 205 _bfd_delete_bfd (nbfd); |
| 217 return NULL; | 206 return NULL; |
| 218 } | 207 } |
| 219 | 208 |
| 220 #ifdef HAVE_FDOPEN | 209 #ifdef HAVE_FDOPEN |
| 221 if (fd != -1) | 210 if (fd != -1) |
| 222 nbfd->iostream = fdopen (fd, mode); | 211 nbfd->iostream = fdopen (fd, mode); |
| 223 else | 212 else |
| 224 #endif | 213 #endif |
| 225 nbfd->iostream = real_fopen (filename, mode); | 214 nbfd->iostream = real_fopen (filename, mode); |
| 226 if (nbfd->iostream == NULL) | 215 if (nbfd->iostream == NULL) |
| 227 { | 216 { |
| 228 bfd_set_error (bfd_error_system_call); | 217 bfd_set_error (bfd_error_system_call); |
| 229 _bfd_delete_bfd (nbfd); | 218 _bfd_delete_bfd (nbfd); |
| 230 return NULL; | 219 return NULL; |
| 231 } | 220 } |
| 232 | 221 |
| 233 /* OK, put everything where it belongs. */ | 222 /* OK, put everything where it belongs. */ |
| 234 nbfd->filename = filename; | 223 nbfd->filename = filename; |
| 235 | 224 |
| 236 /* Figure out whether the user is opening the file for reading, | 225 /* Figure out whether the user is opening the file for reading, |
| 237 writing, or both, by looking at the MODE argument. */ | 226 writing, or both, by looking at the MODE argument. */ |
| 238 if ((mode[0] == 'r' || mode[0] == 'w' || mode[0] == 'a') | 227 if ((mode[0] == 'r' || mode[0] == 'w' || mode[0] == 'a') |
| 239 && mode[1] == '+') | 228 && mode[1] == '+') |
| 240 nbfd->direction = both_direction; | 229 nbfd->direction = both_direction; |
| 241 else if (mode[0] == 'r') | 230 else if (mode[0] == 'r') |
| 242 nbfd->direction = read_direction; | 231 nbfd->direction = read_direction; |
| 243 else | 232 else |
| 244 nbfd->direction = write_direction; | 233 nbfd->direction = write_direction; |
| 245 | 234 |
| 246 if (! bfd_cache_init (nbfd)) | 235 if (! bfd_cache_init (nbfd)) |
| 247 { | 236 { |
| 248 _bfd_delete_bfd (nbfd); | 237 _bfd_delete_bfd (nbfd); |
| 249 return NULL; | 238 return NULL; |
| 250 } | 239 } |
| 251 nbfd->opened_once = TRUE; | 240 nbfd->opened_once = TRUE; |
| 241 |
| 252 /* If we opened the file by name, mark it cacheable; we can close it | 242 /* If we opened the file by name, mark it cacheable; we can close it |
| 253 and reopen it later. However, if a file descriptor was provided, | 243 and reopen it later. However, if a file descriptor was provided, |
| 254 then it may have been opened with special flags that make it | 244 then it may have been opened with special flags that make it |
| 255 unsafe to close and reopen the file. */ | 245 unsafe to close and reopen the file. */ |
| 256 if (fd == -1) | 246 if (fd == -1) |
| 257 bfd_set_cacheable (nbfd, TRUE); | 247 (void) bfd_set_cacheable (nbfd, TRUE); |
| 258 | 248 |
| 259 return nbfd; | 249 return nbfd; |
| 260 } | 250 } |
| 261 | 251 |
| 262 /* | 252 /* |
| 263 FUNCTION | 253 FUNCTION |
| 264 bfd_openr | 254 bfd_openr |
| 265 | 255 |
| 266 SYNOPSIS | 256 SYNOPSIS |
| 267 bfd *bfd_openr (const char *filename, const char *target); | 257 bfd *bfd_openr (const char *filename, const char *target); |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 All memory attached to the BFD is released. | 687 All memory attached to the BFD is released. |
| 698 | 688 |
| 699 The file descriptor associated with the BFD is closed (even | 689 The file descriptor associated with the BFD is closed (even |
| 700 if it was passed in to BFD by <<bfd_fdopenr>>). | 690 if it was passed in to BFD by <<bfd_fdopenr>>). |
| 701 | 691 |
| 702 RETURNS | 692 RETURNS |
| 703 <<TRUE>> is returned if all is ok, otherwise <<FALSE>>. | 693 <<TRUE>> is returned if all is ok, otherwise <<FALSE>>. |
| 704 */ | 694 */ |
| 705 | 695 |
| 706 | 696 |
error: old chunk mismatch |
None
| OLD | NEW |