1 /* A program to test BFD.
2 Copyright (C) 2012-2023 Free Software Foundation, Inc.
4 This file is part of the GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
27 printf ("oops: %s\n", s
);
32 iovec_open (struct bfd
*nbfd ATTRIBUTE_UNUSED
, void *open_closure
)
37 static file_ptr
iovec_read (struct bfd
*nbfd ATTRIBUTE_UNUSED
,
38 void *stream
, void *buf
, file_ptr nbytes
,
41 FILE* file
= (FILE*) stream
;
43 if (fseek(file
, offset
, SEEK_SET
) != 0)
46 return fread (buf
, 1, nbytes
, file
);
50 iovec_stat (struct bfd
*abfd ATTRIBUTE_UNUSED
,
51 void *stream
, struct stat
*sb
)
53 return fstat (fileno ((FILE*) stream
), sb
);
57 check_format_any (struct bfd
*abfd
, bfd_format format
)
59 char** targets
= NULL
;
61 if (bfd_check_format_matches (abfd
, format
, &targets
))
66 bfd_find_target (targets
[0], abfd
);
68 return bfd_check_format (abfd
, format
);
75 main (int argc
, const char** argv
)
81 die ("Usage: test archivefile");
83 file
= fopen(argv
[1], "rb");
85 die ("file not found");
87 abfd
= bfd_openr_iovec (argv
[1], 0, iovec_open
, file
,
88 iovec_read
, NULL
, iovec_stat
);
90 die ("error opening file");
92 if (!check_format_any (abfd
, bfd_archive
))
93 die ("not an archive");
95 mbfd
= bfd_openr_next_archived_file (abfd
, 0);
97 die ("error opening archive member");
99 if (!bfd_close (mbfd
))
100 die ("error closing archive member");
102 if (!bfd_close (abfd
))
103 die ("error closing archive");