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 /* Decode MODE from its binary form in a stat structure, and encode it
25 into a 9-byte string STRING, terminated with a NUL. */
28 pax_decode_mode (mode_t mode, char *string)
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' : '-'));
48 /* Report an error associated with the system call CALL and the
49 optional name NAME. */
51 call_arg_error (char const *call, char const *name)
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));
61 /* Report a fatal error associated with the system call CALL and
62 the optional file name NAME. */
64 call_arg_fatal (char const *call, char const *name)
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));
74 /* Report a warning associated with the system call CALL and
75 the optional file name NAME. */
77 call_arg_warn (char const *call, char const *name)
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));
88 chmod_error_details (char const *name, mode_t mode)
92 pax_decode_mode (mode, buf);
93 ERROR ((0, e, _("%s: Cannot change mode to %s"),
94 quotearg_colon (name), buf));
98 chown_error_details (char const *name, uid_t uid, gid_t gid)
101 ERROR ((0, e, _("%s: Cannot change ownership to uid %lu, gid %lu"),
102 quotearg_colon (name), (unsigned long) uid, (unsigned long) gid));
106 close_error (char const *name)
108 call_arg_error ("close", name);
112 close_warn (char const *name)
114 call_arg_warn ("close", name);
118 exec_fatal (char const *name)
120 call_arg_fatal ("exec", name);
124 link_error (char const *target, char const *source)
127 ERROR ((0, e, _("%s: Cannot hard link to %s"),
128 quotearg_colon (source), quote_n (1, target)));
132 mkdir_error (char const *name)
134 call_arg_error ("mkdir", name);
138 mkfifo_error (char const *name)
140 call_arg_error ("mkfifo", name);
144 mknod_error (char const *name)
146 call_arg_error ("mknod", name);
150 open_error (char const *name)
152 call_arg_error ("open", name);
156 open_fatal (char const *name)
158 call_arg_fatal ("open", name);
162 open_warn (char const *name)
164 call_arg_warn ("open", name);
168 read_error (char const *name)
170 call_arg_error ("read", name);
174 read_error_details (char const *name, off_t offset, size_t size)
176 char buf[UINTMAX_STRSIZE_BOUND];
179 ngettext ("%s: Read error at byte %s, while reading %lu byte",
180 "%s: Read error at byte %s, while reading %lu bytes",
182 quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
183 (unsigned long) size));
187 read_warn_details (char const *name, off_t offset, size_t size)
189 char buf[UINTMAX_STRSIZE_BOUND];
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",
195 quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
196 (unsigned long) size));
200 read_fatal (char const *name)
202 call_arg_fatal ("read", name);
206 read_fatal_details (char const *name, off_t offset, size_t size)
208 char buf[UINTMAX_STRSIZE_BOUND];
211 ngettext ("%s: Read error at byte %s, while reading %lu byte",
212 "%s: Read error at byte %s, while reading %lu bytes",
214 quotearg_colon (name), STRINGIFY_BIGINT (offset, buf),
215 (unsigned long) size));
219 readlink_error (char const *name)
221 call_arg_error ("readlink", name);
225 readlink_warn (char const *name)
227 call_arg_warn ("readlink", name);
231 rmdir_error (char const *name)
233 call_arg_error ("rmdir", name);
237 savedir_error (char const *name)
239 call_arg_error ("savedir", name);
243 savedir_warn (char const *name)
245 call_arg_warn ("savedir", name);
249 seek_error (char const *name)
251 call_arg_error ("seek", name);
255 seek_error_details (char const *name, off_t offset)
257 char buf[UINTMAX_STRSIZE_BOUND];
259 ERROR ((0, e, _("%s: Cannot seek to %s"),
260 quotearg_colon (name),
261 STRINGIFY_BIGINT (offset, buf)));
265 seek_warn (char const *name)
267 call_arg_warn ("seek", name);
271 seek_warn_details (char const *name, off_t offset)
273 char buf[UINTMAX_STRSIZE_BOUND];
275 WARN ((0, e, _("%s: Warning: Cannot seek to %s"),
276 quotearg_colon (name),
277 STRINGIFY_BIGINT (offset, buf)));
281 symlink_error (char const *contents, char const *name)
284 ERROR ((0, e, _("%s: Cannot create symlink to %s"),
285 quotearg_colon (name), quote_n (1, contents)));
289 stat_fatal (char const *name)
291 call_arg_fatal ("stat", name);
295 stat_error (char const *name)
297 call_arg_error ("stat", name);
301 stat_warn (char const *name)
303 call_arg_warn ("stat", name);
307 truncate_error (char const *name)
309 call_arg_error ("truncate", name);
313 truncate_warn (char const *name)
315 call_arg_warn ("truncate", name);
319 unlink_error (char const *name)
321 call_arg_error ("unlink", name);
325 utime_error (char const *name)
327 call_arg_error ("utime", name);
331 waitpid_error (char const *name)
333 call_arg_error ("waitpid", name);
337 write_error (char const *name)
339 call_arg_error ("write", name);
343 write_error_details (char const *name, size_t status, size_t size)
349 ngettext ("%s: Wrote only %lu of %lu byte",
350 "%s: Wrote only %lu of %lu bytes",
352 name, (unsigned long int) status, (unsigned long int) size));
356 write_fatal (char const *name)
358 call_arg_fatal ("write", name);
362 chdir_fatal (char const *name)
364 call_arg_fatal ("chdir", name);