2 * Copyright (c) 2003-2007 Tim Kientzle
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/queue.h>
28 #include <sys/types.h>
40 ELFTC_VCSID("$Id: util.c 3174 2015-03-27 17:13:41Z emaste $");
42 static void bsdar_vwarnc(struct bsdar *, int code,
43 const char *fmt, va_list ap);
44 static void bsdar_verrc(struct bsdar *bsdar, int code,
45 const char *fmt, va_list ap);
48 bsdar_vwarnc(struct bsdar *bsdar, int code, const char *fmt, va_list ap)
51 fprintf(stderr, "%s: warning: ", bsdar->progname);
52 vfprintf(stderr, fmt, ap);
54 fprintf(stderr, ": %s", strerror(code));
55 fprintf(stderr, "\n");
59 bsdar_warnc(struct bsdar *bsdar, int code, const char *fmt, ...)
64 bsdar_vwarnc(bsdar, code, fmt, ap);
69 bsdar_verrc(struct bsdar *bsdar, int code, const char *fmt, va_list ap)
72 fprintf(stderr, "%s: fatal: ", bsdar->progname);
73 vfprintf(stderr, fmt, ap);
75 fprintf(stderr, ": %s", strerror(code));
76 fprintf(stderr, "\n");
80 bsdar_errc(struct bsdar *bsdar, int code, const char *fmt, ...)
85 bsdar_verrc(bsdar, code, fmt, ap);
90 #define AR_STRMODE_SIZE 12
92 bsdar_strmode(mode_t m)
94 static char buf[AR_STRMODE_SIZE];
96 #if ELFTC_HAVE_STRMODE
97 /* Use the system's strmode(3). */
105 * The first character of the string denotes the type of the
114 #if defined(S_ISFIFO)
115 else if (S_ISFIFO(m))
124 #if defined(S_ISSOCK)
125 else if (S_ISSOCK(m))
132 /* The next 3 characters show permissions for the owner. */
133 buf[1] = (m & S_IRUSR) ? 'r' : '-';
134 buf[2] = m & S_IWUSR ? 'w' : '-';
136 c = (m & S_IXUSR) ? 's' : 'S';
138 c = (m & S_IXUSR) ? 'x' : '-';
141 /* The next 3 characters describe permissions for the group. */
142 buf[4] = (m & S_IRGRP) ? 'r' : '-';
143 buf[5] = m & S_IWGRP ? 'w' : '-';
145 c = (m & S_IXGRP) ? 's' : 'S';
147 c = (m & S_IXGRP) ? 'x' : '-';
151 /* The next 3 characters describe permissions for others. */
152 buf[7] = (m & S_IROTH) ? 'r' : '-';
153 buf[8] = m & S_IWOTH ? 'w' : '-';
154 if (m & S_ISVTX) /* sticky bit */
155 c = (m & S_IXOTH) ? 't' : 'T';
157 c = (m & S_IXOTH) ? 'x' : '-';
160 /* End the string with a blank and NUL-termination. */
165 #endif /* !ELTC_HAVE_STRMODE */
169 bsdar_is_pseudomember(struct bsdar *bsdar, const char *name)
172 * The "__.SYMDEF" member is special in the BSD format
175 if (bsdar->options & AR_BSD)
176 return (strcmp(name, AR_SYMTAB_NAME_BSD) == 0);
179 * The names "/ " and "// " are special in the SVR4
182 return (strcmp(name, AR_STRINGTAB_NAME_SVR4) == 0 ||
183 strcmp(name, AR_SYMTAB_NAME_SVR4) == 0);