Changes to make -Ur work again.
[deliverable/binutils-gdb.git] / binutils / bucomm.c
1 /* bucomm.c -- Bin Utils COMmon code.
2 Copyright (C) 1991 Free Software Foundation, Inc.
3
4 This file is part of GNU Binutils.
5
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 2 of the License, or
9 (at your option) any later version.
10
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.
15
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
19 \f
20 /* We might put this in a library someday so it could be dynamically
21 loaded, but for now it's not necessary. */
22
23 #include "bfd.h"
24 #include "sysdep.h"
25 #include "bucomm.h"
26
27 #ifdef __STDC__
28 #include <stdarg.h>
29 #else
30 #include <varargs.h>
31 #endif
32
33 char *target = NULL; /* default as late as possible */
34
35 /* Yes, this is what atexit is for, but that isn't guaranteed yet.
36 And yes, I know this isn't as good, but it does what is needed just fine. */
37 void (*exit_handler) ();
38
39
40 /* Error reporting */
41
42 char *program_name;
43
44 void
45 bfd_nonfatal (string)
46 CONST char *string;
47 {
48 CONST char *errmsg = bfd_errmsg (bfd_error);
49
50 if (string)
51 fprintf (stderr, "%s: %s: %s\n", program_name, string, errmsg);
52 else
53 fprintf (stderr, "%s: %s\n", program_name, errmsg);
54 }
55
56 void
57 bfd_fatal (string)
58 CONST char *string;
59 {
60 bfd_nonfatal (string);
61
62 if (NULL != exit_handler)
63 (*exit_handler) ();
64 exit (1);
65 }
66
67 #ifdef __STDC__
68 void
69 fatal (const char *format, ...)
70 {
71 va_list args;
72
73 fprintf (stderr, "%s: ", program_name);
74 va_start (args, format);
75 vfprintf (stderr, format, args);
76 va_end (args);
77 putc ('\n', stderr);
78 if (NULL != exit_handler)
79 (*exit_handler) ();
80 exit (1);
81 }
82 #else
83 void
84 fatal (va_alist)
85 va_dcl
86 {
87 char *Format;
88 va_list args;
89
90 fprintf (stderr, "%s: ", program_name);
91 va_start (args);
92 Format = va_arg (args, char *);
93 vfprintf (stderr, Format, args);
94 va_end (args);
95 putc ('\n', stderr);
96 if (NULL != exit_handler)
97 (*exit_handler) ();
98 exit (1);
99 }
100 #endif
101 \f
102 /* Display the archive header for an element as if it were an ls -l listing:
103
104 Mode User\tGroup\tSize\tDate Name */
105
106 void
107 print_arelt_descr (file, abfd, verbose)
108 FILE *file;
109 bfd *abfd;
110 boolean verbose;
111 {
112 struct stat buf;
113
114 if (verbose)
115 {
116 if (bfd_stat_arch_elt (abfd, &buf) == 0)
117 {
118 char modebuf[11];
119 char timebuf[40];
120 time_t when = buf.st_mtime;
121 CONST char *ctime_result = (CONST char *) ctime (&when);
122
123 /* POSIX format: skip weekday and seconds from ctime output. */
124 sprintf (timebuf, "%.12s %.4s", ctime_result + 4, ctime_result + 20);
125
126 mode_string (buf.st_mode, modebuf);
127 modebuf[10] = '\0';
128 /* POSIX 1003.2/D11 says to skip first character (entry type). */
129 fprintf (file, "%s %d/%d %6ld %s ", modebuf + 1,
130 buf.st_uid, buf.st_gid, buf.st_size, timebuf);
131 }
132 }
133
134 fprintf (file, "%s\n", abfd->filename);
135 }
This page took 0.040449 seconds and 4 git commands to generate.