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