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