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 |
|
---|
27 | void
|
---|
28 | pax_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. */
|
---|
50 | void
|
---|
51 | call_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. */
|
---|
63 | void
|
---|
64 | call_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. */
|
---|
76 | void
|
---|
77 | call_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 |
|
---|
87 | void
|
---|
88 | chmod_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 |
|
---|
97 | void
|
---|
98 | chown_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 |
|
---|
105 | void
|
---|
106 | close_error (char const *name)
|
---|
107 | {
|
---|
108 | call_arg_error ("close", name);
|
---|
109 | }
|
---|
110 |
|
---|
111 | void
|
---|
112 | close_warn (char const *name)
|
---|
113 | {
|
---|
114 | call_arg_warn ("close", name);
|
---|
115 | }
|
---|
116 |
|
---|
117 | void
|
---|
118 | exec_fatal (char const *name)
|
---|
119 | {
|
---|
120 | call_arg_fatal ("exec", name);
|
---|
121 | }
|
---|
122 |
|
---|
123 | void
|
---|
124 | link_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 |
|
---|
131 | void
|
---|
132 | mkdir_error (char const *name)
|
---|
133 | {
|
---|
134 | call_arg_error ("mkdir", name);
|
---|
135 | }
|
---|
136 |
|
---|
137 | void
|
---|
138 | mkfifo_error (char const *name)
|
---|
139 | {
|
---|
140 | call_arg_error ("mkfifo", name);
|
---|
141 | }
|
---|
142 |
|
---|
143 | void
|
---|
144 | mknod_error (char const *name)
|
---|
145 | {
|
---|
146 | call_arg_error ("mknod", name);
|
---|
147 | }
|
---|
148 |
|
---|
149 | void
|
---|
150 | open_error (char const *name)
|
---|
151 | {
|
---|
152 | call_arg_error ("open", name);
|
---|
153 | }
|
---|
154 |
|
---|
155 | void
|
---|
156 | open_fatal (char const *name)
|
---|
157 | {
|
---|
158 | call_arg_fatal ("open", name);
|
---|
159 | }
|
---|
160 |
|
---|
161 | void
|
---|
162 | open_warn (char const *name)
|
---|
163 | {
|
---|
164 | call_arg_warn ("open", name);
|
---|
165 | }
|
---|
166 |
|
---|
167 | void
|
---|
168 | read_error (char const *name)
|
---|
169 | {
|
---|
170 | call_arg_error ("read", name);
|
---|
171 | }
|
---|
172 |
|
---|
173 | void
|
---|
174 | read_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 |
|
---|
186 | void
|
---|
187 | read_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 |
|
---|
199 | void
|
---|
200 | read_fatal (char const *name)
|
---|
201 | {
|
---|
202 | call_arg_fatal ("read", name);
|
---|
203 | }
|
---|
204 |
|
---|
205 | void
|
---|
206 | read_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 |
|
---|
218 | void
|
---|
219 | readlink_error (char const *name)
|
---|
220 | {
|
---|
221 | call_arg_error ("readlink", name);
|
---|
222 | }
|
---|
223 |
|
---|
224 | void
|
---|
225 | readlink_warn (char const *name)
|
---|
226 | {
|
---|
227 | call_arg_warn ("readlink", name);
|
---|
228 | }
|
---|
229 |
|
---|
230 | void
|
---|
231 | rmdir_error (char const *name)
|
---|
232 | {
|
---|
233 | call_arg_error ("rmdir", name);
|
---|
234 | }
|
---|
235 |
|
---|
236 | void
|
---|
237 | savedir_error (char const *name)
|
---|
238 | {
|
---|
239 | call_arg_error ("savedir", name);
|
---|
240 | }
|
---|
241 |
|
---|
242 | void
|
---|
243 | savedir_warn (char const *name)
|
---|
244 | {
|
---|
245 | call_arg_warn ("savedir", name);
|
---|
246 | }
|
---|
247 |
|
---|
248 | void
|
---|
249 | seek_error (char const *name)
|
---|
250 | {
|
---|
251 | call_arg_error ("seek", name);
|
---|
252 | }
|
---|
253 |
|
---|
254 | void
|
---|
255 | seek_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 |
|
---|
264 | void
|
---|
265 | seek_warn (char const *name)
|
---|
266 | {
|
---|
267 | call_arg_warn ("seek", name);
|
---|
268 | }
|
---|
269 |
|
---|
270 | void
|
---|
271 | seek_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 |
|
---|
280 | void
|
---|
281 | symlink_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 |
|
---|
288 | void
|
---|
289 | stat_fatal (char const *name)
|
---|
290 | {
|
---|
291 | call_arg_fatal ("stat", name);
|
---|
292 | }
|
---|
293 |
|
---|
294 | void
|
---|
295 | stat_error (char const *name)
|
---|
296 | {
|
---|
297 | call_arg_error ("stat", name);
|
---|
298 | }
|
---|
299 |
|
---|
300 | void
|
---|
301 | stat_warn (char const *name)
|
---|
302 | {
|
---|
303 | call_arg_warn ("stat", name);
|
---|
304 | }
|
---|
305 |
|
---|
306 | void
|
---|
307 | truncate_error (char const *name)
|
---|
308 | {
|
---|
309 | call_arg_error ("truncate", name);
|
---|
310 | }
|
---|
311 |
|
---|
312 | void
|
---|
313 | truncate_warn (char const *name)
|
---|
314 | {
|
---|
315 | call_arg_warn ("truncate", name);
|
---|
316 | }
|
---|
317 |
|
---|
318 | void
|
---|
319 | unlink_error (char const *name)
|
---|
320 | {
|
---|
321 | call_arg_error ("unlink", name);
|
---|
322 | }
|
---|
323 |
|
---|
324 | void
|
---|
325 | utime_error (char const *name)
|
---|
326 | {
|
---|
327 | call_arg_error ("utime", name);
|
---|
328 | }
|
---|
329 |
|
---|
330 | void
|
---|
331 | waitpid_error (char const *name)
|
---|
332 | {
|
---|
333 | call_arg_error ("waitpid", name);
|
---|
334 | }
|
---|
335 |
|
---|
336 | void
|
---|
337 | write_error (char const *name)
|
---|
338 | {
|
---|
339 | call_arg_error ("write", name);
|
---|
340 | }
|
---|
341 |
|
---|
342 | void
|
---|
343 | write_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 |
|
---|
355 | void
|
---|
356 | write_fatal (char const *name)
|
---|
357 | {
|
---|
358 | call_arg_fatal ("write", name);
|
---|
359 | }
|
---|
360 |
|
---|
361 | void
|
---|
362 | chdir_fatal (char const *name)
|
---|
363 | {
|
---|
364 | call_arg_fatal ("chdir", name);
|
---|
365 | }
|
---|