b99430ba2b8f11b0fa126829e7071574193e50bf
[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 <!-- ##### SECTION Image ##### -->
45
46
47 <!-- ##### ENUM GFileError ##### -->
48 <para>
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
55 of that manual.
56 </para>
57
58 <para>
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.
63 </para>
64
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
84      mapping.
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
90   memory.)
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
93   links.
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
100      limit.
101 @G_FILE_ERROR_NFILE: There are too many distinct file openings in the
102      entire system.
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
108      library function.
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
114      blocked `SIGPIPE'.
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
122     is returning errors.
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
131   code applies.
132
133 <!-- ##### MACRO G_FILE_ERROR ##### -->
134 <para>
135 Error domain for file operations. Errors in this domain will
136 be from the #GFileError enumeration. See #GError for information on 
137 error domains.
138 </para>
139
140
141
142 <!-- ##### ENUM GFileTest ##### -->
143 <para>
144 A test to perform on a file using g_file_test().
145 </para>
146
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
149     to a regular file.
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.
155
156 <!-- ##### FUNCTION g_file_error_from_errno ##### -->
157 <para>
158
159 </para>
160
161 @err_no: 
162 @Returns: 
163
164
165 <!-- ##### FUNCTION g_file_get_contents ##### -->
166 <para>
167
168 </para>
169
170 @filename: 
171 @contents: 
172 @length: 
173 @error: 
174 @Returns: 
175
176
177 <!-- ##### FUNCTION g_file_set_contents ##### -->
178 <para>
179
180 </para>
181
182 @filename: 
183 @contents: 
184 @length: 
185 @error: 
186 @Returns: 
187
188
189 <!-- ##### FUNCTION g_file_test ##### -->
190 <para>
191
192 </para>
193
194 @filename: 
195 @test: 
196 @Returns: 
197
198
199 <!-- ##### FUNCTION g_mkstemp ##### -->
200 <para>
201
202 </para>
203
204 @tmpl: 
205 @Returns: 
206
207
208 <!-- ##### FUNCTION g_mkstemp_full ##### -->
209 <para>
210
211 </para>
212
213 @tmpl: 
214 @flags: 
215 @mode: 
216 @Returns: 
217
218
219 <!-- ##### FUNCTION g_file_open_tmp ##### -->
220 <para>
221
222 </para>
223
224 @tmpl: 
225 @name_used: 
226 @error: 
227 @Returns: 
228
229
230 <!-- ##### FUNCTION g_file_read_link ##### -->
231 <para>
232
233 </para>
234
235 @filename: 
236 @error: 
237 @Returns: 
238
239
240 <!-- ##### FUNCTION g_mkdir_with_parents ##### -->
241 <para>
242
243 </para>
244
245 @pathname: 
246 @mode: 
247 @Returns: 
248
249
250 <!-- ##### STRUCT GDir ##### -->
251 <para>
252 An opaque structure representing an opened directory.
253 </para>
254
255
256 <!-- ##### FUNCTION g_dir_open ##### -->
257 <para>
258
259 </para>
260
261 @path: 
262 @flags: 
263 @error: 
264 @Returns: 
265
266
267 <!-- ##### FUNCTION g_dir_read_name ##### -->
268 <para>
269
270 </para>
271
272 @dir: 
273 @Returns: 
274
275
276 <!-- ##### FUNCTION g_dir_rewind ##### -->
277 <para>
278
279 </para>
280
281 @dir: 
282
283
284 <!-- ##### FUNCTION g_dir_close ##### -->
285 <para>
286
287 </para>
288
289 @dir: 
290
291
292 <!-- ##### STRUCT GMappedFile ##### -->
293 <para>
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.
297 </para>
298
299
300 <!-- ##### FUNCTION g_mapped_file_new ##### -->
301 <para>
302
303 </para>
304
305 @filename: 
306 @writable: 
307 @error: 
308 @Returns: 
309
310
311 <!-- ##### FUNCTION g_mapped_file_ref ##### -->
312 <para>
313
314 </para>
315
316 @file: 
317 @Returns: 
318
319
320 <!-- ##### FUNCTION g_mapped_file_unref ##### -->
321 <para>
322
323 </para>
324
325 @file: 
326
327
328 <!-- ##### FUNCTION g_mapped_file_free ##### -->
329 <para>
330
331 </para>
332
333 @file: 
334
335
336 <!-- ##### FUNCTION g_mapped_file_get_length ##### -->
337 <para>
338
339 </para>
340
341 @file: 
342 @Returns: 
343
344
345 <!-- ##### FUNCTION g_mapped_file_get_contents ##### -->
346 <para>
347
348 </para>
349
350 @file: 
351 @Returns: 
352
353
354 <!-- ##### FUNCTION g_open ##### -->
355 <para>
356
357 </para>
358
359 @filename: 
360 @flags: 
361 @mode: 
362 @Returns: 
363
364
365 <!-- ##### FUNCTION g_rename ##### -->
366 <para>
367
368 </para>
369
370 @oldfilename: 
371 @newfilename: 
372 @Returns: 
373
374
375 <!-- ##### FUNCTION g_mkdir ##### -->
376 <para>
377
378 </para>
379
380 @filename: 
381 @mode: 
382 @Returns: 
383
384
385 <!-- ##### FUNCTION g_stat ##### -->
386 <para>
387
388 </para>
389
390 @filename: 
391 @buf: 
392 @Returns: 
393
394
395 <!-- ##### FUNCTION g_lstat ##### -->
396 <para>
397
398 </para>
399
400 @filename: 
401 @buf: 
402 @Returns: 
403
404
405 <!-- ##### FUNCTION g_unlink ##### -->
406 <para>
407
408 </para>
409
410 @filename: 
411 @Returns: 
412
413
414 <!-- ##### FUNCTION g_remove ##### -->
415 <para>
416
417 </para>
418
419 @filename: 
420 @Returns: 
421
422
423 <!-- ##### FUNCTION g_rmdir ##### -->
424 <para>
425
426 </para>
427
428 @filename: 
429 @Returns: 
430
431
432 <!-- ##### FUNCTION g_fopen ##### -->
433 <para>
434
435 </para>
436
437 @filename: 
438 @mode: 
439 @Returns: 
440
441
442 <!-- ##### FUNCTION g_freopen ##### -->
443 <para>
444
445 </para>
446
447 @filename: 
448 @mode: 
449 @stream: 
450 @Returns: 
451
452
453 <!-- ##### FUNCTION g_chmod ##### -->
454 <para>
455
456 </para>
457
458 @filename: 
459 @mode: 
460 @Returns: 
461
462
463 <!-- ##### FUNCTION g_access ##### -->
464 <para>
465
466 </para>
467
468 @filename: 
469 @mode: 
470 @Returns: 
471
472
473 <!-- ##### FUNCTION g_creat ##### -->
474 <para>
475
476 </para>
477
478 @filename: 
479 @mode: 
480 @Returns: 
481
482
483 <!-- ##### FUNCTION g_chdir ##### -->
484 <para>
485
486 </para>
487
488 @path: 
489 @Returns: 
490
491
492 <!-- ##### FUNCTION g_utime ##### -->
493 <para>
494
495 </para>
496
497 @filename: 
498 @utb: 
499 @Returns: 
500
501