Introduce the idea of a filename encoding, which is *literally* the
[glib.git] / docs / reference / glib / tmpl / fileutils.sgml
blob28ebe3b2c2b03a55d864f7d09d22bf4cc992a903
1 <!-- ##### SECTION Title ##### -->
2 File Utilities
4 <!-- ##### SECTION Short_Description ##### -->
5 various file-related functions.
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
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.
15 </para>
16 <para>
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.
21 </para>
22 <para>
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.
28 </para>
30 <para>
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().
34 </para>
36 <!-- ##### SECTION See_Also ##### -->
37 <para>
39 </para>
41 <!-- ##### ENUM GFileError ##### -->
42 <para>
43 Values corresponding to <literal>errno</literal> codes returned from file operations
44 on UNIX. Unlike <literal>errno</literal> codes, #GFileError values are available on
45 all systems, even Windows. The exact meaning of each code depends on what
46 sort of file operation you were performing; the UNIX documentation
47 gives more details. The following error code descriptions come
48 from the GNU C Library manual, and are under the copyright
49 of that manual.
50 </para>
52 <para>
53 It's not very portable to make detailed assumptions about exactly
54 which errors will be returned from a given operation. Some errors
55 don't occur on some systems, etc., sometimes there are subtle
56 differences in when a system will report a given error, etc.
57 </para>
59 @G_FILE_ERROR_EXIST: Operation not permitted; only the owner of the
60 file (or other resource) or processes with special privileges can
61 perform the operation.
62 @G_FILE_ERROR_ISDIR: File is a directory; you cannot open a directory
63 for writing, or create or remove hard links to it.
64 @G_FILE_ERROR_ACCES: Permission denied; the file permissions do not
65 allow the attempted operation.
66 @G_FILE_ERROR_NAMETOOLONG: Filename too long.
67 @G_FILE_ERROR_NOENT: No such file or directory. This is a "file
68 doesn't exist" error for ordinary files that are referenced in
69 contexts where they are expected to already exist.
70 @G_FILE_ERROR_NOTDIR: A file that isn't a directory was specified when
71 a directory is required.
72 @G_FILE_ERROR_NXIO: No such device or address. The system tried to
73 use the device represented by a file you specified, and it
74 couldn't find the device. This can mean that the device file was
75 installed incorrectly, or that the physical device is missing or
76 not correctly attached to the computer.
77 @G_FILE_ERROR_NODEV: This file is of a type that doesn't support
78 mapping.
79 @G_FILE_ERROR_ROFS: The directory containing the new link can't be
80 modified because it's on a read-only file system.
81 @G_FILE_ERROR_TXTBSY: Text file busy.
82 @G_FILE_ERROR_FAULT: You passed in a pointer to bad memory.
83 (GLib won't reliably return this, don't pass in pointers to bad
84 memory.)
85 @G_FILE_ERROR_LOOP: Too many levels of symbolic links were encountered
86 in looking up a file name. This often indicates a cycle of symbolic
87 links.
88 @G_FILE_ERROR_NOSPC: No space left on device; write operation on a
89 file failed because the disk is full.
90 @G_FILE_ERROR_NOMEM: No memory available. The system cannot allocate
91 more virtual memory because its capacity is full.
92 @G_FILE_ERROR_MFILE: The current process has too many files open and
93 can't open any more. Duplicate descriptors do count toward this
94 limit.
95 @G_FILE_ERROR_NFILE: There are too many distinct file openings in the
96 entire system.
97 @G_FILE_ERROR_BADF: Bad file descriptor; for example, I/O on a
98 descriptor that has been closed or reading from a descriptor open
99 only for writing (or vice versa).
100 @G_FILE_ERROR_INVAL: Invalid argument. This is used to indicate
101 various kinds of problems with passing the wrong argument to a
102 library function.
103 @G_FILE_ERROR_PIPE: Broken pipe; there is no process reading from the
104 other end of a pipe. Every library function that returns this
105 error code also generates a `SIGPIPE' signal; this signal
106 terminates the program if not handled or blocked. Thus, your
107 program will never actually see this code unless it has handled or
108 blocked `SIGPIPE'.
109 @G_FILE_ERROR_AGAIN: Resource temporarily unavailable; the call might
110 work if you try again later.
111 @G_FILE_ERROR_INTR: Interrupted function call; an asynchronous signal
112 occurred and prevented completion of the call. When this
113 happens, you should try the call again.
114 @G_FILE_ERROR_IO: Input/output error; usually used for physical read
115 or write errors. i.e. the disk or other physical device hardware
116 is returning errors.
117 @G_FILE_ERROR_PERM: Operation not permitted; only the owner of the
118 file (or other resource) or processes with special privileges can
119 perform the operation.
120 @G_FILE_ERROR_NOSYS: Function not implemented; this indicates that the
121 system is missing some functionality.
122 @G_FILE_ERROR_FAILED: Does not correspond to a UNIX error code; this
123 is the standard "failed for unspecified reason" error code present in
124 all #GError error code enumerations. Returned if no specific
125 code applies.
127 <!-- ##### MACRO G_FILE_ERROR ##### -->
128 <para>
129 Error domain for file operations. Errors in this domain will
130 be from the #GFileError enumeration. See #GError for information on
131 error domains.
132 </para>
136 <!-- ##### ENUM GFileTest ##### -->
137 <para>
138 A test to perform on a file using g_file_test().
139 </para>
141 @G_FILE_TEST_IS_REGULAR: %TRUE if the file is a regular file (not a symlink or directory)
142 @G_FILE_TEST_IS_SYMLINK: %TRUE if the file is a symlink.
143 @G_FILE_TEST_IS_DIR: %TRUE if the file is a directory.
144 @G_FILE_TEST_IS_EXECUTABLE: %TRUE if the file is executable.
145 @G_FILE_TEST_EXISTS: %TRUE if the file exists. It may or may not be a regular file.
147 <!-- ##### FUNCTION g_file_error_from_errno ##### -->
148 <para>
150 </para>
152 @err_no:
153 @Returns:
156 <!-- ##### FUNCTION g_file_get_contents ##### -->
157 <para>
159 </para>
161 @filename:
162 @contents:
163 @length:
164 @error:
165 @Returns:
168 <!-- ##### FUNCTION g_file_test ##### -->
169 <para>
171 </para>
173 @filename:
174 @test:
175 @Returns:
178 <!-- ##### FUNCTION g_mkstemp ##### -->
179 <para>
181 </para>
183 @tmpl:
184 @Returns:
187 <!-- ##### FUNCTION g_file_open_tmp ##### -->
188 <para>
190 </para>
192 @tmpl:
193 @name_used:
194 @error:
195 @Returns:
198 <!-- ##### FUNCTION g_file_read_link ##### -->
199 <para>
201 </para>
203 @filename:
204 @error:
205 @Returns:
208 <!-- ##### STRUCT GDir ##### -->
209 <para>
210 An opaque structure representing an opened directory.
211 </para>
214 <!-- ##### FUNCTION g_dir_open ##### -->
215 <para>
217 </para>
219 @path:
220 @flags:
221 @error:
222 @Returns:
225 <!-- ##### FUNCTION g_dir_read_name ##### -->
226 <para>
228 </para>
230 @dir:
231 @Returns:
234 <!-- ##### FUNCTION g_dir_rewind ##### -->
235 <para>
237 </para>
239 @dir:
242 <!-- ##### FUNCTION g_dir_close ##### -->
243 <para>
245 </para>
247 @dir:
250 <!-- ##### FUNCTION g_open ##### -->
251 <para>
253 </para>
255 @filename:
256 @flags:
257 @mode:
258 @Returns:
261 <!-- ##### FUNCTION g_rename ##### -->
262 <para>
264 </para>
266 @oldfilename:
267 @newfilename:
268 @Returns:
271 <!-- ##### FUNCTION g_mkdir ##### -->
272 <para>
274 </para>
276 @filename:
277 @mode:
278 @Returns:
281 <!-- ##### FUNCTION g_stat ##### -->
282 <para>
284 </para>
286 @filename:
287 @buf:
288 @Returns:
291 <!-- ##### FUNCTION g_unlink ##### -->
292 <para>
294 </para>
296 @filename:
297 @Returns:
300 <!-- ##### FUNCTION g_remove ##### -->
301 <para>
303 </para>
305 @filename:
306 @Returns:
309 <!-- ##### FUNCTION g_fopen ##### -->
310 <para>
312 </para>
314 @filename:
315 @mode:
316 @Returns:
319 <!-- ##### FUNCTION g_freopen ##### -->
320 <para>
322 </para>
324 @filename:
325 @mode:
326 @stream:
327 @Returns: