This source file includes following definitions.
- mc_propagate_error
- is_exe
- canonicalize_pathname
1
2
3
4
5 #ifndef MC_UTIL_H
6 #define MC_UTIL_H
7
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <inttypes.h>
11 #include <unistd.h>
12
13 #include "lib/global.h"
14
15 #include "lib/vfs/vfs.h"
16
17
18
19 #ifndef MAXSYMLINKS
20 #define MAXSYMLINKS 32
21 #endif
22
23 #define MAX_SAVED_BOOKMARKS 10
24
25 #define MC_PTR_FREE(ptr) \
26 do \
27 { \
28 g_free (ptr); \
29 (ptr) = NULL; \
30 } \
31 while (0)
32
33 #define mc_return_if_error(mcerror) \
34 do \
35 { \
36 if (mcerror != NULL && *mcerror != NULL) \
37 return; \
38 } \
39 while (0)
40 #define mc_return_val_if_error(mcerror, mcvalue) \
41 do \
42 { \
43 if (mcerror != NULL && *mcerror != NULL) \
44 return mcvalue; \
45 } \
46 while (0)
47
48 #define whitespace(c) ((c) == ' ' || (c) == '\t')
49 #define whiteness(c) (whitespace (c) || (c) == '\n')
50
51 #define MC_PIPE_BUFSIZE BUF_8K
52 #define MC_PIPE_STREAM_EOF 0
53 #define MC_PIPE_STREAM_UNREAD -1
54 #define MC_PIPE_ERROR_CREATE_PIPE -2
55 #define MC_PIPE_ERROR_PARSE_COMMAND -3
56 #define MC_PIPE_ERROR_CREATE_PIPE_STREAM -4
57 #define MC_PIPE_ERROR_READ -5
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 #define _GL_CMP(n1, n2) (((n1) > (n2)) - ((n1) < (n2)))
74
75
76 #define DOZ(a, b) ((a) > (b) ? (a) - (b) : 0)
77
78
79 #define EXECUTE_INTERNAL (1 << 0)
80 #define EXECUTE_AS_SHELL (1 << 2)
81 #define EXECUTE_HIDE (1 << 3)
82
83
84
85
86 typedef enum
87 {
88 CANON_PATH_NOCHANGE = 0,
89 CANON_PATH_JOINSLASHES = 1L << 0,
90 CANON_PATH_REMSLASHDOTS = 1L << 1,
91 CANON_PATH_REMDOUBLEDOTS = 1L
92 << 3,
93 CANON_PATH_GUARDUNC = 1L << 4,
94 CANON_PATH_ALL = CANON_PATH_JOINSLASHES | CANON_PATH_REMSLASHDOTS | CANON_PATH_REMDOUBLEDOTS
95 | CANON_PATH_GUARDUNC
96 } canon_path_flags_t;
97
98 enum compression_type
99 {
100 COMPRESSION_NONE,
101 COMPRESSION_ZIP,
102 COMPRESSION_GZIP,
103 COMPRESSION_BZIP,
104 COMPRESSION_BZIP2,
105 COMPRESSION_LZIP,
106 COMPRESSION_LZ4,
107 COMPRESSION_LZMA,
108 COMPRESSION_LZO,
109 COMPRESSION_XZ,
110 COMPRESSION_ZSTD,
111 };
112
113
114 typedef struct
115 {
116
117 int fd;
118
119 char buf[MC_PIPE_BUFSIZE];
120
121 size_t pos;
122
123
124
125
126
127 ssize_t len;
128
129 gboolean null_term;
130
131 int error;
132 } mc_pipe_stream_t;
133
134
135 typedef struct
136 {
137
138 GPid child_pid;
139
140 mc_pipe_stream_t out;
141
142 mc_pipe_stream_t err;
143 } mc_pipe_t;
144
145
146 #ifndef HAVE_SIGHANDLER_T
147 typedef void (*sighandler_t) (int);
148 #endif
149
150
151
152
153
154 extern struct sigaction startup_handler;
155
156
157
158 int is_printable (int c);
159
160
161
162
163 char *name_quote (const char *c, gboolean quote_percent);
164
165
166 char *fake_name_quote (const char *c, gboolean quote_percent);
167
168
169
170
171 const char *path_trunc (const char *path, size_t trunc_len);
172
173
174
175
176 const char *size_trunc (uintmax_t size, gboolean use_si);
177
178
179
180
181 const char *size_trunc_sep (uintmax_t size, gboolean use_si);
182
183
184
185
186
187 void size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gboolean use_si);
188 const char *string_perm (mode_t mode_bits);
189
190 const char *extension (const char *);
191 const char *unix_error_string (int error_num);
192 const char *skip_separators (const char *s);
193 const char *skip_numbers (const char *s);
194
195
196 void wipe_password (char *passwd);
197
198 char *diff_two_paths (const vfs_path_t *vpath1, const vfs_path_t *vpath2);
199
200
201 const char *x_basename (const char *fname);
202
203 char *load_mc_home_file (const char *from, const char *filename, char **allocated_filename,
204 size_t *length);
205
206
207 void init_groups (void);
208 void destroy_groups (void);
209 int get_user_permissions (struct stat *buf);
210
211 void init_uid_gid_cache (void);
212 const char *get_group (gid_t gid);
213 const char *get_owner (uid_t uid);
214
215
216 const char *extract_line (const char *s, const char *top, size_t *len);
217
218
219 MC_MOCKABLE sighandler_t my_signal (int signum, sighandler_t handler);
220 MC_MOCKABLE int my_sigaction (int signum, const struct sigaction *act, struct sigaction *oldact);
221 MC_MOCKABLE pid_t my_fork (void);
222 MC_MOCKABLE int my_execvp (const char *file, char *const argv[]);
223 MC_MOCKABLE char *my_get_current_dir (void);
224
225
226 int my_system (int flags, const char *shell, const char *command);
227 int my_systeml (int flags, const char *shell, ...);
228 int my_systemv (const char *command, char *const argv[]);
229 int my_systemv_flags (int flags, const char *command, char *const argv[]);
230
231 mc_pipe_t *mc_popen (const char *command, gboolean read_out, gboolean read_err, GError **error);
232 void mc_pread (mc_pipe_t *p, GError **error);
233 void mc_pclose (mc_pipe_t *p, GError **error);
234
235 GString *mc_pstream_get_string (mc_pipe_stream_t *ps);
236
237 MC_MOCKABLE void my_exit (int status);
238 void save_stop_handler (void);
239
240
241 char *tilde_expand (const char *directory);
242
243 void canonicalize_pathname_custom (char *path, canon_path_flags_t flags);
244
245 char *mc_realpath (const char *path, char *resolved_path);
246
247
248
249 enum compression_type get_compression_type (int fd, const char *name);
250 const char *decompress_extension (int type);
251
252 GList *list_append_unique (GList *list, char *text);
253
254
255
256 void load_file_position (const vfs_path_t *filename_vpath, long *line, long *column, off_t *offset,
257 GArray **bookmarks);
258
259 void save_file_position (const vfs_path_t *filename_vpath, long line, long column, off_t offset,
260 GArray *bookmarks);
261
262
263
264 extern int ascii_alpha_to_cntrl (int ch);
265
266 #undef Q_
267 const char *Q_ (const char *s);
268
269 gboolean mc_util_make_backup_if_possible (const char *file_name, const char *backup_suffix);
270 gboolean mc_util_restore_from_backup_if_possible (const char *file_name, const char *backup_suffix);
271 gboolean mc_util_unlink_backup_if_possible (const char *file_name, const char *backup_suffix);
272
273 MC_MOCKABLE char *guess_message_value (void);
274
275 char *mc_build_filename (const char *first_element, ...);
276 char *mc_build_filenamev (const char *first_element, va_list args);
277
278 const char *mc_get_profile_root (void);
279
280 void mc_propagate_error (GError **dest, int code, const char *format, ...) G_GNUC_PRINTF (3, 4);
281 void mc_replace_error (GError **dest, int code, const char *format, ...) G_GNUC_PRINTF (3, 4);
282
283 gboolean mc_time_elapsed (gint64 *timestamp, gint64 delay);
284
285
286
287
288
289 static inline gboolean
290 exist_file (const char *name)
291 {
292 return (access (name, R_OK) == 0);
293 }
294
295
296
297 static inline gboolean
298 is_exe (mode_t mode)
299 {
300 return ((mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0);
301 }
302
303
304
305
306
307
308
309
310
311
312
313
314 static inline void
315 canonicalize_pathname (char *path)
316 {
317 canonicalize_pathname_custom (path, CANON_PATH_ALL);
318 }
319
320
321
322 #endif