1 | /* gfileutils.h - File utility functions |
2 | * |
3 | * Copyright 2000 Red Hat, Inc. |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Lesser General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2.1 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Lesser General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Lesser General Public License |
16 | * along with this library; if not, see <http://www.gnu.org/licenses/>. |
17 | */ |
18 | |
19 | #ifndef __G_FILEUTILS_H__ |
20 | #define __G_FILEUTILS_H__ |
21 | |
22 | #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION) |
23 | #error "Only <glib.h> can be included directly." |
24 | #endif |
25 | |
26 | #include <glibconfig.h> |
27 | #include <glib/gerror.h> |
28 | |
29 | G_BEGIN_DECLS |
30 | |
31 | #define G_FILE_ERROR g_file_error_quark () |
32 | |
33 | typedef enum |
34 | { |
35 | G_FILE_ERROR_EXIST, |
36 | G_FILE_ERROR_ISDIR, |
37 | G_FILE_ERROR_ACCES, |
38 | G_FILE_ERROR_NAMETOOLONG, |
39 | G_FILE_ERROR_NOENT, |
40 | G_FILE_ERROR_NOTDIR, |
41 | G_FILE_ERROR_NXIO, |
42 | G_FILE_ERROR_NODEV, |
43 | G_FILE_ERROR_ROFS, |
44 | G_FILE_ERROR_TXTBSY, |
45 | G_FILE_ERROR_FAULT, |
46 | G_FILE_ERROR_LOOP, |
47 | G_FILE_ERROR_NOSPC, |
48 | G_FILE_ERROR_NOMEM, |
49 | G_FILE_ERROR_MFILE, |
50 | G_FILE_ERROR_NFILE, |
51 | G_FILE_ERROR_BADF, |
52 | G_FILE_ERROR_INVAL, |
53 | G_FILE_ERROR_PIPE, |
54 | G_FILE_ERROR_AGAIN, |
55 | G_FILE_ERROR_INTR, |
56 | G_FILE_ERROR_IO, |
57 | G_FILE_ERROR_PERM, |
58 | G_FILE_ERROR_NOSYS, |
59 | G_FILE_ERROR_FAILED |
60 | } GFileError; |
61 | |
62 | /* For backward-compat reasons, these are synced to an old |
63 | * anonymous enum in libgnome. But don't use that enum |
64 | * in new code. |
65 | */ |
66 | typedef enum |
67 | { |
68 | G_FILE_TEST_IS_REGULAR = 1 << 0, |
69 | G_FILE_TEST_IS_SYMLINK = 1 << 1, |
70 | G_FILE_TEST_IS_DIR = 1 << 2, |
71 | G_FILE_TEST_IS_EXECUTABLE = 1 << 3, |
72 | G_FILE_TEST_EXISTS = 1 << 4 |
73 | } GFileTest; |
74 | |
75 | /** |
76 | * GFileSetContentsFlags: |
77 | * @G_FILE_SET_CONTENTS_NONE: No guarantees about file consistency or durability. |
78 | * The most dangerous setting, which is slightly faster than other settings. |
79 | * @G_FILE_SET_CONTENTS_CONSISTENT: Guarantee file consistency: after a crash, |
80 | * either the old version of the file or the new version of the file will be |
81 | * available, but not a mixture. On Unix systems this equates to an `fsync()` |
82 | * on the file and use of an atomic `rename()` of the new version of the file |
83 | * over the old. |
84 | * @G_FILE_SET_CONTENTS_DURABLE: Guarantee file durability: after a crash, the |
85 | * new version of the file will be available. On Unix systems this equates to |
86 | * an `fsync()` on the file (if %G_FILE_SET_CONTENTS_CONSISTENT is unset), or |
87 | * the effects of %G_FILE_SET_CONTENTS_CONSISTENT plus an `fsync()` on the |
88 | * directory containing the file after calling `rename()`. |
89 | * @G_FILE_SET_CONTENTS_ONLY_EXISTING: Only apply consistency and durability |
90 | * guarantees if the file already exists. This may speed up file operations |
91 | * if the file doesn’t currently exist, but may result in a corrupted version |
92 | * of the new file if the system crashes while writing it. |
93 | * |
94 | * Flags to pass to g_file_set_contents_full() to affect its safety and |
95 | * performance. |
96 | * |
97 | * Since: 2.66 |
98 | */ |
99 | typedef enum |
100 | { |
101 | G_FILE_SET_CONTENTS_NONE = 0, |
102 | G_FILE_SET_CONTENTS_CONSISTENT = 1 << 0, |
103 | G_FILE_SET_CONTENTS_DURABLE = 1 << 1, |
104 | G_FILE_SET_CONTENTS_ONLY_EXISTING = 1 << 2 |
105 | } GFileSetContentsFlags |
106 | GLIB_AVAILABLE_ENUMERATOR_IN_2_66; |
107 | |
108 | GLIB_AVAILABLE_IN_ALL |
109 | GQuark g_file_error_quark (void); |
110 | /* So other code can generate a GFileError */ |
111 | GLIB_AVAILABLE_IN_ALL |
112 | GFileError g_file_error_from_errno (gint err_no); |
113 | |
114 | GLIB_AVAILABLE_IN_ALL |
115 | gboolean g_file_test (const gchar *filename, |
116 | GFileTest test); |
117 | GLIB_AVAILABLE_IN_ALL |
118 | gboolean g_file_get_contents (const gchar *filename, |
119 | gchar **contents, |
120 | gsize *length, |
121 | GError **error); |
122 | GLIB_AVAILABLE_IN_ALL |
123 | gboolean g_file_set_contents (const gchar *filename, |
124 | const gchar *contents, |
125 | gssize length, |
126 | GError **error); |
127 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
128 | GLIB_AVAILABLE_IN_2_66 |
129 | gboolean g_file_set_contents_full (const gchar *filename, |
130 | const gchar *contents, |
131 | gssize length, |
132 | GFileSetContentsFlags flags, |
133 | int mode, |
134 | GError **error); |
135 | G_GNUC_END_IGNORE_DEPRECATIONS |
136 | GLIB_AVAILABLE_IN_ALL |
137 | gchar *g_file_read_link (const gchar *filename, |
138 | GError **error); |
139 | |
140 | /* Wrapper / workalike for mkdtemp() */ |
141 | GLIB_AVAILABLE_IN_2_30 |
142 | gchar *g_mkdtemp (gchar *tmpl); |
143 | GLIB_AVAILABLE_IN_2_30 |
144 | gchar *g_mkdtemp_full (gchar *tmpl, |
145 | gint mode); |
146 | |
147 | /* Wrapper / workalike for mkstemp() */ |
148 | GLIB_AVAILABLE_IN_ALL |
149 | gint g_mkstemp (gchar *tmpl); |
150 | GLIB_AVAILABLE_IN_ALL |
151 | gint g_mkstemp_full (gchar *tmpl, |
152 | gint flags, |
153 | gint mode); |
154 | |
155 | /* Wrappers for g_mkstemp and g_mkdtemp() */ |
156 | GLIB_AVAILABLE_IN_ALL |
157 | gint g_file_open_tmp (const gchar *tmpl, |
158 | gchar **name_used, |
159 | GError **error); |
160 | GLIB_AVAILABLE_IN_2_30 |
161 | gchar *g_dir_make_tmp (const gchar *tmpl, |
162 | GError **error); |
163 | |
164 | GLIB_AVAILABLE_IN_ALL |
165 | gchar *g_build_path (const gchar *separator, |
166 | const gchar *first_element, |
167 | ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED; |
168 | GLIB_AVAILABLE_IN_ALL |
169 | gchar *g_build_pathv (const gchar *separator, |
170 | gchar **args) G_GNUC_MALLOC; |
171 | |
172 | GLIB_AVAILABLE_IN_ALL |
173 | gchar *g_build_filename (const gchar *first_element, |
174 | ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED; |
175 | GLIB_AVAILABLE_IN_ALL |
176 | gchar *g_build_filenamev (gchar **args) G_GNUC_MALLOC; |
177 | GLIB_AVAILABLE_IN_2_56 |
178 | gchar *g_build_filename_valist (const gchar *first_element, |
179 | va_list *args) G_GNUC_MALLOC; |
180 | |
181 | GLIB_AVAILABLE_IN_ALL |
182 | gint g_mkdir_with_parents (const gchar *pathname, |
183 | gint mode); |
184 | |
185 | #ifdef G_OS_WIN32 |
186 | |
187 | /* On Win32, the canonical directory separator is the backslash, and |
188 | * the search path separator is the semicolon. Note that also the |
189 | * (forward) slash works as directory separator. |
190 | */ |
191 | #define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/') |
192 | |
193 | #else /* !G_OS_WIN32 */ |
194 | |
195 | #define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR) |
196 | |
197 | #endif /* !G_OS_WIN32 */ |
198 | |
199 | GLIB_AVAILABLE_IN_ALL |
200 | gboolean g_path_is_absolute (const gchar *file_name); |
201 | GLIB_AVAILABLE_IN_ALL |
202 | const gchar *g_path_skip_root (const gchar *file_name); |
203 | |
204 | GLIB_DEPRECATED_FOR(g_path_get_basename) |
205 | const gchar *g_basename (const gchar *file_name); |
206 | #define g_dirname g_path_get_dirname GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_path_get_dirname) |
207 | |
208 | GLIB_AVAILABLE_IN_ALL |
209 | gchar *g_get_current_dir (void); |
210 | GLIB_AVAILABLE_IN_ALL |
211 | gchar *g_path_get_basename (const gchar *file_name) G_GNUC_MALLOC; |
212 | GLIB_AVAILABLE_IN_ALL |
213 | gchar *g_path_get_dirname (const gchar *file_name) G_GNUC_MALLOC; |
214 | |
215 | GLIB_AVAILABLE_IN_2_58 |
216 | gchar *g_canonicalize_filename (const gchar *filename, |
217 | const gchar *relative_to) G_GNUC_MALLOC; |
218 | |
219 | G_END_DECLS |
220 | |
221 | #endif /* __G_FILEUTILS_H__ */ |
222 | |