1 /* This file is part of GNU paxutils
2
3 Copyright (C) 1994-2001, 2003, 2005, 2007, 2023 Free Software Foundation,
4 Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21 #ifndef _paxlib_h_
22 #define _paxlib_h_
23
24 /* Error reporting functions and definitions */
25
26 /* Exit status for paxutils app. Let's try to keep this list as simple as
27 possible. tar -d option strongly invites a status different for unequal
28 comparison and other errors. */
29 #define PAXEXIT_SUCCESS 0
30 #define PAXEXIT_DIFFERS 1
31 #define PAXEXIT_FAILURE 2
32
33 extern void (*error_hook) (void);
34
35 /* Both WARN and ERROR write a message on stderr and continue processing,
36 however ERROR manages so tar will exit unsuccessfully. FATAL_ERROR
37 writes a message on stderr and aborts immediately, with another message
38 line telling so. USAGE_ERROR works like FATAL_ERROR except that the
39 other message line suggests trying --help. All four macros accept a
40 single argument of the form ((0, errno, _("FORMAT"), Args...)). errno
41 is zero when the error is not being detected by the system. */
42
43 #define WARN(Args) \
44 do { if (error_hook) error_hook (); error Args; } while (0)
45 #define ERROR(Args) \
46 do \
47 { \
48 if (error_hook) error_hook (); \
49 error Args; \
50 exit_status = PAXEXIT_FAILURE; \
51 } \
52 while (0)
53 #define FATAL_ERROR(Args) \
54 do \
55 { \
56 if (error_hook) error_hook (); \
57 error Args; \
58 fatal_exit (); \
59 } \
60 while (0)
61 #define USAGE_ERROR(Args) \
62 do \
63 { \
64 if (error_hook) error_hook (); \
65 error Args; \
66 usage (PAXEXIT_FAILURE); \
67 } \
68 while (0)
69
70 extern int exit_status;
71
72 void pax_decode_mode (mode_t mode, char *string);
73 void call_arg_error (char const *call, char const *name);
74 _Noreturn void call_arg_fatal (char const *call, char const *name);
75 void call_arg_warn (char const *call, char const *name);
76 void chmod_error_details (char const *name, mode_t mode);
77 void chown_error_details (char const *name, uid_t uid, gid_t gid);
78
79 void decode_mode (mode_t, char *);
80
81 _Noreturn void chdir_fatal (char const *);
82 void chmod_error_details (char const *, mode_t);
83 void chown_error_details (char const *, uid_t, gid_t);
84 void close_error (char const *);
85 void close_warn (char const *);
86 _Noreturn void exec_fatal (char const *);
87 void link_error (char const *, char const *);
88 void mkdir_error (char const *);
89 void mkfifo_error (char const *);
90 void mknod_error (char const *);
91 void open_error (char const *);
92 _Noreturn void open_fatal (char const *);
93 void open_warn (char const *);
94 void read_error (char const *);
95 void read_error_details (char const *, off_t, size_t);
96 _Noreturn void read_fatal (char const *);
97 _Noreturn void read_fatal_details (char const *, off_t, size_t);
98 void read_warn_details (char const *, off_t, size_t);
99 void readlink_error (char const *);
100 void readlink_warn (char const *);
101 void rmdir_error (char const *);
102 void savedir_error (char const *);
103 void savedir_warn (char const *);
104 void seek_error (char const *);
105 void seek_error_details (char const *, off_t);
106 void seek_warn (char const *);
107 void seek_warn_details (char const *, off_t);
108 _Noreturn void stat_fatal (char const *);
109 void stat_error (char const *);
110 void stat_warn (char const *);
111 void symlink_error (char const *, char const *);
112 void truncate_error (char const *);
113 void truncate_warn (char const *);
114 void unlink_error (char const *);
115 void utime_error (char const *);
116 void waitpid_error (char const *);
117 void write_error (char const *);
118 void write_error_details (char const *, size_t, size_t);
119
120 _Noreturn void pax_exit (void);
121 _Noreturn void fatal_exit (void);
122
123 /* Name-related functions */
124 bool removed_prefixes_p (void);
125 char *safer_name_suffix (char const *file_name, bool link_target, bool absolute_names);
126
127 #endif