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