1 /*
2  * Distributed under the Boost Software License, Version 1.0.
3  *    (See accompanying file LICENSE_1_0.txt or copy at
4  *          http://www.boost.org/LICENSE_1_0.txt)
5  */
6 module glib.gfileutils;
7 
8 import glib.gtypes;
9 import glib.gerror;
10 
11 
12 //enum G_FILE_ERROR = g_file_error_quark ();
13 
14 enum GFileError
15 {
16   G_FILE_ERROR_EXIST,
17   G_FILE_ERROR_ISDIR,
18   G_FILE_ERROR_ACCES,
19   G_FILE_ERROR_NAMETOOLONG,
20   G_FILE_ERROR_NOENT,
21   G_FILE_ERROR_NOTDIR,
22   G_FILE_ERROR_NXIO,
23   G_FILE_ERROR_NODEV,
24   G_FILE_ERROR_ROFS,
25   G_FILE_ERROR_TXTBSY,
26   G_FILE_ERROR_FAULT,
27   G_FILE_ERROR_LOOP,
28   G_FILE_ERROR_NOSPC,
29   G_FILE_ERROR_NOMEM,
30   G_FILE_ERROR_MFILE,
31   G_FILE_ERROR_NFILE,
32   G_FILE_ERROR_BADF,
33   G_FILE_ERROR_INVAL,
34   G_FILE_ERROR_PIPE,
35   G_FILE_ERROR_AGAIN,
36   G_FILE_ERROR_INTR,
37   G_FILE_ERROR_IO,
38   G_FILE_ERROR_PERM,
39   G_FILE_ERROR_NOSYS,
40   G_FILE_ERROR_FAILED
41 }
42 
43 enum GFileTest
44 {
45   G_FILE_TEST_IS_REGULAR    = 1 << 0,
46   G_FILE_TEST_IS_SYMLINK    = 1 << 1,
47   G_FILE_TEST_IS_DIR        = 1 << 2,
48   G_FILE_TEST_IS_EXECUTABLE = 1 << 3,
49   G_FILE_TEST_EXISTS        = 1 << 4
50 }
51 
52 
53 extern (C) {
54 
55     GQuark     g_file_error_quark      ();
56 
57     GFileError g_file_error_from_errno (gint err_no);
58 
59 
60 
61     gboolean g_file_set_contents (const(gchar) *filename,
62                                   const(gchar) *contents,
63                                   gssize         length,
64                                   GError       **error);
65 
66     gchar   *g_file_read_link    (const(gchar)  *filename,
67                                   GError      **error);
68 
69     gchar   *g_mkdtemp            (gchar        *tmpl);
70 
71     gchar   *g_mkdtemp_full       (gchar        *tmpl,
72                                    gint          mode);
73 
74     gint     g_mkstemp_full       (gchar        *tmpl,
75                                    gint          flags,
76                                    gint          mode);
77 
78     gchar   *g_dir_make_tmp       (const(gchar)  *tmpl,
79                                    GError      **error);
80 
81     gchar   *g_build_path         (const(gchar) *separator,
82                                    const(gchar) *first_element,
83                                    ...);
84 
85     gchar   *g_build_pathv        (const(gchar)  *separator,
86                                    gchar       **args);
87 
88     gchar   *g_build_filename     (const(gchar) *first_element,
89                                    ...);
90 
91     gchar   *g_build_filenamev    (gchar      **args);
92 
93     gint     g_mkdir_with_parents (const(gchar) *pathname,
94                                    gint         mode);
95 
96 
97     version (Win32) {
98         enum G_DIR_SEPARATOR = '\\';
99         enum G_DIR_SEPARATOR_S = "\\";
100         auto G_IS_DIR_SEPARATOR(C)(C c) {
101             return c == G_DIR_SEPARATOR || c == '/';
102         }
103         enum G_SEARCHPATH_SEPARATOR = ';';
104         enum G_SEARCHPATH_SEPARATOR_S = ";";
105     }
106     else {  /* !G_OS_WIN32 */
107         enum G_DIR_SEPARATOR = '/';
108         enum G_DIR_SEPARATOR_S = "/";
109         auto G_IS_DIR_SEPARATOR(C)(C c) {
110             return c == G_DIR_SEPARATOR;
111         }
112         enum G_SEARCHPATH_SEPARATOR = ':';
113         enum G_SEARCHPATH_SEPARATOR_S = ":";
114     }
115 
116 
117     gboolean     g_path_is_absolute (const(gchar) *file_name);
118 
119     const(gchar) *g_path_skip_root   (const(gchar) *file_name);
120 
121     deprecated("use g_path_get_basename")
122     const(gchar) *g_basename         (const(gchar) *file_name);
123 
124 
125 
126     gchar *g_path_get_basename (const(gchar) *file_name);
127 
128     gchar *g_path_get_dirname  (const(gchar) *file_name);
129 
130     version (Win32) {
131 
132         gboolean g_file_test_utf8         (const(gchar)  *filename,
133                                            GFileTest     test);
134 
135         gboolean g_file_get_contents_utf8 (const(gchar)  *filename,
136                                            gchar       **contents,
137                                            gsize        *length,
138                                            GError      **error);
139 
140         gint     g_mkstemp_utf8           (gchar        *tmpl);
141 
142         gint     g_file_open_tmp_utf8     (const(gchar)  *tmpl,
143                                            gchar       **name_used,
144                                            GError      **error);
145 
146         gchar   *g_get_current_dir_utf8   ();
147 
148         alias g_file_test = g_file_test_utf8;
149         alias g_file_get_contents = g_file_get_contents_utf8;
150         alias g_mkstemp = g_mkstemp_utf8;
151         alias g_file_open_tmp = g_file_open_tmp_utf8;
152         alias g_get_current_dir = g_get_current_dir_utf8;
153 
154     }
155     else {
156 
157         gboolean g_file_test         (const(gchar)  *filename,
158                                       GFileTest     test);
159 
160         gboolean g_file_get_contents (const(gchar)  *filename,
161                                       gchar       **contents,
162                                       gsize        *length,
163                                       GError      **error);
164 
165         gint     g_mkstemp            (gchar        *tmpl);
166 
167         gint     g_file_open_tmp      (const(gchar)  *tmpl,
168                                        gchar       **name_used,
169                                        GError      **error);
170 
171         gchar *g_get_current_dir   ();
172 
173     }
174 }