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_file_open_tmp ##### --> 206 <para> 207 208 </para> 209 210 @tmpl: 211 @name_used: 212 @error: 213 @Returns: 214 215 216 <!-- ##### FUNCTION g_file_read_link ##### --> 217 <para> 218 219 </para> 220 221 @filename: 222 @error: 223 @Returns: 224 225 226 <!-- ##### FUNCTION g_mkdir_with_parents ##### --> 227 <para> 228 229 </para> 230 231 @pathname: 232 @mode: 233 @Returns: 234 235 236 <!-- ##### STRUCT GDir ##### --> 237 <para> 238 An opaque structure representing an opened directory. 239 </para> 240 241 242 <!-- ##### FUNCTION g_dir_open ##### --> 243 <para> 244 245 </para> 246 247 @path: 248 @flags: 249 @error: 250 @Returns: 251 252 253 <!-- ##### FUNCTION g_dir_read_name ##### --> 254 <para> 255 256 </para> 257 258 @dir: 259 @Returns: 260 261 262 <!-- ##### FUNCTION g_dir_rewind ##### --> 263 <para> 264 265 </para> 266 267 @dir: 268 269 270 <!-- ##### FUNCTION g_dir_close ##### --> 271 <para> 272 273 </para> 274 275 @dir: 276 277 278 <!-- ##### STRUCT GMappedFile ##### --> 279 <para> 280 The #GMappedFile represents a file mapping created with 281 g_mapped_file_new(). It has only private members and should 282 not be accessed directly. 283 </para> 284 285 286 <!-- ##### FUNCTION g_mapped_file_new ##### --> 287 <para> 288 289 </para> 290 291 @filename: 292 @writable: 293 @error: 294 @Returns: 295 296 297 <!-- ##### FUNCTION g_mapped_file_free ##### --> 298 <para> 299 300 </para> 301 302 @file: 303 304 305 <!-- ##### FUNCTION g_mapped_file_get_length ##### --> 306 <para> 307 308 </para> 309 310 @file: 311 @Returns: 312 313 314 <!-- ##### FUNCTION g_mapped_file_get_contents ##### --> 315 <para> 316 317 </para> 318 319 @file: 320 @Returns: 321 322 323 <!-- ##### FUNCTION g_open ##### --> 324 <para> 325 326 </para> 327 328 @filename: 329 @flags: 330 @mode: 331 @Returns: 332 333 334 <!-- ##### FUNCTION g_rename ##### --> 335 <para> 336 337 </para> 338 339 @oldfilename: 340 @newfilename: 341 @Returns: 342 343 344 <!-- ##### FUNCTION g_mkdir ##### --> 345 <para> 346 347 </para> 348 349 @filename: 350 @mode: 351 @Returns: 352 353 354 <!-- ##### FUNCTION g_stat ##### --> 355 <para> 356 357 </para> 358 359 @filename: 360 @buf: 361 @Returns: 362 363 364 <!-- ##### FUNCTION g_lstat ##### --> 365 <para> 366 367 </para> 368 369 @filename: 370 @buf: 371 @Returns: 372 373 374 <!-- ##### FUNCTION g_unlink ##### --> 375 <para> 376 377 </para> 378 379 @filename: 380 @Returns: 381 382 383 <!-- ##### FUNCTION g_remove ##### --> 384 <para> 385 386 </para> 387 388 @filename: 389 @Returns: 390 391 392 <!-- ##### FUNCTION g_rmdir ##### --> 393 <para> 394 395 </para> 396 397 @filename: 398 @Returns: 399 400 401 <!-- ##### FUNCTION g_fopen ##### --> 402 <para> 403 404 </para> 405 406 @filename: 407 @mode: 408 @Returns: 409 410 411 <!-- ##### FUNCTION g_freopen ##### --> 412 <para> 413 414 </para> 415 416 @filename: 417 @mode: 418 @stream: 419 @Returns: 420 421 422 <!-- ##### FUNCTION g_chmod ##### --> 423 <para> 424 425 </para> 426 427 @filename: 428 @mode: 429 @Returns: 430 431 432 <!-- ##### FUNCTION g_access ##### --> 433 <para> 434 435 </para> 436 437 @filename: 438 @mode: 439 @Returns: 440 441 442 <!-- ##### FUNCTION g_creat ##### --> 443 <para> 444 445 </para> 446 447 @filename: 448 @mode: 449 @Returns: 450 451 452 <!-- ##### FUNCTION g_chdir ##### --> 453 <para> 454 455 </para> 456 457 @path: 458 @Returns: 459 460 461 <!-- ##### FUNCTION g_utime ##### --> 462 <para> 463 464 </para> 465 466 @filename: 467 @utb: 468 @Returns: 469 470 471