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