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