1 /* Miscellaneous error functions
3 Copyright (C) 2005, 2007 Free Software Foundation, Inc.
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 3, or (at your option) any later
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.
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. */
24 void (*error_hook) (void);
26 /* Decode MODE from its binary form in a stat structure, and encode it
27 into a 9-byte string STRING, terminated with a NUL. */
30 pax_decode_mode (mode_t mode, char *string)
32 *string++ = mode & S_IRUSR ? 'r' : '-';
33 *string++ = mode & S_IWUSR ? 'w' : '-';
34 *string++ = (mode & S_ISUID
35 ? (mode & S_IXUSR ? 's' : 'S')
36 : (mode & S_IXUSR ? 'x' : '-'));
37 *string++ = mode & S_IRGRP ? 'r' : '-';
38 *string++ = mode & S_IWGRP ? 'w' : '-';
39 *string++ = (mode & S_ISGID
40 ? (mode & S_IXGRP ? 's' : 'S')
41 : (mode & S_IXGRP ? 'x' : '-'));
42 *string++ = mode & S_IROTH ? 'r' : '-';
43 *string++ = mode & S_IWOTH ? 'w' : '-';
44 *string++ = (mode & S_ISVTX
45 ? (mode & S_IXOTH ? 't' : 'T')
46 : (mode & S_IXOTH ? 'x' : '-'));
50 /* Report an error associated with the system call CALL and the
51 optional name NAME. */
53 call_arg_error (char const *call, char const *name)
56 /* TRANSLATORS: %s after `Cannot' is a function name, e.g. `Cannot open'.
57 Directly translating this to another language will not work, first because
58 %s itself is not translated.
59 Translate it as `%s: Function %s failed'. */
60 ERROR ((0, e, _("%s: Cannot %s"), quotearg_colon (name), call));
63 /* Report a fatal error associated with the system call CALL and
64 the optional file name NAME. */
66 call_arg_fatal (char const *call, char const *name)
69 /* TRANSLATORS: %s after `Cannot' is a function name, e.g. `Cannot open'.
70 Directly translating this to another language will not work, first because
71 %s itself is not translated.
72 Translate it as `%s: Function %s failed'. */
73 FATAL_ERROR ((0, e, _("%s: Cannot %s"), quotearg_colon (name), call));
76 /* Report a warning associated with the system call CALL and
77 the optional file name NAME. */
79 call_arg_warn (char const *call, char const *name)
82 /* TRANSLATORS: %s after `Cannot' is a function name, e.g. `Cannot open'.
83 Directly translating this to another language will not work, first because
84 %s itself is not translated.
85 Translate it as `%s: Function %s failed'. */
86 WARN ((0, e, _("%s: Warning: Cannot %s"), quotearg_colon (name), call));
90 chmod_error_details (char const *name, mode_t mode)
94 pax_decode_mode (mode, buf);
95 ERROR ((0, e, _("%s: Cannot change mode to %s"),
96 quotearg_colon (name), buf));
100 chown_error_details (char const *name, uid_t uid, gid_t gid)
103 ERROR ((0, e, _("%s: Cannot change ownership to uid %lu, gid %lu"),
104 quotearg_colon (name), (unsigned long) uid, (unsigned long) gid));
108 close_error (char const *name)
110 call_arg_error ("close", name);
114 close_warn (char const *name)
116 call_arg_warn ("close", name);
120 exec_fatal (char const *name)
122 call_arg_fatal ("exec", name);
126 link_error (char const *target, char const *source)
129 ERROR ((0, e, _("%s: Cannot hard link to %s"),
130 quotearg_colon (source), quote_n (1, target)));
134 mkdir_error (char const *name)
136 call_arg_error ("mkdir", name);
140 mkfifo_error (char const *name)
142 call_arg_error ("mkfifo", name);
146 mknod_error (char const *name)
148 call_arg_error ("mknod", name);
152 open_error (char const *name)
154 call_arg_error ("open", name);
158 open_fatal (char const *name)
160 call_arg_fatal ("open", name);
164 open_warn (char const *name)
166 call_arg_warn ("open", name);
170 read_error (char const *name)
172 call_arg_error ("read", name);
176 read_error_details (char const *name, off_t offset, size_t size)
178 char buf[UINTMAX_STRSIZE_BOUND];
181 ngettext ("%s: Read error at byte %s, while reading %lu byte",
182 "%s: Read error at byte %s, while reading %lu bytes",
184 quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
185 (unsigned long) size));
189 read_warn_details (char const *name, off_t offset, size_t size)
191 char buf[UINTMAX_STRSIZE_BOUND];
194 ngettext ("%s: Warning: Read error at byte %s, while reading %lu byte",
195 "%s: Warning: Read error at byte %s, while reading %lu bytes",
197 quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
198 (unsigned long) size));
202 read_fatal (char const *name)
204 call_arg_fatal ("read", name);
208 read_fatal_details (char const *name, off_t offset, size_t size)
210 char buf[UINTMAX_STRSIZE_BOUND];
213 ngettext ("%s: Read error at byte %s, while reading %lu byte",
214 "%s: Read error at byte %s, while reading %lu bytes",
216 quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
217 (unsigned long) size));
221 readlink_error (char const *name)
223 call_arg_error ("readlink", name);
227 readlink_warn (char const *name)
229 call_arg_warn ("readlink", name);
233 rmdir_error (char const *name)
235 call_arg_error ("rmdir", name);
239 savedir_error (char const *name)
241 call_arg_error ("savedir", name);
245 savedir_warn (char const *name)
247 call_arg_warn ("savedir", name);
251 seek_error (char const *name)
253 call_arg_error ("seek", name);
257 seek_error_details (char const *name, off_t offset)
259 char buf[UINTMAX_STRSIZE_BOUND];
261 ERROR ((0, e, _("%s: Cannot seek to %s"),
262 quotearg_colon (name),
263 STRINGIFY_BIGINT (offset, buf)));
267 seek_warn (char const *name)
269 call_arg_warn ("seek", name);
273 seek_warn_details (char const *name, off_t offset)
275 char buf[UINTMAX_STRSIZE_BOUND];
277 WARN ((0, e, _("%s: Warning: Cannot seek to %s"),
278 quotearg_colon (name),
279 STRINGIFY_BIGINT (offset, buf)));
283 symlink_error (char const *contents, char const *name)
286 ERROR ((0, e, _("%s: Cannot create symlink to %s"),
287 quotearg_colon (name), quote_n (1, contents)));
291 stat_fatal (char const *name)
293 call_arg_fatal ("stat", name);
297 stat_error (char const *name)
299 call_arg_error ("stat", name);
303 stat_warn (char const *name)
305 call_arg_warn ("stat", name);
309 truncate_error (char const *name)
311 call_arg_error ("truncate", name);
315 truncate_warn (char const *name)
317 call_arg_warn ("truncate", name);
321 unlink_error (char const *name)
323 call_arg_error ("unlink", name);
327 utime_error (char const *name)
329 call_arg_error ("utime", name);
333 waitpid_error (char const *name)
335 call_arg_error ("waitpid", name);
339 write_error (char const *name)
341 call_arg_error ("write", name);
345 write_error_details (char const *name, size_t status, size_t size)
351 ngettext ("%s: Wrote only %lu of %lu byte",
352 "%s: Wrote only %lu of %lu bytes",
354 name, (unsigned long int) status, (unsigned long int) size));
358 chdir_fatal (char const *name)
360 call_arg_fatal ("chdir", name);