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 <!-- ##### ENUM GFileError ##### -->
46 Values corresponding to <literal>errno</literal> codes returned from file operations
47 on UNIX. Unlike <literal>errno</literal> codes, #GFileError values are available on
48 all systems, even Windows. The exact meaning of each code depends on what
49 sort of file operation you were performing; the UNIX documentation
50 gives more details. The following error code descriptions come
51 from the GNU C Library manual, and are under the copyright
56 It's not very portable to make detailed assumptions about exactly
57 which errors will be returned from a given operation. Some errors
58 don't occur on some systems, etc., sometimes there are subtle
59 differences in when a system will report a given error, etc.
62 @G_FILE_ERROR_EXIST: Operation not permitted; only the owner of the
63 file (or other resource) or processes with special privileges can
64 perform the operation.
65 @G_FILE_ERROR_ISDIR: File is a directory; you cannot open a directory
66 for writing, or create or remove hard links to it.
67 @G_FILE_ERROR_ACCES: Permission denied; the file permissions do not
68 allow the attempted operation.
69 @G_FILE_ERROR_NAMETOOLONG: Filename too long.
70 @G_FILE_ERROR_NOENT: No such file or directory. This is a "file
71 doesn't exist" error for ordinary files that are referenced in
72 contexts where they are expected to already exist.
73 @G_FILE_ERROR_NOTDIR: A file that isn't a directory was specified when
74 a directory is required.
75 @G_FILE_ERROR_NXIO: No such device or address. The system tried to
76 use the device represented by a file you specified, and it
77 couldn't find the device. This can mean that the device file was
78 installed incorrectly, or that the physical device is missing or
79 not correctly attached to the computer.
80 @G_FILE_ERROR_NODEV: This file is of a type that doesn't support
82 @G_FILE_ERROR_ROFS: The directory containing the new link can't be
83 modified because it's on a read-only file system.
84 @G_FILE_ERROR_TXTBSY: Text file busy.
85 @G_FILE_ERROR_FAULT: You passed in a pointer to bad memory.
86 (GLib won't reliably return this, don't pass in pointers to bad
88 @G_FILE_ERROR_LOOP: Too many levels of symbolic links were encountered
89 in looking up a file name. This often indicates a cycle of symbolic
91 @G_FILE_ERROR_NOSPC: No space left on device; write operation on a
92 file failed because the disk is full.
93 @G_FILE_ERROR_NOMEM: No memory available. The system cannot allocate
94 more virtual memory because its capacity is full.
95 @G_FILE_ERROR_MFILE: The current process has too many files open and
96 can't open any more. Duplicate descriptors do count toward this
98 @G_FILE_ERROR_NFILE: There are too many distinct file openings in the
100 @G_FILE_ERROR_BADF: Bad file descriptor; for example, I/O on a
101 descriptor that has been closed or reading from a descriptor open
102 only for writing (or vice versa).
103 @G_FILE_ERROR_INVAL: Invalid argument. This is used to indicate
104 various kinds of problems with passing the wrong argument to a
106 @G_FILE_ERROR_PIPE: Broken pipe; there is no process reading from the
107 other end of a pipe. Every library function that returns this
108 error code also generates a `SIGPIPE' signal; this signal
109 terminates the program if not handled or blocked. Thus, your
110 program will never actually see this code unless it has handled or
112 @G_FILE_ERROR_AGAIN: Resource temporarily unavailable; the call might
113 work if you try again later.
114 @G_FILE_ERROR_INTR: Interrupted function call; an asynchronous signal
115 occurred and prevented completion of the call. When this
116 happens, you should try the call again.
117 @G_FILE_ERROR_IO: Input/output error; usually used for physical read
118 or write errors. i.e. the disk or other physical device hardware
120 @G_FILE_ERROR_PERM: Operation not permitted; only the owner of the
121 file (or other resource) or processes with special privileges can
122 perform the operation.
123 @G_FILE_ERROR_NOSYS: Function not implemented; this indicates that the
124 system is missing some functionality.
125 @G_FILE_ERROR_FAILED: Does not correspond to a UNIX error code; this
126 is the standard "failed for unspecified reason" error code present in
127 all #GError error code enumerations. Returned if no specific
130 <!-- ##### MACRO G_FILE_ERROR ##### -->
132 Error domain for file operations. Errors in this domain will
133 be from the #GFileError enumeration. See #GError for information on
139 <!-- ##### ENUM GFileTest ##### -->
141 A test to perform on a file using g_file_test().
144 @G_FILE_TEST_IS_REGULAR: %TRUE if the file is a regular file (not a symlink or directory)
145 @G_FILE_TEST_IS_SYMLINK: %TRUE if the file is a symlink.
146 @G_FILE_TEST_IS_DIR: %TRUE if the file is a directory.
147 @G_FILE_TEST_IS_EXECUTABLE: %TRUE if the file is executable.
148 @G_FILE_TEST_EXISTS: %TRUE if the file exists. It may or may not be a regular file.
150 <!-- ##### FUNCTION g_file_error_from_errno ##### -->
159 <!-- ##### FUNCTION g_file_get_contents ##### -->
171 <!-- ##### FUNCTION g_file_set_contents ##### -->
183 <!-- ##### FUNCTION g_file_test ##### -->
193 <!-- ##### FUNCTION g_mkstemp ##### -->
202 <!-- ##### FUNCTION g_file_open_tmp ##### -->
213 <!-- ##### FUNCTION g_file_read_link ##### -->
223 <!-- ##### STRUCT GDir ##### -->
225 An opaque structure representing an opened directory.
229 <!-- ##### FUNCTION g_dir_open ##### -->
240 <!-- ##### FUNCTION g_dir_read_name ##### -->
249 <!-- ##### FUNCTION g_dir_rewind ##### -->
257 <!-- ##### FUNCTION g_dir_close ##### -->
265 <!-- ##### STRUCT GMappedFile ##### -->
267 The #GMappedFile represents a file mapping created with
268 g_mapped_file_new(). It has only private members and should
269 not be accessed directly.
273 <!-- ##### FUNCTION g_mapped_file_new ##### -->
284 <!-- ##### FUNCTION g_mapped_file_free ##### -->
292 <!-- ##### FUNCTION g_mapped_file_get_length ##### -->
301 <!-- ##### FUNCTION g_mapped_file_get_contents ##### -->
310 <!-- ##### FUNCTION g_open ##### -->
321 <!-- ##### FUNCTION g_rename ##### -->
331 <!-- ##### FUNCTION g_mkdir ##### -->
341 <!-- ##### FUNCTION g_stat ##### -->
351 <!-- ##### FUNCTION g_lstat ##### -->
361 <!-- ##### FUNCTION g_unlink ##### -->
370 <!-- ##### FUNCTION g_remove ##### -->
379 <!-- ##### FUNCTION g_rmdir ##### -->
388 <!-- ##### FUNCTION g_fopen ##### -->
398 <!-- ##### FUNCTION g_freopen ##### -->
409 <!-- ##### FUNCTION g_chmod ##### -->
419 <!-- ##### FUNCTION g_access ##### -->
429 <!-- ##### FUNCTION g_creat ##### -->
439 <!-- ##### FUNCTION g_chdir ##### -->