1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 various file-related functions
7 <!-- ##### SECTION Long_Description ##### -->
9 There is a group of functions which wrap the common POSIX functions
10 dealing with filenames (g_open(), g_rename(), g_mkdir(), g_stat(),
11 g_unlink(), g_remove(), g_fopen(), g_freopen()). The point of these
12 wrappers is to make it possible to handle file names with any Unicode
13 characters in them on Windows without having to use ifdefs and the
14 wide character API in the application code.
17 The pathname argument should be in the GLib file name encoding. On
18 POSIX this is the actual on-disk encoding which might correspond to
19 the locale settings of the process (or the
20 <envar>G_FILENAME_ENCODING</envar> environment variable), or not.
23 On Windows the GLib file name encoding is UTF-8. Note that the
24 Microsoft C library does not use UTF-8, but has separate APIs for
25 current system code page and wide characters (UTF-16). The GLib
26 wrappers call the wide character API if present (on modern Windows
27 systems), otherwise convert to/from the system code page.
31 Another group of functions allows to open and read directories
32 in the GLib file name encoding. These are g_dir_open(),
33 g_dir_read_name(), g_dir_rewind(), g_dir_close().
36 <!-- ##### SECTION See_Also ##### -->
41 <!-- ##### SECTION Stability_Level ##### -->
44 <!-- ##### SECTION Image ##### -->
47 <!-- ##### ENUM GFileError ##### -->
49 Values corresponding to <literal>errno</literal> codes returned from file operations
50 on UNIX. Unlike <literal>errno</literal> codes, #GFileError values are available on
51 all systems, even Windows. The exact meaning of each code depends on what
52 sort of file operation you were performing; the UNIX documentation
53 gives more details. The following error code descriptions come
54 from the GNU C Library manual, and are under the copyright
59 It's not very portable to make detailed assumptions about exactly
60 which errors will be returned from a given operation. Some errors
61 don't occur on some systems, etc., sometimes there are subtle
62 differences in when a system will report a given error, etc.
65 @G_FILE_ERROR_EXIST: Operation not permitted; only the owner of the
66 file (or other resource) or processes with special privileges can
67 perform the operation.
68 @G_FILE_ERROR_ISDIR: File is a directory; you cannot open a directory
69 for writing, or create or remove hard links to it.
70 @G_FILE_ERROR_ACCES: Permission denied; the file permissions do not
71 allow the attempted operation.
72 @G_FILE_ERROR_NAMETOOLONG: Filename too long.
73 @G_FILE_ERROR_NOENT: No such file or directory. This is a "file
74 doesn't exist" error for ordinary files that are referenced in
75 contexts where they are expected to already exist.
76 @G_FILE_ERROR_NOTDIR: A file that isn't a directory was specified when
77 a directory is required.
78 @G_FILE_ERROR_NXIO: No such device or address. The system tried to
79 use the device represented by a file you specified, and it
80 couldn't find the device. This can mean that the device file was
81 installed incorrectly, or that the physical device is missing or
82 not correctly attached to the computer.
83 @G_FILE_ERROR_NODEV: This file is of a type that doesn't support
85 @G_FILE_ERROR_ROFS: The directory containing the new link can't be
86 modified because it's on a read-only file system.
87 @G_FILE_ERROR_TXTBSY: Text file busy.
88 @G_FILE_ERROR_FAULT: You passed in a pointer to bad memory.
89 (GLib won't reliably return this, don't pass in pointers to bad
91 @G_FILE_ERROR_LOOP: Too many levels of symbolic links were encountered
92 in looking up a file name. This often indicates a cycle of symbolic
94 @G_FILE_ERROR_NOSPC: No space left on device; write operation on a
95 file failed because the disk is full.
96 @G_FILE_ERROR_NOMEM: No memory available. The system cannot allocate
97 more virtual memory because its capacity is full.
98 @G_FILE_ERROR_MFILE: The current process has too many files open and
99 can't open any more. Duplicate descriptors do count toward this
101 @G_FILE_ERROR_NFILE: There are too many distinct file openings in the
103 @G_FILE_ERROR_BADF: Bad file descriptor; for example, I/O on a
104 descriptor that has been closed or reading from a descriptor open
105 only for writing (or vice versa).
106 @G_FILE_ERROR_INVAL: Invalid argument. This is used to indicate
107 various kinds of problems with passing the wrong argument to a
109 @G_FILE_ERROR_PIPE: Broken pipe; there is no process reading from the
110 other end of a pipe. Every library function that returns this
111 error code also generates a `SIGPIPE' signal; this signal
112 terminates the program if not handled or blocked. Thus, your
113 program will never actually see this code unless it has handled or
115 @G_FILE_ERROR_AGAIN: Resource temporarily unavailable; the call might
116 work if you try again later.
117 @G_FILE_ERROR_INTR: Interrupted function call; an asynchronous signal
118 occurred and prevented completion of the call. When this
119 happens, you should try the call again.
120 @G_FILE_ERROR_IO: Input/output error; usually used for physical read
121 or write errors. i.e. the disk or other physical device hardware
123 @G_FILE_ERROR_PERM: Operation not permitted; only the owner of the
124 file (or other resource) or processes with special privileges can
125 perform the operation.
126 @G_FILE_ERROR_NOSYS: Function not implemented; this indicates that the
127 system is missing some functionality.
128 @G_FILE_ERROR_FAILED: Does not correspond to a UNIX error code; this
129 is the standard "failed for unspecified reason" error code present in
130 all #GError error code enumerations. Returned if no specific
133 <!-- ##### MACRO G_FILE_ERROR ##### -->
135 Error domain for file operations. Errors in this domain will
136 be from the #GFileError enumeration. See #GError for information on
142 <!-- ##### ENUM GFileTest ##### -->
144 A test to perform on a file using g_file_test().
147 @G_FILE_TEST_IS_REGULAR: %TRUE if the file is a regular file (not a directory).
148 Note that this test will also return %TRUE if the tested file is a symlink
150 @G_FILE_TEST_IS_SYMLINK: %TRUE if the file is a symlink.
151 @G_FILE_TEST_IS_DIR: %TRUE if the file is a directory.
152 @G_FILE_TEST_IS_EXECUTABLE: %TRUE if the file is executable.
153 @G_FILE_TEST_EXISTS: %TRUE if the file exists.
154 It may or may not be a regular file.
156 <!-- ##### FUNCTION g_file_error_from_errno ##### -->
165 <!-- ##### FUNCTION g_file_get_contents ##### -->
177 <!-- ##### FUNCTION g_file_set_contents ##### -->
189 <!-- ##### FUNCTION g_file_test ##### -->
199 <!-- ##### FUNCTION g_mkstemp ##### -->
208 <!-- ##### FUNCTION g_mkstemp_full ##### -->
219 <!-- ##### FUNCTION g_file_open_tmp ##### -->
230 <!-- ##### FUNCTION g_file_read_link ##### -->
240 <!-- ##### FUNCTION g_mkdir_with_parents ##### -->
250 <!-- ##### STRUCT GDir ##### -->
252 An opaque structure representing an opened directory.
256 <!-- ##### FUNCTION g_dir_open ##### -->
267 <!-- ##### FUNCTION g_dir_read_name ##### -->
276 <!-- ##### FUNCTION g_dir_rewind ##### -->
284 <!-- ##### FUNCTION g_dir_close ##### -->
292 <!-- ##### STRUCT GMappedFile ##### -->
294 The #GMappedFile represents a file mapping created with
295 g_mapped_file_new(). It has only private members and should
296 not be accessed directly.
300 <!-- ##### FUNCTION g_mapped_file_new ##### -->
311 <!-- ##### FUNCTION g_mapped_file_ref ##### -->
320 <!-- ##### FUNCTION g_mapped_file_unref ##### -->
328 <!-- ##### FUNCTION g_mapped_file_free ##### -->
336 <!-- ##### FUNCTION g_mapped_file_get_length ##### -->
345 <!-- ##### FUNCTION g_mapped_file_get_contents ##### -->
354 <!-- ##### FUNCTION g_open ##### -->
365 <!-- ##### FUNCTION g_rename ##### -->
375 <!-- ##### FUNCTION g_mkdir ##### -->
385 <!-- ##### FUNCTION g_stat ##### -->
395 <!-- ##### FUNCTION g_lstat ##### -->
405 <!-- ##### FUNCTION g_unlink ##### -->
414 <!-- ##### FUNCTION g_remove ##### -->
423 <!-- ##### FUNCTION g_rmdir ##### -->
432 <!-- ##### FUNCTION g_fopen ##### -->
442 <!-- ##### FUNCTION g_freopen ##### -->
453 <!-- ##### FUNCTION g_chmod ##### -->
463 <!-- ##### FUNCTION g_access ##### -->
473 <!-- ##### FUNCTION g_creat ##### -->
483 <!-- ##### FUNCTION g_chdir ##### -->
492 <!-- ##### FUNCTION g_utime ##### -->