Updates
[platform/upstream/glib.git] / docs / reference / glib / tmpl / fileutils.sgml
1 <!-- ##### SECTION Title ##### -->
2 File Utilities
3
4 <!-- ##### SECTION Short_Description ##### -->
5 various file-related functions.
6
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>
29
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>
35
36 <!-- ##### SECTION See_Also ##### -->
37 <para>
38
39 </para>
40
41 <!-- ##### SECTION Stability_Level ##### -->
42
43
44 <!-- ##### ENUM GFileError ##### -->
45 <para>
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
52 of that manual.
53 </para>
54
55 <para>
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.
60 </para>
61
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
81      mapping.
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
87   memory.)
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
90   links.
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
97      limit.
98 @G_FILE_ERROR_NFILE: There are too many distinct file openings in the
99      entire system.
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
105      library function.
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
111      blocked `SIGPIPE'.
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
119     is returning errors.
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
128   code applies.
129
130 <!-- ##### MACRO G_FILE_ERROR ##### -->
131 <para>
132 Error domain for file operations. Errors in this domain will
133 be from the #GFileError enumeration. See #GError for information on 
134 error domains.
135 </para>
136
137
138
139 <!-- ##### ENUM GFileTest ##### -->
140 <para>
141 A test to perform on a file using g_file_test().
142 </para>
143
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.
149
150 <!-- ##### FUNCTION g_file_error_from_errno ##### -->
151 <para>
152
153 </para>
154
155 @err_no: 
156 @Returns: 
157
158
159 <!-- ##### FUNCTION g_file_get_contents ##### -->
160 <para>
161
162 </para>
163
164 @filename: 
165 @contents: 
166 @length: 
167 @error: 
168 @Returns: 
169
170
171 <!-- ##### FUNCTION g_file_set_contents ##### -->
172 <para>
173
174 </para>
175
176 @filename: 
177 @contents: 
178 @length: 
179 @error: 
180 @Returns: 
181
182
183 <!-- ##### FUNCTION g_file_test ##### -->
184 <para>
185
186 </para>
187
188 @filename: 
189 @test: 
190 @Returns: 
191
192
193 <!-- ##### FUNCTION g_mkstemp ##### -->
194 <para>
195
196 </para>
197
198 @tmpl: 
199 @Returns: 
200
201
202 <!-- ##### FUNCTION g_file_open_tmp ##### -->
203 <para>
204
205 </para>
206
207 @tmpl: 
208 @name_used: 
209 @error: 
210 @Returns: 
211
212
213 <!-- ##### FUNCTION g_file_read_link ##### -->
214 <para>
215
216 </para>
217
218 @filename: 
219 @error: 
220 @Returns: 
221
222
223 <!-- ##### STRUCT GDir ##### -->
224 <para>
225 An opaque structure representing an opened directory.
226 </para>
227
228
229 <!-- ##### FUNCTION g_dir_open ##### -->
230 <para>
231
232 </para>
233
234 @path: 
235 @flags: 
236 @error: 
237 @Returns: 
238
239
240 <!-- ##### FUNCTION g_dir_read_name ##### -->
241 <para>
242
243 </para>
244
245 @dir: 
246 @Returns: 
247
248
249 <!-- ##### FUNCTION g_dir_rewind ##### -->
250 <para>
251
252 </para>
253
254 @dir: 
255
256
257 <!-- ##### FUNCTION g_dir_close ##### -->
258 <para>
259
260 </para>
261
262 @dir: 
263
264
265 <!-- ##### STRUCT GMappedFile ##### -->
266 <para>
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.
270 </para>
271
272
273 <!-- ##### FUNCTION g_mapped_file_new ##### -->
274 <para>
275
276 </para>
277
278 @filename: 
279 @writable: 
280 @error: 
281 @Returns: 
282
283
284 <!-- ##### FUNCTION g_mapped_file_free ##### -->
285 <para>
286
287 </para>
288
289 @file: 
290
291
292 <!-- ##### FUNCTION g_mapped_file_get_length ##### -->
293 <para>
294
295 </para>
296
297 @file: 
298 @Returns: 
299
300
301 <!-- ##### FUNCTION g_mapped_file_get_contents ##### -->
302 <para>
303
304 </para>
305
306 @file: 
307 @Returns: 
308
309
310 <!-- ##### FUNCTION g_open ##### -->
311 <para>
312
313 </para>
314
315 @filename: 
316 @flags: 
317 @mode: 
318 @Returns: 
319
320
321 <!-- ##### FUNCTION g_rename ##### -->
322 <para>
323
324 </para>
325
326 @oldfilename: 
327 @newfilename: 
328 @Returns: 
329
330
331 <!-- ##### FUNCTION g_mkdir ##### -->
332 <para>
333
334 </para>
335
336 @filename: 
337 @mode: 
338 @Returns: 
339
340
341 <!-- ##### FUNCTION g_stat ##### -->
342 <para>
343
344 </para>
345
346 @filename: 
347 @buf: 
348 @Returns: 
349
350
351 <!-- ##### FUNCTION g_lstat ##### -->
352 <para>
353
354 </para>
355
356 @filename: 
357 @buf: 
358 @Returns: 
359
360
361 <!-- ##### FUNCTION g_unlink ##### -->
362 <para>
363
364 </para>
365
366 @filename: 
367 @Returns: 
368
369
370 <!-- ##### FUNCTION g_remove ##### -->
371 <para>
372
373 </para>
374
375 @filename: 
376 @Returns: 
377
378
379 <!-- ##### FUNCTION g_rmdir ##### -->
380 <para>
381
382 </para>
383
384 @filename: 
385 @Returns: 
386
387
388 <!-- ##### FUNCTION g_fopen ##### -->
389 <para>
390
391 </para>
392
393 @filename: 
394 @mode: 
395 @Returns: 
396
397
398 <!-- ##### FUNCTION g_freopen ##### -->
399 <para>
400
401 </para>
402
403 @filename: 
404 @mode: 
405 @stream: 
406 @Returns: 
407
408
409 <!-- ##### FUNCTION g_chmod ##### -->
410 <para>
411
412 </para>
413
414 @filename: 
415 @mode: 
416 @Returns: 
417
418
419 <!-- ##### FUNCTION g_access ##### -->
420 <para>
421
422 </para>
423
424 @filename: 
425 @mode: 
426 @Returns: 
427
428
429 <!-- ##### FUNCTION g_creat ##### -->
430 <para>
431
432 </para>
433
434 @filename: 
435 @mode: 
436 @Returns: 
437
438
439 <!-- ##### FUNCTION g_chdir ##### -->
440 <para>
441
442 </para>
443
444 @path: 
445 @Returns: 
446
447