817aeb62293e0812868ad0e43e861ed89d1f61b1
[platform/upstream/glib2.0.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 directory).
145     Note that this test will also return %TRUE if the tested file is a symlink
146     to a regular file.
147 @G_FILE_TEST_IS_SYMLINK: %TRUE if the file is a symlink.
148 @G_FILE_TEST_IS_DIR: %TRUE if the file is a directory.
149 @G_FILE_TEST_IS_EXECUTABLE: %TRUE if the file is executable.
150 @G_FILE_TEST_EXISTS: %TRUE if the file exists. 
151     It may or may not be a regular file.
152
153 <!-- ##### FUNCTION g_file_error_from_errno ##### -->
154 <para>
155
156 </para>
157
158 @err_no: 
159 @Returns: 
160
161
162 <!-- ##### FUNCTION g_file_get_contents ##### -->
163 <para>
164
165 </para>
166
167 @filename: 
168 @contents: 
169 @length: 
170 @error: 
171 @Returns: 
172
173
174 <!-- ##### FUNCTION g_file_set_contents ##### -->
175 <para>
176
177 </para>
178
179 @filename: 
180 @contents: 
181 @length: 
182 @error: 
183 @Returns: 
184
185
186 <!-- ##### FUNCTION g_file_test ##### -->
187 <para>
188
189 </para>
190
191 @filename: 
192 @test: 
193 @Returns: 
194
195
196 <!-- ##### FUNCTION g_mkstemp ##### -->
197 <para>
198
199 </para>
200
201 @tmpl: 
202 @Returns: 
203
204
205 <!-- ##### FUNCTION g_mkstemp_full ##### -->
206 <para>
207
208 </para>
209
210 @tmpl: 
211 @flags: 
212 @mode: 
213 @Returns: 
214
215
216 <!-- ##### FUNCTION g_file_open_tmp ##### -->
217 <para>
218
219 </para>
220
221 @tmpl: 
222 @name_used: 
223 @error: 
224 @Returns: 
225
226
227 <!-- ##### FUNCTION g_file_read_link ##### -->
228 <para>
229
230 </para>
231
232 @filename: 
233 @error: 
234 @Returns: 
235
236
237 <!-- ##### FUNCTION g_mkdir_with_parents ##### -->
238 <para>
239
240 </para>
241
242 @pathname: 
243 @mode: 
244 @Returns: 
245
246
247 <!-- ##### STRUCT GDir ##### -->
248 <para>
249 An opaque structure representing an opened directory.
250 </para>
251
252
253 <!-- ##### FUNCTION g_dir_open ##### -->
254 <para>
255
256 </para>
257
258 @path: 
259 @flags: 
260 @error: 
261 @Returns: 
262
263
264 <!-- ##### FUNCTION g_dir_read_name ##### -->
265 <para>
266
267 </para>
268
269 @dir: 
270 @Returns: 
271
272
273 <!-- ##### FUNCTION g_dir_rewind ##### -->
274 <para>
275
276 </para>
277
278 @dir: 
279
280
281 <!-- ##### FUNCTION g_dir_close ##### -->
282 <para>
283
284 </para>
285
286 @dir: 
287
288
289 <!-- ##### STRUCT GMappedFile ##### -->
290 <para>
291 The #GMappedFile represents a file mapping created with
292 g_mapped_file_new(). It has only private members and should
293 not be accessed directly.
294 </para>
295
296
297 <!-- ##### FUNCTION g_mapped_file_new ##### -->
298 <para>
299
300 </para>
301
302 @filename: 
303 @writable: 
304 @error: 
305 @Returns: 
306
307
308 <!-- ##### FUNCTION g_mapped_file_ref ##### -->
309 <para>
310
311 </para>
312
313 @file: 
314 @Returns: 
315
316
317 <!-- ##### FUNCTION g_mapped_file_unref ##### -->
318 <para>
319
320 </para>
321
322 @file: 
323
324
325 <!-- ##### FUNCTION g_mapped_file_free ##### -->
326 <para>
327
328 </para>
329
330 @file: 
331
332
333 <!-- ##### FUNCTION g_mapped_file_get_length ##### -->
334 <para>
335
336 </para>
337
338 @file: 
339 @Returns: 
340
341
342 <!-- ##### FUNCTION g_mapped_file_get_contents ##### -->
343 <para>
344
345 </para>
346
347 @file: 
348 @Returns: 
349
350
351 <!-- ##### FUNCTION g_open ##### -->
352 <para>
353
354 </para>
355
356 @filename: 
357 @flags: 
358 @mode: 
359 @Returns: 
360
361
362 <!-- ##### FUNCTION g_rename ##### -->
363 <para>
364
365 </para>
366
367 @oldfilename: 
368 @newfilename: 
369 @Returns: 
370
371
372 <!-- ##### FUNCTION g_mkdir ##### -->
373 <para>
374
375 </para>
376
377 @filename: 
378 @mode: 
379 @Returns: 
380
381
382 <!-- ##### FUNCTION g_stat ##### -->
383 <para>
384
385 </para>
386
387 @filename: 
388 @buf: 
389 @Returns: 
390
391
392 <!-- ##### FUNCTION g_lstat ##### -->
393 <para>
394
395 </para>
396
397 @filename: 
398 @buf: 
399 @Returns: 
400
401
402 <!-- ##### FUNCTION g_unlink ##### -->
403 <para>
404
405 </para>
406
407 @filename: 
408 @Returns: 
409
410
411 <!-- ##### FUNCTION g_remove ##### -->
412 <para>
413
414 </para>
415
416 @filename: 
417 @Returns: 
418
419
420 <!-- ##### FUNCTION g_rmdir ##### -->
421 <para>
422
423 </para>
424
425 @filename: 
426 @Returns: 
427
428
429 <!-- ##### FUNCTION g_fopen ##### -->
430 <para>
431
432 </para>
433
434 @filename: 
435 @mode: 
436 @Returns: 
437
438
439 <!-- ##### FUNCTION g_freopen ##### -->
440 <para>
441
442 </para>
443
444 @filename: 
445 @mode: 
446 @stream: 
447 @Returns: 
448
449
450 <!-- ##### FUNCTION g_chmod ##### -->
451 <para>
452
453 </para>
454
455 @filename: 
456 @mode: 
457 @Returns: 
458
459
460 <!-- ##### FUNCTION g_access ##### -->
461 <para>
462
463 </para>
464
465 @filename: 
466 @mode: 
467 @Returns: 
468
469
470 <!-- ##### FUNCTION g_creat ##### -->
471 <para>
472
473 </para>
474
475 @filename: 
476 @mode: 
477 @Returns: 
478
479
480 <!-- ##### FUNCTION g_chdir ##### -->
481 <para>
482
483 </para>
484
485 @path: 
486 @Returns: 
487
488
489 <!-- ##### FUNCTION g_utime ##### -->
490 <para>
491
492 </para>
493
494 @filename: 
495 @utb: 
496 @Returns: 
497
498