source: trunk/essentials/app-arch/tar/lib/paxerror.c

Last change on this file was 3342, checked in by bird, 18 years ago

tar 1.16.1

File size: 7.8 KB
Line 
1/* Miscellaneous error functions
2
3 Copyright (C) 2005 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any later
8 version.
9
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18
19#include <system.h>
20#include <paxlib.h>
21#include <quote.h>
22#include <quotearg.h>
23
24/* Decode MODE from its binary form in a stat structure, and encode it
25 into a 9-byte string STRING, terminated with a NUL. */
26
27void
28pax_decode_mode (mode_t mode, char *string)
29{
30 *string++ = mode & S_IRUSR ? 'r' : '-';
31 *string++ = mode & S_IWUSR ? 'w' : '-';
32 *string++ = (mode & S_ISUID
33 ? (mode & S_IXUSR ? 's' : 'S')
34 : (mode & S_IXUSR ? 'x' : '-'));
35 *string++ = mode & S_IRGRP ? 'r' : '-';
36 *string++ = mode & S_IWGRP ? 'w' : '-';
37 *string++ = (mode & S_ISGID
38 ? (mode & S_IXGRP ? 's' : 'S')
39 : (mode & S_IXGRP ? 'x' : '-'));
40 *string++ = mode & S_IROTH ? 'r' : '-';
41 *string++ = mode & S_IWOTH ? 'w' : '-';
42 *string++ = (mode & S_ISVTX
43 ? (mode & S_IXOTH ? 't' : 'T')
44 : (mode & S_IXOTH ? 'x' : '-'));
45 *string = '\0';
46}
47
48/* Report an error associated with the system call CALL and the
49 optional name NAME. */
50void
51call_arg_error (char const *call, char const *name)
52{
53 int e = errno;
54 /* TRANSLATORS: %s after `Cannot' is a function name, e.g. `Cannot open'.
55 Directly translating this to another language will not work, first because
56 %s itself is not translated.
57 Translate it as `%s: Function %s failed'. */
58 ERROR ((0, e, _("%s: Cannot %s"), quotearg_colon (name), call));
59}
60
61/* Report a fatal error associated with the system call CALL and
62 the optional file name NAME. */
63void
64call_arg_fatal (char const *call, char const *name)
65{
66 int e = errno;
67 /* TRANSLATORS: %s after `Cannot' is a function name, e.g. `Cannot open'.
68 Directly translating this to another language will not work, first because
69 %s itself is not translated.
70 Translate it as `%s: Function %s failed'. */
71 FATAL_ERROR ((0, e, _("%s: Cannot %s"), quotearg_colon (name), call));
72}
73
74/* Report a warning associated with the system call CALL and
75 the optional file name NAME. */
76void
77call_arg_warn (char const *call, char const *name)
78{
79 int e = errno;
80 /* TRANSLATORS: %s after `Cannot' is a function name, e.g. `Cannot open'.
81 Directly translating this to another language will not work, first because
82 %s itself is not translated.
83 Translate it as `%s: Function %s failed'. */
84 WARN ((0, e, _("%s: Warning: Cannot %s"), quotearg_colon (name), call));
85}
86
87void
88chmod_error_details (char const *name, mode_t mode)
89{
90 int e = errno;
91 char buf[10];
92 pax_decode_mode (mode, buf);
93 ERROR ((0, e, _("%s: Cannot change mode to %s"),
94 quotearg_colon (name), buf));
95}
96
97void
98chown_error_details (char const *name, uid_t uid, gid_t gid)
99{
100 int e = errno;
101 ERROR ((0, e, _("%s: Cannot change ownership to uid %lu, gid %lu"),
102 quotearg_colon (name), (unsigned long) uid, (unsigned long) gid));
103}
104
105void
106close_error (char const *name)
107{
108 call_arg_error ("close", name);
109}
110
111void
112close_warn (char const *name)
113{
114 call_arg_warn ("close", name);
115}
116
117void
118exec_fatal (char const *name)
119{
120 call_arg_fatal ("exec", name);
121}
122
123void
124link_error (char const *target, char const *source)
125{
126 int e = errno;
127 ERROR ((0, e, _("%s: Cannot hard link to %s"),
128 quotearg_colon (source), quote_n (1, target)));
129}
130
131void
132mkdir_error (char const *name)
133{
134 call_arg_error ("mkdir", name);
135}
136
137void
138mkfifo_error (char const *name)
139{
140 call_arg_error ("mkfifo", name);
141}
142
143void
144mknod_error (char const *name)
145{
146 call_arg_error ("mknod", name);
147}
148
149void
150open_error (char const *name)
151{
152 call_arg_error ("open", name);
153}
154
155void
156open_fatal (char const *name)
157{
158 call_arg_fatal ("open", name);
159}
160
161void
162open_warn (char const *name)
163{
164 call_arg_warn ("open", name);
165}
166
167void
168read_error (char const *name)
169{
170 call_arg_error ("read", name);
171}
172
173void
174read_error_details (char const *name, off_t offset, size_t size)
175{
176 char buf[UINTMAX_STRSIZE_BOUND];
177 int e = errno;
178 ERROR ((0, e,
179 ngettext ("%s: Read error at byte %s, while reading %lu byte",
180 "%s: Read error at byte %s, while reading %lu bytes",
181 size),
182 quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
183 (unsigned long) size));
184}
185
186void
187read_warn_details (char const *name, off_t offset, size_t size)
188{
189 char buf[UINTMAX_STRSIZE_BOUND];
190 int e = errno;
191 WARN ((0, e,
192 ngettext ("%s: Warning: Read error at byte %s, while reading %lu byte",
193 "%s: Warning: Read error at byte %s, while reading %lu bytes",
194 size),
195 quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
196 (unsigned long) size));
197}
198
199void
200read_fatal (char const *name)
201{
202 call_arg_fatal ("read", name);
203}
204
205void
206read_fatal_details (char const *name, off_t offset, size_t size)
207{
208 char buf[UINTMAX_STRSIZE_BOUND];
209 int e = errno;
210 FATAL_ERROR ((0, e,
211 ngettext ("%s: Read error at byte %s, while reading %lu byte",
212 "%s: Read error at byte %s, while reading %lu bytes",
213 size),
214 quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
215 (unsigned long) size));
216}
217
218void
219readlink_error (char const *name)
220{
221 call_arg_error ("readlink", name);
222}
223
224void
225readlink_warn (char const *name)
226{
227 call_arg_warn ("readlink", name);
228}
229
230void
231rmdir_error (char const *name)
232{
233 call_arg_error ("rmdir", name);
234}
235
236void
237savedir_error (char const *name)
238{
239 call_arg_error ("savedir", name);
240}
241
242void
243savedir_warn (char const *name)
244{
245 call_arg_warn ("savedir", name);
246}
247
248void
249seek_error (char const *name)
250{
251 call_arg_error ("seek", name);
252}
253
254void
255seek_error_details (char const *name, off_t offset)
256{
257 char buf[UINTMAX_STRSIZE_BOUND];
258 int e = errno;
259 ERROR ((0, e, _("%s: Cannot seek to %s"),
260 quotearg_colon (name),
261 STRINGIFY_BIGINT (offset, buf)));
262}
263
264void
265seek_warn (char const *name)
266{
267 call_arg_warn ("seek", name);
268}
269
270void
271seek_warn_details (char const *name, off_t offset)
272{
273 char buf[UINTMAX_STRSIZE_BOUND];
274 int e = errno;
275 WARN ((0, e, _("%s: Warning: Cannot seek to %s"),
276 quotearg_colon (name),
277 STRINGIFY_BIGINT (offset, buf)));
278}
279
280void
281symlink_error (char const *contents, char const *name)
282{
283 int e = errno;
284 ERROR ((0, e, _("%s: Cannot create symlink to %s"),
285 quotearg_colon (name), quote_n (1, contents)));
286}
287
288void
289stat_fatal (char const *name)
290{
291 call_arg_fatal ("stat", name);
292}
293
294void
295stat_error (char const *name)
296{
297 call_arg_error ("stat", name);
298}
299
300void
301stat_warn (char const *name)
302{
303 call_arg_warn ("stat", name);
304}
305
306void
307truncate_error (char const *name)
308{
309 call_arg_error ("truncate", name);
310}
311
312void
313truncate_warn (char const *name)
314{
315 call_arg_warn ("truncate", name);
316}
317
318void
319unlink_error (char const *name)
320{
321 call_arg_error ("unlink", name);
322}
323
324void
325utime_error (char const *name)
326{
327 call_arg_error ("utime", name);
328}
329
330void
331waitpid_error (char const *name)
332{
333 call_arg_error ("waitpid", name);
334}
335
336void
337write_error (char const *name)
338{
339 call_arg_error ("write", name);
340}
341
342void
343write_error_details (char const *name, size_t status, size_t size)
344{
345 if (status == 0)
346 write_error (name);
347 else
348 ERROR ((0, 0,
349 ngettext ("%s: Wrote only %lu of %lu byte",
350 "%s: Wrote only %lu of %lu bytes",
351 size),
352 name, (unsigned long int) status, (unsigned long int) size));
353}
354
355void
356write_fatal (char const *name)
357{
358 call_arg_fatal ("write", name);
359}
360
361void
362chdir_fatal (char const *name)
363{
364 call_arg_fatal ("chdir", name);
365}
Note: See TracBrowser for help on using the repository browser.