inotify: stop using constructor()
[glib.git] / glib / gfileutils.h
blob93dbde3e21bf5e5afd816e849b1d6c238f05b670
1 /* gfileutils.h - File utility functions
3 * Copyright 2000 Red Hat, Inc.
5 * GLib is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * GLib 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.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with GLib; see the file COPYING.LIB. If not,
17 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #ifndef __G_FILEUTILS_H__
22 #define __G_FILEUTILS_H__
24 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
25 #error "Only <glib.h> can be included directly."
26 #endif
28 #include <glib/gerror.h>
30 G_BEGIN_DECLS
32 #define G_FILE_ERROR g_file_error_quark ()
34 typedef enum
36 G_FILE_ERROR_EXIST,
37 G_FILE_ERROR_ISDIR,
38 G_FILE_ERROR_ACCES,
39 G_FILE_ERROR_NAMETOOLONG,
40 G_FILE_ERROR_NOENT,
41 G_FILE_ERROR_NOTDIR,
42 G_FILE_ERROR_NXIO,
43 G_FILE_ERROR_NODEV,
44 G_FILE_ERROR_ROFS,
45 G_FILE_ERROR_TXTBSY,
46 G_FILE_ERROR_FAULT,
47 G_FILE_ERROR_LOOP,
48 G_FILE_ERROR_NOSPC,
49 G_FILE_ERROR_NOMEM,
50 G_FILE_ERROR_MFILE,
51 G_FILE_ERROR_NFILE,
52 G_FILE_ERROR_BADF,
53 G_FILE_ERROR_INVAL,
54 G_FILE_ERROR_PIPE,
55 G_FILE_ERROR_AGAIN,
56 G_FILE_ERROR_INTR,
57 G_FILE_ERROR_IO,
58 G_FILE_ERROR_PERM,
59 G_FILE_ERROR_NOSYS,
60 G_FILE_ERROR_FAILED
61 } GFileError;
63 /* For backward-compat reasons, these are synced to an old
64 * anonymous enum in libgnome. But don't use that enum
65 * in new code.
67 typedef enum
69 G_FILE_TEST_IS_REGULAR = 1 << 0,
70 G_FILE_TEST_IS_SYMLINK = 1 << 1,
71 G_FILE_TEST_IS_DIR = 1 << 2,
72 G_FILE_TEST_IS_EXECUTABLE = 1 << 3,
73 G_FILE_TEST_EXISTS = 1 << 4
74 } GFileTest;
76 GLIB_AVAILABLE_IN_ALL
77 GQuark g_file_error_quark (void);
78 /* So other code can generate a GFileError */
79 GLIB_AVAILABLE_IN_ALL
80 GFileError g_file_error_from_errno (gint err_no);
82 GLIB_AVAILABLE_IN_ALL
83 gboolean g_file_test (const gchar *filename,
84 GFileTest test);
85 GLIB_AVAILABLE_IN_ALL
86 gboolean g_file_get_contents (const gchar *filename,
87 gchar **contents,
88 gsize *length,
89 GError **error);
90 GLIB_AVAILABLE_IN_ALL
91 gboolean g_file_set_contents (const gchar *filename,
92 const gchar *contents,
93 gssize length,
94 GError **error);
95 GLIB_AVAILABLE_IN_ALL
96 gchar *g_file_read_link (const gchar *filename,
97 GError **error);
99 /* Wrapper / workalike for mkdtemp() */
100 GLIB_AVAILABLE_IN_2_30
101 gchar *g_mkdtemp (gchar *tmpl);
102 GLIB_AVAILABLE_IN_2_30
103 gchar *g_mkdtemp_full (gchar *tmpl,
104 gint mode);
106 /* Wrapper / workalike for mkstemp() */
107 GLIB_AVAILABLE_IN_ALL
108 gint g_mkstemp (gchar *tmpl);
109 GLIB_AVAILABLE_IN_ALL
110 gint g_mkstemp_full (gchar *tmpl,
111 gint flags,
112 gint mode);
114 /* Wrappers for g_mkstemp and g_mkdtemp() */
115 GLIB_AVAILABLE_IN_ALL
116 gint g_file_open_tmp (const gchar *tmpl,
117 gchar **name_used,
118 GError **error);
119 GLIB_AVAILABLE_IN_2_30
120 gchar *g_dir_make_tmp (const gchar *tmpl,
121 GError **error);
123 GLIB_AVAILABLE_IN_ALL
124 gchar *g_build_path (const gchar *separator,
125 const gchar *first_element,
126 ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
127 GLIB_AVAILABLE_IN_ALL
128 gchar *g_build_pathv (const gchar *separator,
129 gchar **args) G_GNUC_MALLOC;
131 GLIB_AVAILABLE_IN_ALL
132 gchar *g_build_filename (const gchar *first_element,
133 ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
134 GLIB_AVAILABLE_IN_ALL
135 gchar *g_build_filenamev (gchar **args) G_GNUC_MALLOC;
137 GLIB_AVAILABLE_IN_ALL
138 gint g_mkdir_with_parents (const gchar *pathname,
139 gint mode);
141 #ifdef G_OS_WIN32
143 /* On Win32, the canonical directory separator is the backslash, and
144 * the search path separator is the semicolon. Note that also the
145 * (forward) slash works as directory separator.
147 #define G_DIR_SEPARATOR '\\'
148 #define G_DIR_SEPARATOR_S "\\"
149 #define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/')
150 #define G_SEARCHPATH_SEPARATOR ';'
151 #define G_SEARCHPATH_SEPARATOR_S ";"
153 #else /* !G_OS_WIN32 */
155 #define G_DIR_SEPARATOR '/'
156 #define G_DIR_SEPARATOR_S "/"
157 #define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR)
158 #define G_SEARCHPATH_SEPARATOR ':'
159 #define G_SEARCHPATH_SEPARATOR_S ":"
161 #endif /* !G_OS_WIN32 */
163 GLIB_AVAILABLE_IN_ALL
164 gboolean g_path_is_absolute (const gchar *file_name);
165 GLIB_AVAILABLE_IN_ALL
166 const gchar *g_path_skip_root (const gchar *file_name);
168 GLIB_DEPRECATED_FOR(g_path_get_basename)
169 const gchar *g_basename (const gchar *file_name);
170 #ifndef G_DISABLE_DEPRECATED
171 #define g_dirname g_path_get_dirname
172 #endif
174 GLIB_AVAILABLE_IN_ALL
175 gchar *g_get_current_dir (void);
176 GLIB_AVAILABLE_IN_ALL
177 gchar *g_path_get_basename (const gchar *file_name) G_GNUC_MALLOC;
178 GLIB_AVAILABLE_IN_ALL
179 gchar *g_path_get_dirname (const gchar *file_name) G_GNUC_MALLOC;
181 #ifdef G_OS_WIN32
182 #define g_file_test g_file_test_utf8
183 #define g_file_get_contents g_file_get_contents_utf8
184 #define g_mkstemp g_mkstemp_utf8
185 #define g_file_open_tmp g_file_open_tmp_utf8
186 #define g_get_current_dir g_get_current_dir_utf8
188 GLIB_AVAILABLE_IN_ALL
189 gboolean g_file_test_utf8 (const gchar *filename,
190 GFileTest test);
191 GLIB_AVAILABLE_IN_ALL
192 gboolean g_file_get_contents_utf8 (const gchar *filename,
193 gchar **contents,
194 gsize *length,
195 GError **error);
196 GLIB_AVAILABLE_IN_ALL
197 gint g_mkstemp_utf8 (gchar *tmpl);
198 GLIB_AVAILABLE_IN_ALL
199 gint g_file_open_tmp_utf8 (const gchar *tmpl,
200 gchar **name_used,
201 GError **error);
202 GLIB_AVAILABLE_IN_ALL
203 gchar *g_get_current_dir_utf8 (void);
204 #endif /* G_OS_WIN32 */
206 G_END_DECLS
208 #endif /* __G_FILEUTILS_H__ */