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
75GLIB_AVAILABLE_IN_ALL
76GQuark g_file_error_quark (void);
77/* So other code can generate a GFileError */
78GLIB_AVAILABLE_IN_ALL
79GFileError g_file_error_from_errno (gint err_no);
80
81GLIB_AVAILABLE_IN_ALL
82gboolean g_file_test (const gchar *filename,
83 GFileTest test);
84GLIB_AVAILABLE_IN_ALL
85gboolean g_file_get_contents (const gchar *filename,
86 gchar **contents,
87 gsize *length,
88 GError **error);
89GLIB_AVAILABLE_IN_ALL
90gboolean g_file_set_contents (const gchar *filename,
91 const gchar *contents,
92 gssize length,
93 GError **error);
94GLIB_AVAILABLE_IN_ALL
95gchar *g_file_read_link (const gchar *filename,
96 GError **error);
97
98/* Wrapper / workalike for mkdtemp() */
99GLIB_AVAILABLE_IN_2_30
100gchar *g_mkdtemp (gchar *tmpl);
101GLIB_AVAILABLE_IN_2_30
102gchar *g_mkdtemp_full (gchar *tmpl,
103 gint mode);
104
105/* Wrapper / workalike for mkstemp() */
106GLIB_AVAILABLE_IN_ALL
107gint g_mkstemp (gchar *tmpl);
108GLIB_AVAILABLE_IN_ALL
109gint g_mkstemp_full (gchar *tmpl,
110 gint flags,
111 gint mode);
112
113/* Wrappers for g_mkstemp and g_mkdtemp() */
114GLIB_AVAILABLE_IN_ALL
115gint g_file_open_tmp (const gchar *tmpl,
116 gchar **name_used,
117 GError **error);
118GLIB_AVAILABLE_IN_2_30
119gchar *g_dir_make_tmp (const gchar *tmpl,
120 GError **error);
121
122GLIB_AVAILABLE_IN_ALL
123gchar *g_build_path (const gchar *separator,
124 const gchar *first_element,
125 ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
126GLIB_AVAILABLE_IN_ALL
127gchar *g_build_pathv (const gchar *separator,
128 gchar **args) G_GNUC_MALLOC;
129
130GLIB_AVAILABLE_IN_ALL
131gchar *g_build_filename (const gchar *first_element,
132 ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
133GLIB_AVAILABLE_IN_ALL
134gchar *g_build_filenamev (gchar **args) G_GNUC_MALLOC;
135GLIB_AVAILABLE_IN_2_56
136gchar *g_build_filename_valist (const gchar *first_element,
137 va_list *args) G_GNUC_MALLOC;
138
139GLIB_AVAILABLE_IN_ALL
140gint g_mkdir_with_parents (const gchar *pathname,
141 gint mode);
142
143#ifdef G_OS_WIN32
144
145/* On Win32, the canonical directory separator is the backslash, and
146 * the search path separator is the semicolon. Note that also the
147 * (forward) slash works as directory separator.
148 */
149#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/')
150
151#else /* !G_OS_WIN32 */
152
153#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR)
154
155#endif /* !G_OS_WIN32 */
156
157GLIB_AVAILABLE_IN_ALL
158gboolean g_path_is_absolute (const gchar *file_name);
159GLIB_AVAILABLE_IN_ALL
160const gchar *g_path_skip_root (const gchar *file_name);
161
162GLIB_DEPRECATED_FOR(g_path_get_basename)
163const gchar *g_basename (const gchar *file_name);
164#ifndef G_DISABLE_DEPRECATED
165#define g_dirname g_path_get_dirname
166#endif
167
168GLIB_AVAILABLE_IN_ALL
169gchar *g_get_current_dir (void);
170GLIB_AVAILABLE_IN_ALL
171gchar *g_path_get_basename (const gchar *file_name) G_GNUC_MALLOC;
172GLIB_AVAILABLE_IN_ALL
173gchar *g_path_get_dirname (const gchar *file_name) G_GNUC_MALLOC;
174
175GLIB_AVAILABLE_IN_2_58
176gchar *g_canonicalize_filename (const gchar *filename,
177 const gchar *relative_to) G_GNUC_MALLOC;
178
179G_END_DECLS
180
181#endif /* __G_FILEUTILS_H__ */
182