Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: bfd/opncls.c

Issue 11969036: Merge GDB 7.5.1 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « bfd/oasys.c ('k') | bfd/osf-core.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012
4 Free Software Foundation, Inc. 4 Free Software Foundation, Inc.
5 5
6 Written by Cygnus Support. 6 Written by Cygnus Support.
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
11 it under the terms of the GNU General Public License as published by 11 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 12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version. 13 (at your option) any later version.
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 <<fdopen>>. 183 <<fdopen>>.
184 184
185 Calls <<bfd_find_target>>, so @var{target} is interpreted as by 185 Calls <<bfd_find_target>>, so @var{target} is interpreted as by
186 that function. 186 that function.
187 187
188 The new BFD is marked as cacheable iff @var{fd} is -1. 188 The new BFD is marked as cacheable iff @var{fd} is -1.
189 189
190 If <<NULL>> is returned then an error has occured. Possible errors 190 If <<NULL>> is returned then an error has occured. Possible errors
191 are <<bfd_error_no_memory>>, <<bfd_error_invalid_target>> or 191 are <<bfd_error_no_memory>>, <<bfd_error_invalid_target>> or
192 <<system_call>> error. 192 <<system_call>> error.
193
194 On error, @var{fd} is always closed.
193 */ 195 */
194 196
195 bfd * 197 bfd *
196 bfd_fopen (const char *filename, const char *target, const char *mode, int fd) 198 bfd_fopen (const char *filename, const char *target, const char *mode, int fd)
197 { 199 {
198 bfd *nbfd; 200 bfd *nbfd;
199 const bfd_target *target_vec; 201 const bfd_target *target_vec;
200 202
201 nbfd = _bfd_new_bfd (); 203 nbfd = _bfd_new_bfd ();
202 if (nbfd == NULL) 204 if (nbfd == NULL)
203 return NULL; 205 {
206 if (fd != -1)
207 » close (fd);
208 return NULL;
209 }
204 210
205 target_vec = bfd_find_target (target, nbfd); 211 target_vec = bfd_find_target (target, nbfd);
206 if (target_vec == NULL) 212 if (target_vec == NULL)
207 { 213 {
214 if (fd != -1)
215 close (fd);
208 _bfd_delete_bfd (nbfd); 216 _bfd_delete_bfd (nbfd);
209 return NULL; 217 return NULL;
210 } 218 }
211 219
212 #ifdef HAVE_FDOPEN 220 #ifdef HAVE_FDOPEN
213 if (fd != -1) 221 if (fd != -1)
214 nbfd->iostream = fdopen (fd, mode); 222 nbfd->iostream = fdopen (fd, mode);
215 else 223 else
216 #endif 224 #endif
217 nbfd->iostream = real_fopen (filename, mode); 225 nbfd->iostream = real_fopen (filename, mode);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 cached by BFD (opened as needed, closed as needed to free 308 cached by BFD (opened as needed, closed as needed to free
301 descriptors for other opens), with the supplied @var{fd} used as 309 descriptors for other opens), with the supplied @var{fd} used as
302 an initial file descriptor (but subject to closure at any time), 310 an initial file descriptor (but subject to closure at any time),
303 call bfd_set_cacheable(bfd, 1) on the returned BFD. The default 311 call bfd_set_cacheable(bfd, 1) on the returned BFD. The default
304 is to assume no caching; the file descriptor will remain open 312 is to assume no caching; the file descriptor will remain open
305 until <<bfd_close>>, and will not be affected by BFD operations 313 until <<bfd_close>>, and will not be affected by BFD operations
306 on other files. 314 on other files.
307 315
308 Possible errors are <<bfd_error_no_memory>>, 316 Possible errors are <<bfd_error_no_memory>>,
309 <<bfd_error_invalid_target>> and <<bfd_error_system_call>>. 317 <<bfd_error_invalid_target>> and <<bfd_error_system_call>>.
318
319 On error, @var{fd} is closed.
310 */ 320 */
311 321
312 bfd * 322 bfd *
313 bfd_fdopenr (const char *filename, const char *target, int fd) 323 bfd_fdopenr (const char *filename, const char *target, int fd)
314 { 324 {
315 const char *mode; 325 const char *mode;
316 #if defined(HAVE_FCNTL) && defined(F_GETFL) 326 #if defined(HAVE_FCNTL) && defined(F_GETFL)
317 int fdflags; 327 int fdflags;
318 #endif 328 #endif
319 329
320 #if ! defined(HAVE_FCNTL) || ! defined(F_GETFL) 330 #if ! defined(HAVE_FCNTL) || ! defined(F_GETFL)
321 mode = FOPEN_RUB; /* Assume full access. */ 331 mode = FOPEN_RUB; /* Assume full access. */
322 #else 332 #else
323 fdflags = fcntl (fd, F_GETFL, NULL); 333 fdflags = fcntl (fd, F_GETFL, NULL);
324 if (fdflags == -1) 334 if (fdflags == -1)
325 { 335 {
336 int save = errno;
337
338 close (fd);
339 errno = save;
326 bfd_set_error (bfd_error_system_call); 340 bfd_set_error (bfd_error_system_call);
327 return NULL; 341 return NULL;
328 } 342 }
329 343
330 /* (O_ACCMODE) parens are to avoid Ultrix header file bug. */ 344 /* (O_ACCMODE) parens are to avoid Ultrix header file bug. */
331 switch (fdflags & (O_ACCMODE)) 345 switch (fdflags & (O_ACCMODE))
332 { 346 {
333 case O_RDONLY: mode = FOPEN_RB; break; 347 case O_RDONLY: mode = FOPEN_RB; break;
334 case O_WRONLY: mode = FOPEN_RUB; break; 348 case O_WRONLY: mode = FOPEN_RUB; break;
335 case O_RDWR: mode = FOPEN_RUB; break; 349 case O_RDWR: mode = FOPEN_RUB; break;
(...skipping 1187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 1537
1524 if (! bfd_set_section_contents (abfd, sect, contents, 0, debuglink_size)) 1538 if (! bfd_set_section_contents (abfd, sect, contents, 0, debuglink_size))
1525 { 1539 {
1526 /* XXX Should we delete the section from the bfd ? */ 1540 /* XXX Should we delete the section from the bfd ? */
1527 free (contents); 1541 free (contents);
1528 return FALSE; 1542 return FALSE;
1529 } 1543 }
1530 1544
1531 return TRUE; 1545 return TRUE;
1532 } 1546 }
OLDNEW
« no previous file with comments | « bfd/oasys.c ('k') | bfd/osf-core.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698