1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD 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
13  * GNU 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 gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = glib-File-Utilities.html
27  * outPack = glib
28  * outFile = FileUtils
29  * strct   = 
30  * realStrct=
31  * ctorStrct=
32  * clss    = FileUtils
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_
41  * omit structs:
42  * omit prefixes:
43  * 	- g_dir_
44  * 	- g_mapped_file_
45  * omit code:
46  * 	- g_file_get_contents
47  * omit signals:
48  * imports:
49  * 	- std.c.stdio
50  * 	- glib.Str
51  * 	- glib.ErrorG
52  * 	- glib.GException
53  * structWrap:
54  * module aliases:
55  * local aliases:
56  * overrides:
57  */
58 
59 module glib.FileUtils;
60 
61 public  import gtkc.glibtypes;
62 
63 private import gtkc.glib;
64 private import glib.ConstructionException;
65 
66 private import std.c.stdio;
67 private import glib.Str;
68 private import glib.ErrorG;
69 private import glib.GException;
70 
71 
72 
73 /**
74  * There is a group of functions which wrap the common POSIX functions
75  * dealing with filenames (g_open(), g_rename(), g_mkdir(), g_stat(),
76  * g_unlink(), g_remove(), g_fopen(), g_freopen()). The point of these
77  * wrappers is to make it possible to handle file names with any Unicode
78  * characters in them on Windows without having to use ifdefs and the
79  * wide character API in the application code.
80  *
81  * The pathname argument should be in the GLib file name encoding.
82  * On POSIX this is the actual on-disk encoding which might correspond
83  * to the locale settings of the process (or the
84  * G_FILENAME_ENCODING environment variable), or not.
85  *
86  * On Windows the GLib file name encoding is UTF-8. Note that the
87  * Microsoft C library does not use UTF-8, but has separate APIs for
88  * current system code page and wide characters (UTF-16). The GLib
89  * wrappers call the wide character API if present (on modern Windows
90  * systems), otherwise convert to/from the system code page.
91  *
92  * Another group of functions allows to open and read directories
93  * in the GLib file name encoding. These are g_dir_open(),
94  * g_dir_read_name(), g_dir_rewind(), g_dir_close().
95  */
96 public class FileUtils
97 {
98 	
99 	/**
100 	 * Reads an entire file into allocated memory, with good error
101 	 * checking.
102 	 * If the call was successful, it returns TRUE and sets contents to the file
103 	 * contents and length to the length of the file contents in bytes. The string
104 	 * stored in contents will be nul-terminated, so for text files you can pass
105 	 * NULL for the length argument. If the call was not successful, it returns
106 	 * FALSE and sets error. The error domain is G_FILE_ERROR. Possible error
107 	 * codes are those in the GFileError enumeration. In the error case,
108 	 * contents is set to NULL and length is set to zero.
109 	 * Params:
110 	 * filename = name of a file to read contents from, in the GLib file name encoding. [type filename]
111 	 * contents = location to store an allocated string, use g_free() to free
112 	 * the returned string. [out][array length=length][element-type guint8]
113 	 * Returns: TRUE on success, FALSE if an error occurred
114 	 * Throws: GException on failure.
115 	 */
116 	public static int fileGetContents(string filename, out char[] contents)
117 	{
118 		// gboolean g_file_get_contents (const gchar *filename,  gchar **contents,  gsize *length,  GError **error);
119 		gchar* outcontents = null;
120 		size_t length;
121 		GError* err = null;
122 		
123 		auto p = g_file_get_contents(Str.toStringz(filename), &outcontents, &length, &err);
124 		
125 		if (err !is null)
126 		{
127 			throw new GException( new ErrorG(err) );
128 		}
129 		
130 		contents = outcontents[0 .. length];
131 		return p;
132 	}
133 	
134 	/**
135 	 */
136 	
137 	/**
138 	 * Gets a GFileError constant based on the passed-in err_no.
139 	 * For example, if you pass in EEXIST this function returns
140 	 * G_FILE_ERROR_EXIST. Unlike errno values, you can portably
141 	 * assume that all GFileError values will exist.
142 	 * Normally a GFileError value goes into a GError returned
143 	 * from a function that manipulates files. So you would use
144 	 * g_file_error_from_errno() when constructing a GError.
145 	 * Params:
146 	 * errNo = an "errno" value
147 	 * Returns: GFileError corresponding to the given errno
148 	 */
149 	public static GFileError fileErrorFromErrno(int errNo)
150 	{
151 		// GFileError g_file_error_from_errno (gint err_no);
152 		return g_file_error_from_errno(errNo);
153 	}
154 	
155 	/**
156 	 * Writes all of contents to a file named filename, with good error checking.
157 	 * If a file called filename already exists it will be overwritten.
158 	 * This write is atomic in the sense that it is first written to a temporary
159 	 * Since 2.8
160 	 * Params:
161 	 * filename = name of a file to write contents to, in the GLib file name
162 	 * encoding. [type filename]
163 	 * contents = string to write to the file. [array length=length][element-type guint8]
164 	 * Returns: TRUE on success, FALSE if an error occurred
165 	 * Throws: GException on failure.
166 	 */
167 	public static int fileSetContents(string filename, string contents)
168 	{
169 		// gboolean g_file_set_contents (const gchar *filename,  const gchar *contents,  gssize length,  GError **error);
170 		GError* err = null;
171 		
172 		auto p = g_file_set_contents(Str.toStringz(filename), cast(char*)contents.ptr, cast(int) contents.length, &err);
173 		
174 		if (err !is null)
175 		{
176 			throw new GException( new ErrorG(err) );
177 		}
178 		
179 		return p;
180 	}
181 	
182 	/**
183 	 * Returns TRUE if any of the tests in the bitfield test are
184 	 * TRUE. For example, (G_FILE_TEST_EXISTS |
185 	 * G_FILE_TEST_IS_DIR) will return TRUE if the file exists;
186 	 * the check whether it's a directory doesn't matter since the existence
187 	 * test is TRUE. With the current set of available tests, there's no point
188 	 * passing in more than one test at a time.
189 	 * Apart from G_FILE_TEST_IS_SYMLINK all tests follow symbolic links,
190 	 * so for a symbolic link to a regular file g_file_test() will return
191 	 * TRUE for both G_FILE_TEST_IS_SYMLINK and G_FILE_TEST_IS_REGULAR.
192 	 * Note, that for a dangling symbolic link g_file_test() will return
193 	 * TRUE for G_FILE_TEST_IS_SYMLINK and FALSE for all other flags.
194 	 * You should never use g_file_test() to test whether it is safe
195 	 * to perform an operation, because there is always the possibility
196 	 * of the condition changing before you actually perform the operation.
197 	 * For example, you might think you could use G_FILE_TEST_IS_SYMLINK
198 	 * to know whether it is safe to write to a file without being
199 	 * tricked into writing into a different location. It doesn't work!
200 	 * $(DDOC_COMMENT example)
201 	 * Another thing to note is that G_FILE_TEST_EXISTS and
202 	 * G_FILE_TEST_IS_EXECUTABLE are implemented using the access()
203 	 * system call. This usually doesn't matter, but if your program
204 	 * is setuid or setgid it means that these tests will give you
205 	 * the answer for the real user ID and group ID, rather than the
206 	 * effective user ID and group ID.
207 	 * On Windows, there are no symlinks, so testing for
208 	 * G_FILE_TEST_IS_SYMLINK will always return FALSE. Testing for
209 	 * G_FILE_TEST_IS_EXECUTABLE will just check that the file exists and
210 	 * its name indicates that it is executable, checking for well-known
211 	 * extensions and those listed in the PATHEXT environment variable.
212 	 * Params:
213 	 * filename = a filename to test in the GLib file name encoding
214 	 * test = bitfield of GFileTest flags
215 	 * Returns: whether a test was TRUE
216 	 */
217 	public static int fileTest(string filename, GFileTest test)
218 	{
219 		// gboolean g_file_test (const gchar *filename,  GFileTest test);
220 		return g_file_test(Str.toStringz(filename), test);
221 	}
222 	
223 	/**
224 	 * Opens a temporary file. See the mkstemp() documentation
225 	 * on most UNIX-like systems.
226 	 * The parameter is a string that should follow the rules for
227 	 * mkstemp() templates, i.e. contain the string "XXXXXX".
228 	 * g_mkstemp() is slightly more flexible than mkstemp() in that the
229 	 * sequence does not have to occur at the very end of the template.
230 	 * The X string will be modified to form the name of a file that
231 	 * didn't exist. The string should be in the GLib file name encoding.
232 	 * Most importantly, on Windows it should be in UTF-8.
233 	 * Params:
234 	 * tmpl = template filename. [type filename]
235 	 * Returns: A file handle (as from open()) to the file opened for reading and writing. The file is opened in binary mode on platforms where there is a difference. The file handle should be closed with close(). In case of errors, -1 is returned and errno will be set.
236 	 */
237 	public static int mkstemp(string tmpl)
238 	{
239 		// gint g_mkstemp (gchar *tmpl);
240 		return g_mkstemp(Str.toStringz(tmpl));
241 	}
242 	
243 	/**
244 	 * Opens a temporary file. See the mkstemp() documentation
245 	 * on most UNIX-like systems.
246 	 * The parameter is a string that should follow the rules for
247 	 * mkstemp() templates, i.e. contain the string "XXXXXX".
248 	 * g_mkstemp_full() is slightly more flexible than mkstemp()
249 	 * in that the sequence does not have to occur at the very end of the
250 	 * template and you can pass a mode and additional flags. The X
251 	 * string will be modified to form the name of a file that didn't exist.
252 	 * The string should be in the GLib file name encoding. Most importantly,
253 	 * on Windows it should be in UTF-8.
254 	 * Since 2.22
255 	 * Params:
256 	 * tmpl = template filename. [type filename]
257 	 * flags = flags to pass to an open() call in addition to O_EXCL
258 	 * and O_CREAT, which are passed automatically
259 	 * mode = permissions to create the temporary file with
260 	 * Returns: A file handle (as from open()) to the file opened for reading and writing. The file handle should be closed with close(). In case of errors, -1 is returned and errno will be set.
261 	 */
262 	public static int mkstempFull(string tmpl, int flags, int mode)
263 	{
264 		// gint g_mkstemp_full (gchar *tmpl,  gint flags,  gint mode);
265 		return g_mkstemp_full(Str.toStringz(tmpl), flags, mode);
266 	}
267 	
268 	/**
269 	 * Opens a file for writing in the preferred directory for temporary
270 	 * files (as returned by g_get_tmp_dir()).
271 	 * tmpl should be a string in the GLib file name encoding containing
272 	 * a sequence of six 'X' characters, as the parameter to g_mkstemp().
273 	 * However, unlike these functions, the template should only be a
274 	 * basename, no directory components are allowed. If template is
275 	 * NULL, a default template is used.
276 	 * Note that in contrast to g_mkstemp() (and mkstemp()) tmpl is not
277 	 * modified, and might thus be a read-only literal string.
278 	 * Upon success, and if name_used is non-NULL, the actual name used
279 	 * is returned in name_used. This string should be freed with g_free()
280 	 * when not needed any longer. The returned name is in the GLib file
281 	 * name encoding.
282 	 * Params:
283 	 * tmpl = Template for file name, as in
284 	 * g_mkstemp(), basename only, or NULL for a default template. [type filename][allow-none]
285 	 * nameUsed = location to store actual name used,
286 	 * or NULL. [out][type filename]
287 	 * Returns: A file handle (as from open()) to the file opened for reading and writing. The file is opened in binary mode on platforms where there is a difference. The file handle should be closed with close(). In case of errors, -1 is returned and error will be set.
288 	 * Throws: GException on failure.
289 	 */
290 	public static int fileOpenTmp(string tmpl, out string nameUsed)
291 	{
292 		// gint g_file_open_tmp (const gchar *tmpl,  gchar **name_used,  GError **error);
293 		char* outnameUsed = null;
294 		GError* err = null;
295 		
296 		auto p = g_file_open_tmp(Str.toStringz(tmpl), &outnameUsed, &err);
297 		
298 		if (err !is null)
299 		{
300 			throw new GException( new ErrorG(err) );
301 		}
302 		
303 		nameUsed = Str.toString(outnameUsed);
304 		return p;
305 	}
306 	
307 	/**
308 	 * Reads the contents of the symbolic link filename like the POSIX
309 	 * readlink() function. The returned string is in the encoding used
310 	 * for filenames. Use g_filename_to_utf8() to convert it to UTF-8.
311 	 * Since 2.4
312 	 * Params:
313 	 * filename = the symbolic link
314 	 * Returns: A newly-allocated string with the contents of the symbolic link, or NULL if an error occurred.
315 	 * Throws: GException on failure.
316 	 */
317 	public static string fileReadLink(string filename)
318 	{
319 		// gchar * g_file_read_link (const gchar *filename,  GError **error);
320 		GError* err = null;
321 		
322 		auto p = g_file_read_link(Str.toStringz(filename), &err);
323 		
324 		if (err !is null)
325 		{
326 			throw new GException( new ErrorG(err) );
327 		}
328 		
329 		return Str.toString(p);
330 	}
331 	
332 	/**
333 	 * Create a directory if it doesn't already exist. Create intermediate
334 	 * parent directories as needed, too.
335 	 * Since 2.8
336 	 * Params:
337 	 * pathname = a pathname in the GLib file name encoding
338 	 * mode = permissions to use for newly created directories
339 	 * Returns: 0 if the directory already exists, or was successfully created. Returns -1 if an error occurred, with errno set.
340 	 */
341 	public static int mkdirWithParents(string pathname, int mode)
342 	{
343 		// gint g_mkdir_with_parents (const gchar *pathname,  gint mode);
344 		return g_mkdir_with_parents(Str.toStringz(pathname), mode);
345 	}
346 	
347 	/**
348 	 * Creates a temporary directory. See the mkdtemp() documentation
349 	 * on most UNIX-like systems.
350 	 * The parameter is a string that should follow the rules for
351 	 * mkdtemp() templates, i.e. contain the string "XXXXXX".
352 	 * g_mkdtemp() is slightly more flexible than mkdtemp() in that the
353 	 * sequence does not have to occur at the very end of the template
354 	 * and you can pass a mode and additional flags. The X string will
355 	 * be modified to form the name of a directory that didn't exist.
356 	 * The string should be in the GLib file name encoding. Most importantly,
357 	 * on Windows it should be in UTF-8.
358 	 * Since 2.30
359 	 * Params:
360 	 * tmpl = template directory name. [type filename]
361 	 * Returns: A pointer to tmpl, which has been modified to hold the directory name. In case of errors, NULL is returned and errno will be set.
362 	 */
363 	public static string mkdtemp(string tmpl)
364 	{
365 		// gchar * g_mkdtemp (gchar *tmpl);
366 		return Str.toString(g_mkdtemp(Str.toStringz(tmpl)));
367 	}
368 	
369 	/**
370 	 * Creates a temporary directory. See the mkdtemp() documentation
371 	 * on most UNIX-like systems.
372 	 * The parameter is a string that should follow the rules for
373 	 * mkdtemp() templates, i.e. contain the string "XXXXXX".
374 	 * g_mkdtemp() is slightly more flexible than mkdtemp() in that the
375 	 * sequence does not have to occur at the very end of the template
376 	 * and you can pass a mode. The X string will be modified to form
377 	 * the name of a directory that didn't exist. The string should be
378 	 * in the GLib file name encoding. Most importantly, on Windows it
379 	 * should be in UTF-8.
380 	 * Since 2.30
381 	 * Params:
382 	 * tmpl = template directory name. [type filename]
383 	 * mode = permissions to create the temporary directory with
384 	 * Returns: A pointer to tmpl, which has been modified to hold the directory name. In case of errors, NULL is returned, and errno will be set.
385 	 */
386 	public static string mkdtempFull(string tmpl, int mode)
387 	{
388 		// gchar * g_mkdtemp_full (gchar *tmpl,  gint mode);
389 		return Str.toString(g_mkdtemp_full(Str.toStringz(tmpl), mode));
390 	}
391 	
392 	/**
393 	 * A wrapper for the POSIX open() function. The open() function is
394 	 * used to convert a pathname into a file descriptor.
395 	 * On POSIX systems file descriptors are implemented by the operating
396 	 * system. On Windows, it's the C library that implements open() and
397 	 * file descriptors. The actual Win32 API for opening files is quite
398 	 * different, see MSDN documentation for CreateFile(). The Win32 API
399 	 * uses file handles, which are more randomish integers, not small
400 	 * integers like file descriptors.
401 	 * Because file descriptors are specific to the C library on Windows,
402 	 * the file descriptor returned by this function makes sense only to
403 	 * functions in the same C library. Thus if the GLib-using code uses a
404 	 * different C library than GLib does, the file descriptor returned by
405 	 * this function cannot be passed to C library functions like write()
406 	 * or read().
407 	 * See your C library manual for more details about open().
408 	 * Since 2.6
409 	 * Params:
410 	 * filename = a pathname in the GLib file name encoding (UTF-8 on Windows)
411 	 * flags = as in open()
412 	 * mode = as in open()
413 	 * Returns: a new file descriptor, or -1 if an error occurred. The return value can be used exactly like the return value from open().
414 	 */
415 	public static int open(string filename, int flags, int mode)
416 	{
417 		// int g_open (const gchar *filename,  int flags,  int mode);
418 		return g_open(Str.toStringz(filename), flags, mode);
419 	}
420 	
421 	/**
422 	 * A wrapper for the POSIX rename() function. The rename() function
423 	 * renames a file, moving it between directories if required.
424 	 * See your C library manual for more details about how rename() works
425 	 * on your system. It is not possible in general on Windows to rename
426 	 * a file that is open to some process.
427 	 * Since 2.6
428 	 * Params:
429 	 * oldfilename = a pathname in the GLib file name encoding (UTF-8 on Windows)
430 	 * newfilename = a pathname in the GLib file name encoding
431 	 * Returns: 0 if the renaming succeeded, -1 if an error occurred
432 	 */
433 	public static int rename(string oldfilename, string newfilename)
434 	{
435 		// int g_rename (const gchar *oldfilename,  const gchar *newfilename);
436 		return g_rename(Str.toStringz(oldfilename), Str.toStringz(newfilename));
437 	}
438 	
439 	/**
440 	 * A wrapper for the POSIX mkdir() function. The mkdir() function
441 	 * attempts to create a directory with the given name and permissions.
442 	 * The mode argument is ignored on Windows.
443 	 * See your C library manual for more details about mkdir().
444 	 * Since 2.6
445 	 * Params:
446 	 * filename = a pathname in the GLib file name encoding (UTF-8 on Windows)
447 	 * mode = permissions to use for the newly created directory
448 	 * Returns: 0 if the directory was successfully created, -1 if an error occurred
449 	 */
450 	public static int mkdir(string filename, int mode)
451 	{
452 		// int g_mkdir (const gchar *filename,  int mode);
453 		return g_mkdir(Str.toStringz(filename), mode);
454 	}
455 	
456 	/**
457 	 * A wrapper for the POSIX stat() function. The stat() function
458 	 * returns information about a file. On Windows the stat() function in
459 	 * the C library checks only the FAT-style READONLY attribute and does
460 	 * not look at the ACL at all. Thus on Windows the protection bits in
461 	 * the st_mode field are a fabrication of little use.
462 	 * On Windows the Microsoft C libraries have several variants of the
463 	 * stat struct and stat() function with names
464 	 * like "_stat", "_stat32", "_stat32i64" and "_stat64i32". The one
465 	 * used here is for 32-bit code the one with 32-bit size and time
466 	 * fields, specifically called "_stat32".
467 	 * In Microsoft's compiler, by default "struct stat" means one with
468 	 * 64-bit time fields while in MinGW "struct stat" is the legacy one
469 	 * with 32-bit fields. To hopefully clear up this messs, the gstdio.h
470 	 * header defines a type GStatBuf which is the appropriate struct type
471 	 * depending on the platform and/or compiler being used. On POSIX it
472 	 * is just "struct stat", but note that even on POSIX platforms,
473 	 * "stat" might be a macro.
474 	 * See your C library manual for more details about stat().
475 	 * Since 2.6
476 	 * Params:
477 	 * filename = a pathname in the GLib file name encoding (UTF-8 on Windows)
478 	 * buf = a pointer to a stat struct, which
479 	 * will be filled with the file information
480 	 * Returns: 0 if the information was successfully retrieved, -1 if an error occurred
481 	 */
482 	public static int stat(string filename, GStatBuf* buf)
483 	{
484 		// int g_stat (const gchar *filename,  GStatBuf *buf);
485 		return g_stat(Str.toStringz(filename), buf);
486 	}
487 	
488 	/**
489 	 * A wrapper for the POSIX lstat() function. The lstat() function is
490 	 * like stat() except that in the case of symbolic links, it returns
491 	 * information about the symbolic link itself and not the file that it
492 	 * refers to. If the system does not support symbolic links g_lstat()
493 	 * is identical to g_stat().
494 	 * See your C library manual for more details about lstat().
495 	 * Since 2.6
496 	 * Params:
497 	 * filename = a pathname in the GLib file name encoding (UTF-8 on Windows)
498 	 * buf = a pointer to a stat struct, which
499 	 * will be filled with the file information
500 	 * Returns: 0 if the information was successfully retrieved, -1 if an error occurred
501 	 */
502 	public static int lstat(string filename, GStatBuf* buf)
503 	{
504 		// int g_lstat (const gchar *filename,  GStatBuf *buf);
505 		return g_lstat(Str.toStringz(filename), buf);
506 	}
507 	
508 	/**
509 	 * A wrapper for the POSIX unlink() function. The unlink() function
510 	 * deletes a name from the filesystem. If this was the last link to the
511 	 * file and no processes have it opened, the diskspace occupied by the
512 	 * file is freed.
513 	 * See your C library manual for more details about unlink(). Note
514 	 * that on Windows, it is in general not possible to delete files that
515 	 * are open to some process, or mapped into memory.
516 	 * Since 2.6
517 	 * Params:
518 	 * filename = a pathname in the GLib file name encoding (UTF-8 on Windows)
519 	 * Returns: 0 if the name was successfully deleted, -1 if an error occurred
520 	 */
521 	public static int unlink(string filename)
522 	{
523 		// int g_unlink (const gchar *filename);
524 		return g_unlink(Str.toStringz(filename));
525 	}
526 	
527 	/**
528 	 * A wrapper for the POSIX remove() function. The remove() function
529 	 * deletes a name from the filesystem.
530 	 * See your C library manual for more details about how remove() works
531 	 * on your system. On Unix, remove() removes also directories, as it
532 	 * calls unlink() for files and rmdir() for directories. On Windows,
533 	 * although remove() in the C library only works for files, this
534 	 * function tries first remove() and then if that fails rmdir(), and
535 	 * thus works for both files and directories. Note however, that on
536 	 * Windows, it is in general not possible to remove a file that is
537 	 * open to some process, or mapped into memory.
538 	 * If this function fails on Windows you can't infer too much from the
539 	 * errno value. rmdir() is tried regardless of what caused remove() to
540 	 * fail. Any errno value set by remove() will be overwritten by that
541 	 * set by rmdir().
542 	 * Since 2.6
543 	 * Params:
544 	 * filename = a pathname in the GLib file name encoding (UTF-8 on Windows)
545 	 * Returns: 0 if the file was successfully removed, -1 if an error occurred
546 	 */
547 	public static int remove(string filename)
548 	{
549 		// int g_remove (const gchar *filename);
550 		return g_remove(Str.toStringz(filename));
551 	}
552 	
553 	/**
554 	 * A wrapper for the POSIX rmdir() function. The rmdir() function
555 	 * deletes a directory from the filesystem.
556 	 * See your C library manual for more details about how rmdir() works
557 	 * on your system.
558 	 * Since 2.6
559 	 * Params:
560 	 * filename = a pathname in the GLib file name encoding (UTF-8 on Windows)
561 	 * Returns: 0 if the directory was successfully removed, -1 if an error occurred
562 	 */
563 	public static int rmdir(string filename)
564 	{
565 		// int g_rmdir (const gchar *filename);
566 		return g_rmdir(Str.toStringz(filename));
567 	}
568 	
569 	/**
570 	 * A wrapper for the stdio fopen() function. The fopen() function
571 	 * opens a file and associates a new stream with it.
572 	 * Because file descriptors are specific to the C library on Windows,
573 	 * and a file descriptor is partof the FILE struct, the
574 	 * FILE pointer returned by this function makes sense
575 	 * only to functions in the same C library. Thus if the GLib-using
576 	 * code uses a different C library than GLib does, the
577 	 * FILE pointer returned by this function cannot be
578 	 * passed to C library functions like fprintf() or fread().
579 	 * See your C library manual for more details about fopen().
580 	 * Since 2.6
581 	 * Params:
582 	 * filename = a pathname in the GLib file name encoding (UTF-8 on Windows)
583 	 * mode = a string describing the mode in which the file should be
584 	 * opened
585 	 * Returns: A FILE pointer if the file was successfully opened, or NULL if an error occurred
586 	 */
587 	public static FILE* fopen(string filename, string mode)
588 	{
589 		// FILE * g_fopen (const gchar *filename,  const gchar *mode);
590 		return cast(FILE*)g_fopen(Str.toStringz(filename), Str.toStringz(mode));
591 	}
592 	
593 	/**
594 	 * A wrapper for the POSIX freopen() function. The freopen() function
595 	 * opens a file and associates it with an existing stream.
596 	 * See your C library manual for more details about freopen().
597 	 * Since 2.6
598 	 * Params:
599 	 * filename = a pathname in the GLib file name encoding (UTF-8 on Windows)
600 	 * mode = a string describing the mode in which the file should be
601 	 * opened
602 	 * stream = an existing stream which will be reused, or NULL. [allow-none]
603 	 * Returns: A FILE pointer if the file was successfully opened, or NULL if an error occurred.
604 	 */
605 	public static FILE* freopen(string filename, string mode, FILE* stream)
606 	{
607 		// FILE * g_freopen (const gchar *filename,  const gchar *mode,  FILE *stream);
608 		return cast(FILE*)g_freopen(Str.toStringz(filename), Str.toStringz(mode), cast(void*)stream);
609 	}
610 	
611 	/**
612 	 * A wrapper for the POSIX chmod() function. The chmod() function is
613 	 * used to set the permissions of a file system object.
614 	 * On Windows the file protection mechanism is not at all POSIX-like,
615 	 * and the underlying chmod() function in the C library just sets or
616 	 * clears the FAT-style READONLY attribute. It does not touch any
617 	 * ACL. Software that needs to manage file permissions on Windows
618 	 * exactly should use the Win32 API.
619 	 * See your C library manual for more details about chmod().
620 	 * Since 2.8
621 	 * Params:
622 	 * filename = a pathname in the GLib file name encoding (UTF-8 on Windows)
623 	 * mode = as in chmod()
624 	 * Returns: zero if the operation succeeded, -1 on error.
625 	 */
626 	public static int chmod(string filename, int mode)
627 	{
628 		// int g_chmod (const gchar *filename,  int mode);
629 		return g_chmod(Str.toStringz(filename), mode);
630 	}
631 	
632 	/**
633 	 * A wrapper for the POSIX access() function. This function is used to
634 	 * test a pathname for one or several of read, write or execute
635 	 * permissions, or just existence.
636 	 * On Windows, the file protection mechanism is not at all POSIX-like,
637 	 * and the underlying function in the C library only checks the
638 	 * FAT-style READONLY attribute, and does not look at the ACL of a
639 	 * file at all. This function is this in practise almost useless on
640 	 * Windows. Software that needs to handle file permissions on Windows
641 	 * more exactly should use the Win32 API.
642 	 * See your C library manual for more details about access().
643 	 * Since 2.8
644 	 * Params:
645 	 * filename = a pathname in the GLib file name encoding (UTF-8 on Windows)
646 	 * mode = as in access()
647 	 * Returns: zero if the pathname refers to an existing file system object that has all the tested permissions, or -1 otherwise or on error.
648 	 */
649 	public static int access(string filename, int mode)
650 	{
651 		// int g_access (const gchar *filename,  int mode);
652 		return g_access(Str.toStringz(filename), mode);
653 	}
654 	
655 	/**
656 	 * A wrapper for the POSIX creat() function. The creat() function is
657 	 * used to convert a pathname into a file descriptor, creating a file
658 	 * if necessary.
659 	 * On POSIX systems file descriptors are implemented by the operating
660 	 * system. On Windows, it's the C library that implements creat() and
661 	 * file descriptors. The actual Windows API for opening files is
662 	 * different, see MSDN documentation for CreateFile(). The Win32 API
663 	 * uses file handles, which are more randomish integers, not small
664 	 * integers like file descriptors.
665 	 * Because file descriptors are specific to the C library on Windows,
666 	 * the file descriptor returned by this function makes sense only to
667 	 * functions in the same C library. Thus if the GLib-using code uses a
668 	 * different C library than GLib does, the file descriptor returned by
669 	 * this function cannot be passed to C library functions like write()
670 	 * or read().
671 	 * See your C library manual for more details about creat().
672 	 * Since 2.8
673 	 * Params:
674 	 * filename = a pathname in the GLib file name encoding (UTF-8 on Windows)
675 	 * mode = as in creat()
676 	 * Returns: a new file descriptor, or -1 if an error occurred. The return value can be used exactly like the return value from creat().
677 	 */
678 	public static int creat(string filename, int mode)
679 	{
680 		// int g_creat (const gchar *filename,  int mode);
681 		return g_creat(Str.toStringz(filename), mode);
682 	}
683 	
684 	/**
685 	 * A wrapper for the POSIX chdir() function. The function changes the
686 	 * current directory of the process to path.
687 	 * See your C library manual for more details about chdir().
688 	 * Since 2.8
689 	 * Params:
690 	 * path = a pathname in the GLib file name encoding (UTF-8 on Windows)
691 	 * Returns: 0 on success, -1 if an error occurred.
692 	 */
693 	public static int chdir(string path)
694 	{
695 		// int g_chdir (const gchar *path);
696 		return g_chdir(Str.toStringz(path));
697 	}
698 	
699 	/**
700 	 * A wrapper for the POSIX utime() function. The utime() function
701 	 * sets the access and modification timestamps of a file.
702 	 * See your C library manual for more details about how utime() works
703 	 * on your system.
704 	 * Since 2.18
705 	 * Params:
706 	 * filename = a pathname in the GLib file name encoding (UTF-8 on Windows)
707 	 * utb = a pointer to a struct utimbuf.
708 	 * Returns: 0 if the operation was successful, -1 if an error occurred
709 	 */
710 	public static int utime(string filename, void* utb)
711 	{
712 		// int g_utime (const gchar *filename,  struct utimbuf *utb);
713 		return g_utime(Str.toStringz(filename), utb);
714 	}
715 	
716 	/**
717 	 * This wraps the close() call; in case of error, errno will be
718 	 * preserved, but the error will also be stored as a GError in error.
719 	 * Besides using GError, there is another major reason to prefer this
720 	 * function over the call provided by the system; on Unix, it will
721 	 * attempt to correctly handle EINTR, which has platform-specific
722 	 * semantics.
723 	 * Since 2.36
724 	 * Params:
725 	 * fd = A file descriptor
726 	 * Throws: GException on failure.
727 	 */
728 	public static int close(int fd)
729 	{
730 		// gboolean g_close (gint fd,  GError **error);
731 		GError* err = null;
732 		
733 		auto p = g_close(fd, &err);
734 		
735 		if (err !is null)
736 		{
737 			throw new GException( new ErrorG(err) );
738 		}
739 		
740 		return p;
741 	}
742 }