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
29G_BEGIN_DECLS
30
31#define G_FILE_ERROR g_file_error_quark ()
32
33typedef 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 */
66typedef 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 */
99typedef 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
106GLIB_AVAILABLE_ENUMERATOR_IN_2_66;
107
108GLIB_AVAILABLE_IN_ALL
109GQuark g_file_error_quark (void);
110/* So other code can generate a GFileError */
111GLIB_AVAILABLE_IN_ALL
112GFileError g_file_error_from_errno (gint err_no);
113
114GLIB_AVAILABLE_IN_ALL
115gboolean g_file_test (const gchar *filename,
116 GFileTest test);
117GLIB_AVAILABLE_IN_ALL
118gboolean g_file_get_contents (const gchar *filename,
119 gchar **contents,
120 gsize *length,
121 GError **error);
122GLIB_AVAILABLE_IN_ALL
123gboolean g_file_set_contents (const gchar *filename,
124 const gchar *contents,
125 gssize length,
126 GError **error);
127G_GNUC_BEGIN_IGNORE_DEPRECATIONS
128GLIB_AVAILABLE_IN_2_66
129gboolean g_file_set_contents_full (const gchar *filename,
130 const gchar *contents,
131 gssize length,
132 GFileSetContentsFlags flags,
133 int mode,
134 GError **error);
135G_GNUC_END_IGNORE_DEPRECATIONS
136GLIB_AVAILABLE_IN_ALL
137gchar *g_file_read_link (const gchar *filename,
138 GError **error);
139
140/* Wrapper / workalike for mkdtemp() */
141GLIB_AVAILABLE_IN_2_30
142gchar *g_mkdtemp (gchar *tmpl);
143GLIB_AVAILABLE_IN_2_30
144gchar *g_mkdtemp_full (gchar *tmpl,
145 gint mode);
146
147/* Wrapper / workalike for mkstemp() */
148GLIB_AVAILABLE_IN_ALL
149gint g_mkstemp (gchar *tmpl);
150GLIB_AVAILABLE_IN_ALL
151gint g_mkstemp_full (gchar *tmpl,
152 gint flags,
153 gint mode);
154
155/* Wrappers for g_mkstemp and g_mkdtemp() */
156GLIB_AVAILABLE_IN_ALL
157gint g_file_open_tmp (const gchar *tmpl,
158 gchar **name_used,
159 GError **error);
160GLIB_AVAILABLE_IN_2_30
161gchar *g_dir_make_tmp (const gchar *tmpl,
162 GError **error);
163
164GLIB_AVAILABLE_IN_ALL
165gchar *g_build_path (const gchar *separator,
166 const gchar *first_element,
167 ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
168GLIB_AVAILABLE_IN_ALL
169gchar *g_build_pathv (const gchar *separator,
170 gchar **args) G_GNUC_MALLOC;
171
172GLIB_AVAILABLE_IN_ALL
173gchar *g_build_filename (const gchar *first_element,
174 ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
175GLIB_AVAILABLE_IN_ALL
176gchar *g_build_filenamev (gchar **args) G_GNUC_MALLOC;
177GLIB_AVAILABLE_IN_2_56
178gchar *g_build_filename_valist (const gchar *first_element,
179 va_list *args) G_GNUC_MALLOC;
180
181GLIB_AVAILABLE_IN_ALL
182gint 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
199GLIB_AVAILABLE_IN_ALL
200gboolean g_path_is_absolute (const gchar *file_name);
201GLIB_AVAILABLE_IN_ALL
202const gchar *g_path_skip_root (const gchar *file_name);
203
204GLIB_DEPRECATED_FOR(g_path_get_basename)
205const 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
208GLIB_AVAILABLE_IN_ALL
209gchar *g_get_current_dir (void);
210GLIB_AVAILABLE_IN_ALL
211gchar *g_path_get_basename (const gchar *file_name) G_GNUC_MALLOC;
212GLIB_AVAILABLE_IN_ALL
213gchar *g_path_get_dirname (const gchar *file_name) G_GNUC_MALLOC;
214
215GLIB_AVAILABLE_IN_2_58
216gchar *g_canonicalize_filename (const gchar *filename,
217 const gchar *relative_to) G_GNUC_MALLOC;
218
219G_END_DECLS
220
221#endif /* __G_FILEUTILS_H__ */
222

source code of include/glib-2.0/glib/gfileutils.h