This source file includes following definitions.
- mc_propagate_error
- is_exe
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 typedef enum
45 {
46 CANON_PATH_JOINSLASHES = 1L << 0,
47 CANON_PATH_REMSLASHDOTS = 1L << 1,
48 CANON_PATH_REMDOUBLEDOTS = 1L << 3,
49 CANON_PATH_GUARDUNC = 1L << 4,
50 CANON_PATH_ALL = CANON_PATH_JOINSLASHES
51 | CANON_PATH_REMSLASHDOTS | CANON_PATH_REMDOUBLEDOTS | CANON_PATH_GUARDUNC
52 } CANON_PATH_FLAGS;
53
54 enum compression_type
55 {
56 COMPRESSION_NONE,
57 COMPRESSION_GZIP,
58 COMPRESSION_BZIP,
59 COMPRESSION_BZIP2,
60 COMPRESSION_LZIP,
61 COMPRESSION_LZ4,
62 COMPRESSION_LZMA,
63 COMPRESSION_XZ,
64 COMPRESSION_ZSTD,
65 };
66
67
68 typedef struct
69 {
70
71 int fd;
72
73 char buf[MC_PIPE_BUFSIZE];
74
75
76
77
78
79
80 ssize_t len;
81
82 gboolean null_term;
83
84 int error;
85 } mc_pipe_stream_t;
86
87
88 typedef struct
89 {
90
91 GPid child_pid;
92
93 mc_pipe_stream_t out;
94
95 mc_pipe_stream_t err;
96 } mc_pipe_t;
97
98
99
100
101 typedef struct
102 {
103
104 size_t fnamelen;
105 char *fname;
106 struct stat st;
107
108 char *sort_key;
109
110 char *second_sort_key;
111
112
113 struct
114 {
115 unsigned int marked:1;
116 unsigned int link_to_dir:1;
117 unsigned int stale_link:1;
118 unsigned int dir_size_computed:1;
119 } f;
120 } file_entry_t;
121
122
123
124 extern struct sigaction startup_handler;
125
126
127
128 int is_printable (int c);
129
130
131
132
133 char *name_quote (const char *c, gboolean quote_percent);
134
135
136 char *fake_name_quote (const char *c, gboolean quote_percent);
137
138
139
140
141 const char *path_trunc (const char *path, size_t trunc_len);
142
143
144
145
146 const char *size_trunc (uintmax_t size, gboolean use_si);
147
148
149
150
151 const char *size_trunc_sep (uintmax_t size, gboolean use_si);
152
153
154
155
156
157 void size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gboolean use_si);
158 const char *string_perm (mode_t mode_bits);
159
160 const char *extension (const char *);
161 const char *unix_error_string (int error_num);
162 const char *skip_separators (const char *s);
163 const char *skip_numbers (const char *s);
164 char *strip_ctrl_codes (char *s);
165
166
167
168
169 char *convert_controls (const char *s);
170
171
172 void wipe_password (char *passwd);
173
174 char *diff_two_paths (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
175
176
177 const char *x_basename (const char *fname);
178
179 char *load_mc_home_file (const char *from, const char *filename, char **allocated_filename,
180 size_t * length);
181
182
183 void init_groups (void);
184 void destroy_groups (void);
185 int get_user_permissions (struct stat *buf);
186
187 void init_uid_gid_cache (void);
188 const char *get_group (gid_t gid);
189 const char *get_owner (uid_t uid);
190
191
192 const char *extract_line (const char *s, const char *top);
193
194
195 void open_error_pipe (void);
196 void check_error_pipe (void);
197 int close_error_pipe (int error, const char *text);
198
199
200 int my_system (int flags, const char *shell, const char *command);
201 int my_systeml (int flags, const char *shell, ...);
202 int my_systemv (const char *command, char *const argv[]);
203 int my_systemv_flags (int flags, const char *command, char *const argv[]);
204
205 mc_pipe_t *mc_popen (const char *command, GError ** error);
206 void mc_pread (mc_pipe_t * p, GError ** error);
207 void mc_pclose (mc_pipe_t * p, GError ** error);
208
209 void my_exit (int status);
210 void save_stop_handler (void);
211
212
213 char *tilde_expand (const char *);
214
215 void custom_canonicalize_pathname (char *, CANON_PATH_FLAGS);
216 void canonicalize_pathname (char *);
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 *);
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 *, const char *);
244 gboolean mc_util_restore_from_backup_if_possible (const char *, const char *);
245 gboolean mc_util_unlink_backup_if_possible (const char *, const char *);
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 (guint64 * timestamp, guint64 delay);
260
261
262
263 static inline gboolean
264 exist_file (const char *name)
265 {
266 return (access (name, R_OK) == 0);
267 }
268
269 static inline gboolean
270 is_exe (mode_t mode)
271 {
272 return (gboolean) ((S_IXUSR & mode) || (S_IXGRP & mode) || (S_IXOTH & mode));
273 }
274
275 #endif