1 /* ar.c - Archive modify and extract.
2 Copyright 1991, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 Bugs: should use getopt the way tar does (complete w/optional -) and
23 should have long options too. GNU ar used to check file against filesystem
24 in quick_update and replace operations (would check mtime). Doesn't warn
25 when name truncated. No way to specify pos_end. Error messages should be
29 #include "libiberty.h"
38 #define EXT_NAME_LEN 3 /* bufflen of addition to name if it's MS-DOS */
40 #define EXT_NAME_LEN 6 /* ditto for *NIX */
43 /* We need to open files in binary modes on system where that makes a
51 /* Kludge declaration from BFD! This is ugly! FIXME! XXX */
54 bfd_special_undocumented_glue PARAMS ((bfd * abfd, const char *filename));
56 /* Static declarations */
59 mri_emul PARAMS ((void));
62 normalize PARAMS ((const char *, bfd *));
65 remove_output PARAMS ((void));
68 map_over_members PARAMS ((bfd *, void (*)(bfd *), char **, int));
71 print_contents PARAMS ((bfd * member));
74 delete_members PARAMS ((bfd *, char **files_to_delete));
78 do_quick_append PARAMS ((const char *archive_filename,
79 char **files_to_append));
83 move_members PARAMS ((bfd *, char **files_to_move));
86 replace_members PARAMS ((bfd *, char **files_to_replace, boolean quick));
89 print_descr PARAMS ((bfd * abfd));
92 write_archive PARAMS ((bfd *));
95 ranlib_only PARAMS ((const char *archname));
98 ranlib_touch PARAMS ((const char *archname));
101 usage PARAMS ((int));
103 /** Globals and flags */
107 /* This flag distinguishes between ar and ranlib:
108 1 means this is 'ranlib'; 0 means this is 'ar'.
109 -1 means if we should use argv[0] to decide. */
110 extern int is_ranlib;
112 /* Nonzero means don't warn about creating the archive file if necessary. */
113 int silent_create = 0;
115 /* Nonzero means describe each action performed. */
118 /* Nonzero means preserve dates of members when extracting them. */
119 int preserve_dates = 0;
121 /* Nonzero means don't replace existing members whose dates are more recent
122 than the corresponding files. */
125 /* Controls the writing of an archive symbol table (in BSD: a __.SYMDEF
126 member). -1 means we've been explicitly asked to not write a symbol table;
127 +1 means we've been explictly asked to write it;
129 Traditionally, the default in BSD has been to not write the table.
130 However, for POSIX.2 compliance the default is now to write a symbol table
131 if any of the members are object files. */
134 /* Nonzero means it's the name of an existing member; position new or moved
135 files with respect to this one. */
136 char *posname = NULL;
138 /* Sez how to use `posname': pos_before means position before that member.
139 pos_after means position after that member. pos_end means always at end.
140 pos_default means default appropriately. For the latter two, `posname'
141 should also be zero. */
144 pos_default, pos_before, pos_after, pos_end
145 } postype = pos_default;
148 get_pos_bfd PARAMS ((bfd **, enum pos, const char *));
150 /* Whether to truncate names of files stored in the archive. */
151 static boolean ar_truncate = false;
153 /* Whether to use a full file name match when searching an archive.
154 This is convenient for archives created by the Microsoft lib
156 static boolean full_pathname = false;
163 interactive = isatty (fileno (stdin));
167 /* If COUNT is 0, then FUNCTION is called once on each entry. If nonzero,
168 COUNT is the length of the FILES chain; FUNCTION is called on each entry
169 whose name matches one in FILES. */
172 map_over_members (arch, function, files, count)
174 void (*function) PARAMS ((bfd *));
182 for (head = arch->next; head; head = head->next)
189 /* This may appear to be a baroque way of accomplishing what we want.
190 However we have to iterate over the filenames in order to notice where
191 a filename is requested but does not exist in the archive. Ditto
192 mapping over each file each time -- we want to hack multiple
195 for (; count > 0; files++, count--)
197 boolean found = false;
199 for (head = arch->next; head; head = head->next)
202 if (head->filename == NULL)
204 /* Some archive formats don't get the filenames filled in
205 until the elements are opened. */
207 bfd_stat_arch_elt (head, &buf);
209 if ((head->filename != NULL) &&
210 (!strcmp (normalize (*files, arch), head->filename)))
217 /* xgettext:c-format */
218 fprintf (stderr, _("no entry %s in archive\n"), *files);
222 boolean operation_alters_arch = false;
230 s = help ? stdout : stderr;
234 /* xgettext:c-format */
235 fprintf (s, _("Usage: %s [-]{dmpqrstx}[abcilosSuvV] [member-name] archive-file file...\n"), program_name);
236 /* xgettext:c-format */
237 fprintf (s, _(" %s -M [<mri-script]\n"), program_name);
238 fprintf (s, _(" commands:\n"));
239 fprintf (s, _(" d - delete file(s) from the archive\n"));
240 fprintf (s, _(" m[ab] - move file(s) in the archive\n"));
241 fprintf (s, _(" p - print file(s) found in the archive\n"));
242 fprintf (s, _(" q[f] - quick append file(s) to the archive\n"));
243 fprintf (s, _(" r[ab][f][u] - replace existing or insert new file(s) into the archive\n"));
244 fprintf (s, _(" t - display contents of archive\n"));
245 fprintf (s, _(" x[o] - extract file(s) from the archive\n"));
246 fprintf (s, _(" command specific modifiers:\n"));
247 fprintf (s, _(" [a] - put file(s) after [member-name]\n"));
248 fprintf (s, _(" [b] - put file(s) before [member-name] (same as [i])\n"));
249 fprintf (s, _(" [f] - truncate inserted file names\n"));
250 fprintf (s, _(" [P] - use full path names when matching\n"));
251 fprintf (s, _(" [o] - preserve original dates\n"));
252 fprintf (s, _(" [u] - only replace files that are newer than current archive contents\n"));
253 fprintf (s, _(" generic modifiers:\n"));
254 fprintf (s, _(" [c] - do not warn if the library had to be created\n"));
255 fprintf (s, _(" [s] - create an archive index (cf. ranlib)\n"));
256 fprintf (s, _(" [S] - do not build a symbol table\n"));
257 fprintf (s, _(" [v] - be verbose\n"));
258 fprintf (s, _(" [V] - display the version number\n"));
261 /* xgettext:c-format */
262 fprintf (s, _("Usage: %s [-vV] archive\n"), program_name);
264 list_supported_targets (program_name, stderr);
267 fprintf (s, _("Report bugs to bug-gnu-utils@gnu.org\n"));
269 xexit (help ? 0 : 1);
272 /* Normalize a file name specified on the command line into a file
273 name which we will use in an archive. */
276 normalize (file, abfd)
280 const char *filename;
285 filename = strrchr (file, '/');
286 if (filename != (char *) NULL)
293 && strlen (filename) > abfd->xvec->ar_max_namelen)
298 s = (char *) xmalloc (abfd->xvec->ar_max_namelen + 1);
299 memcpy (s, filename, abfd->xvec->ar_max_namelen);
300 s[abfd->xvec->ar_max_namelen] = '\0';
307 /* Remove any output file. This is only called via xatexit. */
309 static const char *output_filename = NULL;
310 static FILE *output_file = NULL;
311 static bfd *output_bfd = NULL;
316 if (output_filename != NULL)
318 if (output_bfd != NULL && output_bfd->iostream != NULL)
319 fclose ((FILE *) (output_bfd->iostream));
320 if (output_file != NULL)
321 fclose (output_file);
322 unlink (output_filename);
326 /* The option parsing should be in its own function.
327 It will be when I have getopt working. */
338 none = 0, delete, replace, print_table,
339 print_files, extract, move, quick_append
343 char *inarch_filename;
346 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
347 setlocale (LC_MESSAGES, "");
349 bindtextdomain (PACKAGE, LOCALEDIR);
350 textdomain (PACKAGE);
352 program_name = argv[0];
353 xmalloc_set_program_name (program_name);
359 temp = strrchr (program_name, '/');
364 if (strlen (temp) >= 6
365 && strcmp (temp + strlen (temp) - 6, "ranlib") == 0)
371 if (argc > 1 && argv[1][0] == '-')
373 if (strcmp (argv[1], "--help") == 0)
375 else if (strcmp (argv[1], "--version") == 0)
378 print_version ("ranlib");
380 print_version ("ar");
384 START_PROGRESS (program_name, 0);
387 set_default_bfd_target ();
391 xatexit (remove_output);
395 boolean touch = false;
397 if (argc < 2 || strcmp (argv[1], "--help") == 0)
399 if (strcmp (argv[1], "-V") == 0
400 || strcmp (argv[1], "-v") == 0
401 || strncmp (argv[1], "--v", 3) == 0)
402 print_version ("ranlib");
404 if (strcmp (argv[1], "-t") == 0)
409 while (arg_index < argc)
412 ranlib_only (argv[arg_index]);
414 ranlib_touch (argv[arg_index]);
420 if (argc == 2 && strcmp (argv[1], "-M") == 0)
432 ++arg_ptr; /* compatibility */
434 while ((c = *arg_ptr++) != '\0')
445 if (operation != none)
446 fatal (_("two different operation options specified"));
451 operation_alters_arch = true;
455 operation_alters_arch = true;
458 operation = print_files;
461 operation = quick_append;
462 operation_alters_arch = true;
466 operation_alters_arch = true;
469 operation = print_table;
502 postype = pos_before;
505 postype = pos_before;
514 full_pathname = true;
517 /* xgettext:c-format */
518 fprintf (stderr, _("%s: illegal option -- %c\n"), program_name, c);
524 print_version ("ar");
537 /* We can't write an armap when using ar q, so just do ar r
539 if (operation == quick_append && write_armap)
542 if ((operation == none || operation == print_table)
545 ranlib_only (argv[2]);
549 if (operation == none)
550 fatal (_("no operation specified"));
552 if (newer_only && operation != replace)
553 fatal (_("`u' is only meaningful with the `r' option."));
557 if (postype != pos_default)
558 posname = argv[arg_index++];
560 inarch_filename = argv[arg_index++];
562 files = arg_index < argc ? argv + arg_index : NULL;
565 /* We don't use do_quick_append any more. Too many systems
566 expect ar to always rebuild the symbol table even when q is
569 /* We can't do a quick append if we need to construct an
570 extended name table, because do_quick_append won't be able to
571 rebuild the name table. Unfortunately, at this point we
572 don't actually know the maximum name length permitted by this
573 object file format. So, we guess. FIXME. */
574 if (operation == quick_append && ! ar_truncate)
578 for (chk = files; chk != NULL && *chk != '\0'; chk++)
580 if (strlen (normalize (*chk, (bfd *) NULL)) > 14)
588 if (operation == quick_append)
590 /* Note that quick appending to a non-existent archive creates it,
591 even if there are no files to append. */
592 do_quick_append (inarch_filename, files);
597 arch = open_inarch (inarch_filename,
598 files == NULL ? (char *) NULL : files[0]);
603 map_over_members (arch, print_descr, files, argc - 3);
607 map_over_members (arch, print_contents, files, argc - 3);
611 map_over_members (arch, extract_file, files, argc - 3);
616 delete_members (arch, files);
621 move_members (arch, files);
626 if (files != NULL || write_armap > 0)
627 replace_members (arch, files, operation == quick_append);
630 /* Shouldn't happen! */
632 /* xgettext:c-format */
633 fprintf (stderr, _("%s: internal error -- this option not implemented\n"),
639 END_PROGRESS (program_name);
646 open_inarch (archive_filename, file)
647 const char *archive_filename;
657 bfd_set_error (bfd_error_no_error);
661 if (stat (archive_filename, &sbuf) != 0)
665 /* KLUDGE ALERT! Temporary fix until I figger why
666 * stat() is wrong ... think it's buried in GO32's IDT
670 bfd_fatal (archive_filename);
673 if (!operation_alters_arch)
675 fprintf (stderr, "%s: ", program_name);
676 perror (archive_filename);
681 /* Try to figure out the target to use for the archive from the
682 first object on the list. */
687 obj = bfd_openr (file, NULL);
690 if (bfd_check_format (obj, bfd_object))
691 target = bfd_get_target (obj);
692 (void) bfd_close (obj);
696 /* Create an empty archive. */
697 arch = bfd_openw (archive_filename, target);
699 || ! bfd_set_format (arch, bfd_archive)
700 || ! bfd_close (arch))
701 bfd_fatal (archive_filename);
703 /* If we die creating a new archive, don't leave it around. */
704 output_filename = archive_filename;
707 arch = bfd_openr (archive_filename, target);
711 bfd_fatal (archive_filename);
714 if (! bfd_check_format_matches (arch, bfd_archive, &matching))
716 bfd_nonfatal (archive_filename);
717 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
719 list_matching_formats (matching);
725 last_one = &(arch->next);
726 /* Read all the contents right away, regardless. */
727 for (next_one = bfd_openr_next_archived_file (arch, NULL);
729 next_one = bfd_openr_next_archived_file (arch, next_one))
732 *last_one = next_one;
733 last_one = &next_one->next;
735 *last_one = (bfd *) NULL;
736 if (bfd_get_error () != bfd_error_no_more_archived_files)
742 print_contents (abfd)
746 char *cbuf = xmalloc (BUFSIZE);
749 if (bfd_stat_arch_elt (abfd, &buf) != 0)
750 /* xgettext:c-format */
751 fatal (_("internal stat error on %s"), bfd_get_filename (abfd));
754 /* xgettext:c-format */
755 printf (_("\n<member %s>\n\n"), bfd_get_filename (abfd));
757 bfd_seek (abfd, 0, SEEK_SET);
760 while (ncopied < size)
764 int tocopy = size - ncopied;
765 if (tocopy > BUFSIZE)
768 nread = bfd_read (cbuf, 1, tocopy, abfd); /* oops -- broke
771 /* xgettext:c-format */
772 fatal (_("%s is not a valid archive"),
773 bfd_get_filename (bfd_my_archive (abfd)));
774 fwrite (cbuf, 1, nread, stdout);
780 /* Extract a member of the archive into its own file.
782 We defer opening the new file until after we have read a BUFSIZ chunk of the
783 old one, since we know we have just read the archive header for the old
784 one. Since most members are shorter than BUFSIZ, this means we will read
785 the old header, read the old data, write a new inode for the new file, and
786 write the new data, and be done. This 'optimization' is what comes from
787 sitting next to a bare disk and hearing it every time it seeks. -- Gnu
795 char *cbuf = xmalloc (BUFSIZE);
801 if (bfd_stat_arch_elt (abfd, &buf) != 0)
802 /* xgettext:c-format */
803 fatal (_("internal stat error on %s"), bfd_get_filename (abfd));
807 /* xgettext:c-format */
808 fatal (_("stat returns negative size for %s"), bfd_get_filename (abfd));
811 printf ("x - %s\n", bfd_get_filename (abfd));
813 bfd_seek (abfd, 0, SEEK_SET);
818 /* Seems like an abstraction violation, eh? Well it's OK! */
819 output_filename = bfd_get_filename (abfd);
821 ostream = fopen (bfd_get_filename (abfd), FOPEN_WB);
824 perror (bfd_get_filename (abfd));
828 output_file = ostream;
831 while (ncopied < size)
833 tocopy = size - ncopied;
834 if (tocopy > BUFSIZE)
837 nread = bfd_read (cbuf, 1, tocopy, abfd);
839 /* xgettext:c-format */
840 fatal (_("%s is not a valid archive"),
841 bfd_get_filename (bfd_my_archive (abfd)));
843 /* See comment above; this saves disk arm motion */
846 /* Seems like an abstraction violation, eh? Well it's OK! */
847 output_filename = bfd_get_filename (abfd);
849 ostream = fopen (bfd_get_filename (abfd), FOPEN_WB);
852 perror (bfd_get_filename (abfd));
856 output_file = ostream;
858 fwrite (cbuf, 1, nread, ostream);
866 output_filename = NULL;
868 chmod (bfd_get_filename (abfd), buf.st_mode);
871 set_times (bfd_get_filename (abfd), &buf);
878 /* We don't use this anymore. Too many systems expect ar to rebuild
879 the symbol table even when q is used. */
881 /* Just do it quickly; don't worry about dups, armap, or anything like that */
884 do_quick_append (archive_filename, files_to_append)
885 const char *archive_filename;
886 char **files_to_append;
889 char *buf = xmalloc (BUFSIZE);
890 long tocopy, thistime;
893 boolean newfile = false;
894 bfd_set_error (bfd_error_no_error);
896 if (stat (archive_filename, &sbuf) != 0)
901 /* KLUDGE ALERT! Temporary fix until I figger why
902 * stat() is wrong ... think it's buried in GO32's IDT
907 bfd_fatal (archive_filename);
913 ofile = fopen (archive_filename, FOPEN_AUB);
916 perror (program_name);
920 temp = bfd_openr (archive_filename, NULL);
923 bfd_fatal (archive_filename);
925 if (newfile == false)
927 if (bfd_check_format (temp, bfd_archive) != true)
928 /* xgettext:c-format */
929 fatal (_("%s is not an archive"), archive_filename);
933 fwrite (ARMAG, 1, SARMAG, ofile);
935 /* xgettext:c-format */
936 fprintf (stderr, _("%s: creating %s\n"),
937 program_name, archive_filename);
941 temp->flags |= BFD_TRADITIONAL_FORMAT;
943 /* assume it's an achive, go straight to the end, sans $200 */
946 for (; files_to_append && *files_to_append; ++files_to_append)
948 struct ar_hdr *hdr = bfd_special_undocumented_glue (temp, *files_to_append);
951 bfd_fatal (*files_to_append);
954 BFD_SEND (temp, _bfd_truncate_arname, (temp, *files_to_append, (char *) hdr));
956 ifile = fopen (*files_to_append, FOPEN_RB);
959 bfd_nonfatal (*files_to_append);
962 if (stat (*files_to_append, &sbuf) != 0)
964 bfd_nonfatal (*files_to_append);
967 tocopy = sbuf.st_size;
969 /* XXX should do error-checking! */
970 fwrite (hdr, 1, sizeof (struct ar_hdr), ofile);
975 if (thistime > BUFSIZE)
977 fread (buf, 1, thistime, ifile);
978 fwrite (buf, 1, thistime, ofile);
982 if ((sbuf.st_size % 2) == 1)
983 putc ('\012', ofile);
993 write_archive (iarch)
997 char *old_name, *new_name;
998 bfd *contents_head = iarch->next;
1000 old_name = xmalloc (strlen (bfd_get_filename (iarch)) + 1);
1001 strcpy (old_name, bfd_get_filename (iarch));
1002 new_name = make_tempname (old_name);
1004 output_filename = new_name;
1006 obfd = bfd_openw (new_name, bfd_get_target (iarch));
1009 bfd_fatal (old_name);
1013 bfd_set_format (obfd, bfd_archive);
1015 /* Request writing the archive symbol table unless we've
1016 been explicitly requested not to. */
1017 obfd->has_armap = write_armap >= 0;
1021 /* This should really use bfd_set_file_flags, but that rejects
1023 obfd->flags |= BFD_TRADITIONAL_FORMAT;
1026 if (bfd_set_archive_head (obfd, contents_head) != true)
1027 bfd_fatal (old_name);
1029 if (!bfd_close (obfd))
1030 bfd_fatal (old_name);
1033 output_filename = NULL;
1035 /* We don't care if this fails; we might be creating the archive. */
1038 if (smart_rename (new_name, old_name, 0) != 0)
1042 /* Return a pointer to the pointer to the entry which should be rplacd'd
1043 into when altering. DEFAULT_POS should be how to interpret pos_default,
1044 and should be a pos value. */
1047 get_pos_bfd (contents, default_pos, default_posname)
1049 enum pos default_pos;
1050 const char *default_posname;
1052 bfd **after_bfd = contents;
1054 const char *realposname;
1056 if (postype == pos_default)
1058 realpos = default_pos;
1059 realposname = default_posname;
1064 realposname = posname;
1067 if (realpos == pos_end)
1070 after_bfd = &((*after_bfd)->next);
1074 for (; *after_bfd; after_bfd = &(*after_bfd)->next)
1075 if (strcmp ((*after_bfd)->filename, realposname) == 0)
1077 if (realpos == pos_after)
1078 after_bfd = &(*after_bfd)->next;
1086 delete_members (arch, files_to_delete)
1088 char **files_to_delete;
1090 bfd **current_ptr_ptr;
1092 boolean something_changed = false;
1093 for (; *files_to_delete != NULL; ++files_to_delete)
1095 /* In a.out systems, the armap is optional. It's also called
1096 __.SYMDEF. So if the user asked to delete it, we should remember
1097 that fact. This isn't quite right for COFF systems (where
1098 __.SYMDEF might be regular member), but it's very unlikely
1099 to be a problem. FIXME */
1101 if (!strcmp (*files_to_delete, "__.SYMDEF"))
1103 arch->has_armap = false;
1109 current_ptr_ptr = &(arch->next);
1110 while (*current_ptr_ptr)
1112 if (strcmp (*files_to_delete, (*current_ptr_ptr)->filename) == 0)
1115 something_changed = true;
1119 *current_ptr_ptr = ((*current_ptr_ptr)->next);
1124 current_ptr_ptr = &((*current_ptr_ptr)->next);
1128 if (verbose && found == false)
1130 /* xgettext:c-format */
1131 printf (_("No member named `%s'\n"), *files_to_delete);
1137 if (something_changed == true)
1139 write_archive (arch);
1144 /* Reposition existing members within an archive */
1147 move_members (arch, files_to_move)
1149 char **files_to_move;
1151 bfd **after_bfd; /* New entries go after this one */
1152 bfd **current_ptr_ptr; /* cdr pointer into contents */
1154 for (; *files_to_move; ++files_to_move)
1156 current_ptr_ptr = &(arch->next);
1157 while (*current_ptr_ptr)
1159 bfd *current_ptr = *current_ptr_ptr;
1160 if (strcmp (normalize (*files_to_move, arch),
1161 current_ptr->filename) == 0)
1163 /* Move this file to the end of the list - first cut from
1166 *current_ptr_ptr = current_ptr->next;
1168 /* Now glue to end */
1169 after_bfd = get_pos_bfd (&arch->next, pos_end, NULL);
1171 *after_bfd = current_ptr;
1172 current_ptr->next = link;
1175 printf ("m - %s\n", *files_to_move);
1180 current_ptr_ptr = &((*current_ptr_ptr)->next);
1182 /* xgettext:c-format */
1183 fprintf (stderr, _("%s: no entry %s in archive %s!\n"),
1184 program_name, *files_to_move, arch->filename);
1189 write_archive (arch);
1192 /* Ought to default to replacing in place, but this is existing practice! */
1195 replace_members (arch, files_to_move, quick)
1197 char **files_to_move;
1200 boolean changed = false;
1201 bfd **after_bfd; /* New entries go after this one */
1206 while (files_to_move && *files_to_move)
1210 current_ptr = &arch->next;
1211 while (*current_ptr)
1213 current = *current_ptr;
1215 /* For compatibility with existing ar programs, we
1216 permit the same file to be added multiple times. */
1217 if (strcmp (normalize (*files_to_move, arch),
1218 normalize (current->filename, arch)) == 0
1219 && current->arelt_data != NULL)
1223 struct stat fsbuf, asbuf;
1225 if (stat (*files_to_move, &fsbuf) != 0)
1227 if (errno != ENOENT)
1228 bfd_fatal (*files_to_move);
1231 if (bfd_stat_arch_elt (current, &asbuf) != 0)
1232 /* xgettext:c-format */
1233 fatal (_("internal stat error on %s"), current->filename);
1235 if (fsbuf.st_mtime <= asbuf.st_mtime)
1239 after_bfd = get_pos_bfd (&arch->next, pos_after,
1243 *after_bfd = bfd_openr (*files_to_move, NULL);
1244 if (*after_bfd == (bfd *) NULL)
1246 bfd_fatal (*files_to_move);
1248 (*after_bfd)->next = temp;
1250 /* snip out this entry from the chain */
1251 *current_ptr = (*current_ptr)->next;
1255 printf ("r - %s\n", *files_to_move);
1262 current_ptr = &(current->next);
1266 /* Add to the end of the archive. */
1268 after_bfd = get_pos_bfd (&arch->next, pos_end, NULL);
1270 *after_bfd = bfd_openr (*files_to_move, NULL);
1271 if (*after_bfd == (bfd *) NULL)
1273 bfd_fatal (*files_to_move);
1277 printf ("a - %s\n", *files_to_move);
1280 (*after_bfd)->next = temp;
1290 write_archive (arch);
1294 ranlib_only (archname)
1295 const char *archname;
1300 arch = open_inarch (archname, (char *) NULL);
1303 write_archive (arch);
1306 /* Update the timestamp of the symbol map of an archive. */
1309 ranlib_touch (archname)
1310 const char *archname;
1313 /* I don't think updating works on go32. */
1314 ranlib_only (archname);
1320 f = open (archname, O_RDWR | O_BINARY, 0);
1323 bfd_set_error (bfd_error_system_call);
1324 bfd_fatal (archname);
1327 arch = bfd_fdopenr (archname, (const char *) NULL, f);
1329 bfd_fatal (archname);
1330 if (! bfd_check_format_matches (arch, bfd_archive, &matching))
1332 bfd_nonfatal (archname);
1333 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
1335 list_matching_formats (matching);
1341 if (! bfd_has_map (arch))
1342 /* xgettext:c-format */
1343 fatal (_("%s: no archive map to update"), archname);
1345 bfd_update_armap_timestamp (arch);
1347 if (! bfd_close (arch))
1348 bfd_fatal (archname);
1352 /* Things which are interesting to map over all or some of the files: */
1358 print_arelt_descr (stdout, abfd, verbose);