/src/wrappers/glib/library/utilities/glib_file_utilities.e

http://github.com/tybor/Liberty · Specman e · 895 lines · 2 code · 246 blank · 647 comment · 0 complexity · d4a8fcfb8c03b58fd3c3d4a507b39b3a MD5 · raw file

  1. deferred class GLIB_FILE_UTILITIES
  2. -- File Utilities
  3. -- File Utilities -- various file-related functions.
  4. -- Synopsis
  5. -- #include <glib.h>
  6. -- #include <glib/gstdio.h>
  7. -- enum GFileError;
  8. -- #define G_FILE_ERROR
  9. -- enum GFileTest;
  10. -- GFileError g_file_error_from_errno (gint err_no);
  11. -- gboolean g_file_get_contents (const gchar *filename,
  12. -- gchar **contents,
  13. -- gsize *length,
  14. -- GError **error);
  15. -- gboolean g_file_set_contents (const gchar *filename,
  16. -- const gchar *contents,
  17. -- gssize length,
  18. -- GError **error);
  19. -- gboolean g_file_test (const gchar *filename,
  20. -- GFileTest test);
  21. -- gint g_mkstemp (gchar *tmpl);
  22. -- gint g_file_open_tmp (const gchar *tmpl,
  23. -- gchar **name_used,
  24. -- GError **error);
  25. -- gchar* g_file_read_link (const gchar *filename,
  26. -- GError **error);
  27. -- int g_mkdir_with_parents (const gchar *pathname,
  28. -- int mode);
  29. -- GDir;
  30. -- GDir* g_dir_open (const gchar *path,
  31. -- guint flags,
  32. -- GError **error);
  33. -- const gchar* g_dir_read_name (GDir *dir);
  34. -- void g_dir_rewind (GDir *dir);
  35. -- void g_dir_close (GDir *dir);
  36. -- GMappedFile;
  37. -- GMappedFile* g_mapped_file_new (const gchar *filename,
  38. -- gboolean writable,
  39. -- GError **error);
  40. -- void g_mapped_file_free (GMappedFile *file);
  41. -- gsize g_mapped_file_get_length (GMappedFile *file);
  42. -- gchar* g_mapped_file_get_contents (GMappedFile *file);
  43. -- int g_open (const gchar *filename,
  44. -- int flags,
  45. -- int mode);
  46. -- int g_rename (const gchar *oldfilename,
  47. -- const gchar *newfilename);
  48. -- int g_mkdir (const gchar *filename,
  49. -- int mode);
  50. -- int g_stat (const gchar *filename,
  51. -- struct stat *buf);
  52. -- int g_lstat (const gchar *filename,
  53. -- struct stat *buf);
  54. -- int g_unlink (const gchar *filename);
  55. -- int g_remove (const gchar *filename);
  56. -- int g_rmdir (const gchar *filename);
  57. -- FILE* g_fopen (const gchar *filename,
  58. -- const gchar *mode);
  59. -- FILE* g_freopen (const gchar *filename,
  60. -- const gchar *mode,
  61. -- FILE *stream);
  62. -- int g_chmod (const gchar *filename,
  63. -- int mode);
  64. -- int g_access (const gchar *filename,
  65. -- int mode);
  66. -- int g_creat (const gchar *filename,
  67. -- int mode);
  68. -- int g_chdir (const gchar *path);
  69. -- Description
  70. -- There is a group of functions which wrap the common POSIX functions dealing with
  71. -- filenames (g_open(), g_rename(), g_mkdir(), g_stat(), g_unlink(), g_remove(),
  72. -- g_fopen(), g_freopen()). The point of these wrappers is to make it possible to
  73. -- handle file names with any Unicode characters in them on Windows without having
  74. -- to use ifdefs and the wide character API in the application code.
  75. -- The pathname argument should be in the GLib file name encoding. On POSIX this is
  76. -- the actual on-disk encoding which might correspond to the locale settings of the
  77. -- process (or the G_FILENAME_ENCODING environment variable), or not.
  78. -- On Windows the GLib file name encoding is UTF-8. Note that the Microsoft C
  79. -- library does not use UTF-8, but has separate APIs for current system code page
  80. -- and wide characters (UTF-16). The GLib wrappers call the wide character API if
  81. -- present (on modern Windows systems), otherwise convert to/from the system code
  82. -- page.
  83. -- Another group of functions allows to open and read directories in the GLib file
  84. -- name encoding. These are g_dir_open(), g_dir_read_name(), g_dir_rewind(),
  85. -- g_dir_close().
  86. -- Details
  87. -- enum GFileError
  88. -- typedef enum
  89. -- {
  90. -- G_FILE_ERROR_EXIST,
  91. -- G_FILE_ERROR_ISDIR,
  92. -- G_FILE_ERROR_ACCES,
  93. -- G_FILE_ERROR_NAMETOOLONG,
  94. -- G_FILE_ERROR_NOENT,
  95. -- G_FILE_ERROR_NOTDIR,
  96. -- G_FILE_ERROR_NXIO,
  97. -- G_FILE_ERROR_NODEV,
  98. -- G_FILE_ERROR_ROFS,
  99. -- G_FILE_ERROR_TXTBSY,
  100. -- G_FILE_ERROR_FAULT,
  101. -- G_FILE_ERROR_LOOP,
  102. -- G_FILE_ERROR_NOSPC,
  103. -- G_FILE_ERROR_NOMEM,
  104. -- G_FILE_ERROR_MFILE,
  105. -- G_FILE_ERROR_NFILE,
  106. -- G_FILE_ERROR_BADF,
  107. -- G_FILE_ERROR_INVAL,
  108. -- G_FILE_ERROR_PIPE,
  109. -- G_FILE_ERROR_AGAIN,
  110. -- G_FILE_ERROR_INTR,
  111. -- G_FILE_ERROR_IO,
  112. -- G_FILE_ERROR_PERM,
  113. -- G_FILE_ERROR_NOSYS,
  114. -- G_FILE_ERROR_FAILED
  115. -- } GFileError;
  116. -- Values corresponding to errno codes returned from file operations on UNIX. Unlike
  117. -- errno codes, GFileError values are available on all systems, even Windows. The
  118. -- exact meaning of each code depends on what sort of file operation you were
  119. -- performing; the UNIX documentation gives more details. The following error code
  120. -- descriptions come from the GNU C Library manual, and are under the copyright of
  121. -- that manual.
  122. -- It's not very portable to make detailed assumptions about exactly which errors
  123. -- will be returned from a given operation. Some errors don't occur on some systems,
  124. -- etc., sometimes there are subtle differences in when a system will report a given
  125. -- error, etc.
  126. -- G_FILE_ERROR_EXIST Operation not permitted; only the owner of the file (or
  127. -- other resource) or processes with special privileges can
  128. -- perform the operation.
  129. -- G_FILE_ERROR_ISDIR File is a directory; you cannot open a directory for
  130. -- writing, or create or remove hard links to it.
  131. -- G_FILE_ERROR_ACCES Permission denied; the file permissions do not allow the
  132. -- attempted operation.
  133. -- G_FILE_ERROR_NAMETOOLONG Filename too long.
  134. -- G_FILE_ERROR_NOENT No such file or directory. This is a "file doesn't
  135. -- exist" error for ordinary files that are referenced in
  136. -- contexts where they are expected to already exist.
  137. -- G_FILE_ERROR_NOTDIR A file that isn't a directory was specified when a
  138. -- directory is required.
  139. -- G_FILE_ERROR_NXIO No such device or address. The system tried to use the
  140. -- device represented by a file you specified, and it
  141. -- couldn't find the device. This can mean that the device
  142. -- file was installed incorrectly, or that the physical
  143. -- device is missing or not correctly attached to the
  144. -- computer.
  145. -- G_FILE_ERROR_NODEV This file is of a type that doesn't support mapping.
  146. -- G_FILE_ERROR_ROFS The directory containing the new link can't be modified
  147. -- because it's on a read-only file system.
  148. -- G_FILE_ERROR_TXTBSY Text file busy.
  149. -- G_FILE_ERROR_FAULT You passed in a pointer to bad memory. (GLib won't
  150. -- reliably return this, don't pass in pointers to bad
  151. -- memory.)
  152. -- G_FILE_ERROR_LOOP Too many levels of symbolic links were encountered in
  153. -- looking up a file name. This often indicates a cycle of
  154. -- symbolic links.
  155. -- G_FILE_ERROR_NOSPC No space left on device; write operation on a file
  156. -- failed because the disk is full.
  157. -- G_FILE_ERROR_NOMEM No memory available. The system cannot allocate more
  158. -- virtual memory because its capacity is full.
  159. -- G_FILE_ERROR_MFILE The current process has too many files open and can't
  160. -- open any more. Duplicate descriptors do count toward
  161. -- this limit.
  162. -- G_FILE_ERROR_NFILE There are too many distinct file openings in the entire
  163. -- system.
  164. -- G_FILE_ERROR_BADF Bad file descriptor; for example, I/O on a descriptor
  165. -- that has been closed or reading from a descriptor open
  166. -- only for writing (or vice versa).
  167. -- G_FILE_ERROR_INVAL Invalid argument. This is used to indicate various kinds
  168. -- of problems with passing the wrong argument to a library
  169. -- function.
  170. -- G_FILE_ERROR_PIPE Broken pipe; there is no process reading from the other
  171. -- end of a pipe. Every library function that returns this
  172. -- error code also generates a `SIGPIPE' signal; this
  173. -- signal terminates the program if not handled or blocked.
  174. -- Thus, your program will never actually see this code
  175. -- unless it has handled or blocked `SIGPIPE'.
  176. -- G_FILE_ERROR_AGAIN Resource temporarily unavailable; the call might work if
  177. -- you try again later.
  178. -- G_FILE_ERROR_INTR Interrupted function call; an asynchronous signal
  179. -- occurred and prevented completion of the call. When this
  180. -- happens, you should try the call again.
  181. -- G_FILE_ERROR_IO Input/output error; usually used for physical read or
  182. -- write errors. i.e. the disk or other physical device
  183. -- hardware is returning errors.
  184. -- G_FILE_ERROR_PERM Operation not permitted; only the owner of the file (or
  185. -- other resource) or processes with special privileges can
  186. -- perform the operation.
  187. -- G_FILE_ERROR_NOSYS Function not implemented; this indicates that the system
  188. -- is missing some functionality.
  189. -- G_FILE_ERROR_FAILED Does not correspond to a UNIX error code; this is the
  190. -- standard "failed for unspecified reason" error code
  191. -- present in all GError error code enumerations. Returned
  192. -- if no specific code applies.
  193. -- ---------------------------------------------------------------------------------
  194. -- G_FILE_ERROR
  195. -- #define G_FILE_ERROR g_file_error_quark ()
  196. -- Error domain for file operations. Errors in this domain will be from the
  197. -- GFileError enumeration. See GError for information on error domains.
  198. -- ---------------------------------------------------------------------------------
  199. -- enum GFileTest
  200. -- typedef enum
  201. -- {
  202. -- G_FILE_TEST_IS_REGULAR = 1 < < 0,
  203. -- G_FILE_TEST_IS_SYMLINK = 1 < < 1,
  204. -- G_FILE_TEST_IS_DIR = 1 < < 2,
  205. -- G_FILE_TEST_IS_EXECUTABLE = 1 < < 3,
  206. -- G_FILE_TEST_EXISTS = 1 < < 4
  207. -- } GFileTest;
  208. -- A test to perform on a file using g_file_test().
  209. -- G_FILE_TEST_IS_REGULAR TRUE if the file is a regular file (not a symlink or
  210. -- directory)
  211. -- G_FILE_TEST_IS_SYMLINK TRUE if the file is a symlink.
  212. -- G_FILE_TEST_IS_DIR TRUE if the file is a directory.
  213. -- G_FILE_TEST_IS_EXECUTABLE TRUE if the file is executable.
  214. -- G_FILE_TEST_EXISTS TRUE if the file exists. It may or may not be a regular
  215. -- file.
  216. -- ---------------------------------------------------------------------------------
  217. -- g_file_error_from_errno ()
  218. -- GFileError g_file_error_from_errno (gint err_no);
  219. -- Gets a GFileError constant based on the passed-in errno. For example, if you pass
  220. -- in EEXIST this function returns G_FILE_ERROR_EXIST. Unlike errno values, you can
  221. -- portably assume that all GFileError values will exist.
  222. -- Normally a GFileError value goes into a GError returned from a function that
  223. -- manipulates files. So you would use g_file_error_from_errno() when constructing a
  224. -- GError.
  225. -- err_no : an "errno" value
  226. -- Returns : GFileError corresponding to the given errno
  227. -- ---------------------------------------------------------------------------------
  228. -- g_file_get_contents ()
  229. -- gboolean g_file_get_contents (const gchar *filename,
  230. -- gchar **contents,
  231. -- gsize *length,
  232. -- GError **error);
  233. -- Reads an entire file into allocated memory, with good error checking.
  234. -- If the call was successful, it returns TRUE and sets contents to the file
  235. -- contents and length to the length of the file contents in bytes. The string
  236. -- stored in contents will be nul-terminated, so for text files you can pass NULL
  237. -- for the length argument. If the call was not successful, it returns FALSE and
  238. -- sets error. The error domain is G_FILE_ERROR. Possible error codes are those in
  239. -- the GFileError enumeration. In the error case, contents is set to NULL and length
  240. -- is set to zero.
  241. -- filename : name of a file to read contents from, in the GLib file name encoding
  242. -- contents : location to store an allocated string
  243. -- length : location to store length in bytes of the contents, or NULL
  244. -- error : return location for a GError, or NULL
  245. -- Returns : TRUE on success, FALSE if an error occurred
  246. -- ---------------------------------------------------------------------------------
  247. -- g_file_set_contents ()
  248. -- gboolean g_file_set_contents (const gchar *filename,
  249. -- const gchar *contents,
  250. -- gssize length,
  251. -- GError **error);
  252. -- Writes all of contents to a file named filename, with good error checking. If a
  253. -- file called filename already exists it will be overwritten.
  254. -- This write is atomic in the sense that it is first written to a temporary file
  255. -- which is then renamed to the final name. Notes:
  256. -- o On Unix, if filename already exists hard links to filename will break. Also
  257. -- since the file is recreated, existing permissions, access control lists,
  258. -- metadata etc. may be lost. If filename is a symbolic link, the link itself
  259. -- will be replaced, not the linked file.
  260. -- o On Windows renaming a file will not remove an existing file with the new
  261. -- name, so on Windows there is a race condition between the existing file being
  262. -- removed and the temporary file being renamed.
  263. -- o On Windows there is no way to remove a file that is open to some process, or
  264. -- mapped into memory. Thus, this function will fail if filename already exists
  265. -- and is open.
  266. -- If the call was sucessful, it returns TRUE. If the call was not successful, it
  267. -- returns FALSE and sets error. The error domain is G_FILE_ERROR. Possible error
  268. -- codes are those in the GFileError enumeration.
  269. -- filename : name of a file to write contents to, in the GLib file name encoding
  270. -- contents : string to write to the file
  271. -- length : length of contents, or -1 if contents is a nul-terminated string
  272. -- error : return location for a GError, or NULL
  273. -- Returns : TRUE on success, FALSE if an error occurred
  274. -- Since 2.8
  275. -- ---------------------------------------------------------------------------------
  276. -- g_file_test ()
  277. -- gboolean g_file_test (const gchar *filename,
  278. -- GFileTest test);
  279. -- Returns TRUE if any of the tests in the bitfield test are TRUE. For example,
  280. -- (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) will return TRUE if the file exists;
  281. -- the check whether it's a directory doesn't matter since the existence test is
  282. -- TRUE. With the current set of available tests, there's no point passing in more
  283. -- than one test at a time.
  284. -- Apart from G_FILE_TEST_IS_SYMLINK all tests follow symbolic links, so for a
  285. -- symbolic link to a regular file g_file_test() will return TRUE for both
  286. -- G_FILE_TEST_IS_SYMLINK and G_FILE_TEST_IS_REGULAR.
  287. -- Note, that for a dangling symbolic link g_file_test() will return TRUE for
  288. -- G_FILE_TEST_IS_SYMLINK and FALSE for all other flags.
  289. -- You should never use g_file_test() to test whether it is safe to perform an
  290. -- operation, because there is always the possibility of the condition changing
  291. -- before you actually perform the operation. For example, you might think you could
  292. -- use G_FILE_TEST_IS_SYMLINK to know whether it is is safe to write to a file
  293. -- without being tricked into writing into a different location. It doesn't work!
  294. -- /* DON'T DO THIS */
  295. -- if (!g_file_test (filename, G_FILE_TEST_IS_SYMLINK)) {
  296. -- fd = g_open (filename, O_WRONLY);
  297. -- /* write to fd */
  298. -- }
  299. -- Another thing to note is that G_FILE_TEST_EXISTS and G_FILE_TEST_IS_EXECUTABLE
  300. -- are implemented using the access() system call. This usually doesn't matter, but
  301. -- if your program is setuid or setgid it means that these tests will give you the
  302. -- answer for the real user ID and group ID, rather than the effective user ID and
  303. -- group ID.
  304. -- On Windows, there are no symlinks, so testing for G_FILE_TEST_IS_SYMLINK will
  305. -- always return FALSE. Testing for G_FILE_TEST_IS_EXECUTABLE will just check that
  306. -- the file exists and its name indicates that it is executable, checking for
  307. -- well-known extensions and those listed in the PATHEXT environment variable.
  308. -- filename : a filename to test in the GLib file name encoding
  309. -- test : bitfield of GFileTest flags
  310. -- Returns : whether a test was TRUE
  311. -- ---------------------------------------------------------------------------------
  312. -- g_mkstemp ()
  313. -- gint g_mkstemp (gchar *tmpl);
  314. -- Opens a temporary file. See the mkstemp() documentation on most UNIX-like
  315. -- systems.
  316. -- The parameter is a string that should follow the rules for mkstemp() templates,
  317. -- i.e. contain the string "XXXXXX". g_mkstemp() is slightly more flexible than
  318. -- mkstemp() in that the sequence does not have to occur at the very end of the
  319. -- template. The X string will be modified to form the name of a file that didn't
  320. -- exist. The string should be in the GLib file name encoding. Most importantly, on
  321. -- Windows it should be in UTF-8.
  322. -- tmpl : template filename
  323. -- Returns : A file handle (as from open()) to the file opened for reading and
  324. -- writing. The file is opened in binary mode on platforms where there is
  325. -- a difference. The file handle should be closed with close(). In case of
  326. -- errors, -1 is returned.
  327. -- ---------------------------------------------------------------------------------
  328. -- g_file_open_tmp ()
  329. -- gint g_file_open_tmp (const gchar *tmpl,
  330. -- gchar **name_used,
  331. -- GError **error);
  332. -- Opens a file for writing in the preferred directory for temporary files (as
  333. -- returned by g_get_tmp_dir()).
  334. -- tmpl should be a string in the GLib file name encoding containing a sequence of
  335. -- six 'X' characters, as the parameter to g_mkstemp(). However, unlike these
  336. -- functions, the template should only be a basename, no directory components are
  337. -- allowed. If template is NULL, a default template is used.
  338. -- Note that in contrast to g_mkstemp() (and mkstemp()) tmpl is not modified, and
  339. -- might thus be a read-only literal string.
  340. -- The actual name used is returned in name_used if non-NULL. This string should be
  341. -- freed with g_free() when not needed any longer. The returned name is in the GLib
  342. -- file name encoding.
  343. -- tmpl : Template for file name, as in g_mkstemp(), basename only, or NULL, to
  344. -- a default template
  345. -- name_used : location to store actual name used
  346. -- error : return location for a GError
  347. -- Returns : A file handle (as from open()) to the file opened for reading and
  348. -- writing. The file is opened in binary mode on platforms where there
  349. -- is a difference. The file handle should be closed with close(). In
  350. -- case of errors, -1 is returned and error will be set.
  351. -- ---------------------------------------------------------------------------------
  352. -- g_file_read_link ()
  353. -- gchar* g_file_read_link (const gchar *filename,
  354. -- GError **error);
  355. -- Reads the contents of the symbolic link filename like the POSIX readlink()
  356. -- function. The returned string is in the encoding used for filenames. Use
  357. -- g_filename_to_utf8() to convert it to UTF-8.
  358. -- filename : the symbolic link
  359. -- error : return location for a GError
  360. -- Returns : A newly allocated string with the contents of the symbolic link, or
  361. -- NULL if an error occurred.
  362. -- Since 2.4
  363. -- ---------------------------------------------------------------------------------
  364. -- g_mkdir_with_parents ()
  365. -- int g_mkdir_with_parents (const gchar *pathname,
  366. -- int mode);
  367. -- Create a directory if it doesn't already exist. Create intermediate parent
  368. -- directories as needed, too.
  369. -- pathname : a pathname in the GLib file name encoding
  370. -- mode : permissions to use for newly created directories
  371. -- Returns : 0 if the directory already exists, or was successfully created.
  372. -- Returns -1 if an error occurred, with errno set.
  373. -- Since 2.8
  374. -- ---------------------------------------------------------------------------------
  375. -- GDir
  376. -- typedef struct _GDir GDir;
  377. -- An opaque structure representing an opened directory.
  378. -- ---------------------------------------------------------------------------------
  379. -- g_dir_open ()
  380. -- GDir* g_dir_open (const gchar *path,
  381. -- guint flags,
  382. -- GError **error);
  383. -- Opens a directory for reading. The names of the files in the directory can then
  384. -- be retrieved using g_dir_read_name().
  385. -- path : the path to the directory you are interested in. On Unix in the on-disk
  386. -- encoding. On Windows in UTF-8
  387. -- flags : Currently must be set to 0. Reserved for future use.
  388. -- error : return location for a GError, or NULL. If non-NULL, an error will be
  389. -- set if and only if g_dir_open() fails.
  390. -- Returns : a newly allocated GDir on success, NULL on failure. If non-NULL, you
  391. -- must free the result with g_dir_close() when you are finished with it.
  392. -- ---------------------------------------------------------------------------------
  393. -- g_dir_read_name ()
  394. -- const gchar* g_dir_read_name (GDir *dir);
  395. -- Retrieves the name of the next entry in the directory. The '.' and '..' entries
  396. -- are omitted. On Windows, the returned name is in UTF-8. On Unix, it is in the
  397. -- on-disk encoding.
  398. -- dir : a GDir* created by g_dir_open()
  399. -- Returns : The entry's name or NULL if there are no more entries. The return value
  400. -- is owned by GLib and must not be modified or freed.
  401. -- ---------------------------------------------------------------------------------
  402. -- g_dir_rewind ()
  403. -- void g_dir_rewind (GDir *dir);
  404. -- Resets the given directory. The next call to g_dir_read_name() will return the
  405. -- first entry again.
  406. -- dir : a GDir* created by g_dir_open()
  407. -- ---------------------------------------------------------------------------------
  408. -- g_dir_close ()
  409. -- void g_dir_close (GDir *dir);
  410. -- Closes the directory and deallocates all related resources.
  411. -- dir : a GDir* created by g_dir_open()
  412. -- ---------------------------------------------------------------------------------
  413. -- GMappedFile
  414. -- typedef struct _GMappedFile GMappedFile;
  415. -- The GMappedFile represents a file mapping created with g_mapped_file_new(). It
  416. -- has only private members and should not be accessed directly.
  417. -- ---------------------------------------------------------------------------------
  418. -- g_mapped_file_new ()
  419. -- GMappedFile* g_mapped_file_new (const gchar *filename,
  420. -- gboolean writable,
  421. -- GError **error);
  422. -- Maps a file into memory. On UNIX, this is using the mmap() function.
  423. -- If writable is TRUE, the mapped buffer may be modified, otherwise it is an error
  424. -- to modify the mapped buffer. Modifications to the buffer are not visible to other
  425. -- processes mapping the same file, and are not written back to the file.
  426. -- Note that modifications of the underlying file might affect the contents of the
  427. -- GMappedFile. Therefore, mapping should only be used if the file will not be
  428. -- modified, or if all modifications of the file are done atomically (e.g. using
  429. -- g_file_set_contents()).
  430. -- filename : The path of the file to load, in the GLib filename encoding
  431. -- writable : wether the mapping should be writable
  432. -- error : return location for a GError, or NULL
  433. -- Returns : a newly allocated GMappedFile which must be freed with
  434. -- g_mapped_file_free(), or NULL if the mapping failed.
  435. -- Since 2.8
  436. -- ---------------------------------------------------------------------------------
  437. -- g_mapped_file_free ()
  438. -- void g_mapped_file_free (GMappedFile *file);
  439. -- Unmaps the buffer of file and frees it.
  440. -- file : a GMappedFile
  441. -- Since 2.8
  442. -- ---------------------------------------------------------------------------------
  443. -- g_mapped_file_get_length ()
  444. -- gsize g_mapped_file_get_length (GMappedFile *file);
  445. -- Returns the length of the contents of a GMappedFile.
  446. -- file : a GMappedFile
  447. -- Returns : the length of the contents of file.
  448. -- Since 2.8
  449. -- ---------------------------------------------------------------------------------
  450. -- g_mapped_file_get_contents ()
  451. -- gchar* g_mapped_file_get_contents (GMappedFile *file);
  452. -- Returns the contents of a GMappedFile.
  453. -- Note that the contents may not be zero-terminated, even if the GMappedFile is
  454. -- backed by a text file.
  455. -- file : a GMappedFile
  456. -- Returns : the contents of file.
  457. -- Since 2.8
  458. -- ---------------------------------------------------------------------------------
  459. -- g_open ()
  460. -- int g_open (const gchar *filename,
  461. -- int flags,
  462. -- int mode);
  463. -- A wrapper for the POSIX open() function. The open() function is used to convert a
  464. -- pathname into a file descriptor. Note that on POSIX systems file descriptors are
  465. -- implemented by the operating system. On Windows, it's the C library that
  466. -- implements open() and file descriptors. The actual Windows API for opening files
  467. -- is something different.
  468. -- See the C library manual for more details about open().
  469. -- filename : a pathname in the GLib file name encoding (UTF-8 on Windows)
  470. -- flags : as in open()
  471. -- mode : as in open()
  472. -- Returns : a new file descriptor, or -1 if an error occurred. The return value
  473. -- can be used exactly like the return value from open().
  474. -- Since 2.6
  475. -- ---------------------------------------------------------------------------------
  476. -- g_rename ()
  477. -- int g_rename (const gchar *oldfilename,
  478. -- const gchar *newfilename);
  479. -- A wrapper for the POSIX rename() function. The rename() function renames a file,
  480. -- moving it between directories if required.
  481. -- See your C library manual for more details about how rename() works on your
  482. -- system. Note in particular that on Win9x it is not possible to rename a file if a
  483. -- file with the new name already exists. Also it is not possible in general on
  484. -- Windows to rename an open file.
  485. -- oldfilename : a pathname in the GLib file name encoding (UTF-8 on Windows)
  486. -- newfilename : a pathname in the GLib file name encoding
  487. -- Returns : 0 if the renaming succeeded, -1 if an error occurred
  488. -- Since 2.6
  489. -- ---------------------------------------------------------------------------------
  490. -- g_mkdir ()
  491. -- int g_mkdir (const gchar *filename,
  492. -- int mode);
  493. -- A wrapper for the POSIX mkdir() function. The mkdir() function attempts to create
  494. -- a directory with the given name and permissions.
  495. -- See the C library manual for more details about mkdir().
  496. -- filename : a pathname in the GLib file name encoding (UTF-8 on Windows)
  497. -- mode : permissions to use for the newly created directory
  498. -- Returns : 0 if the directory was successfully created, -1 if an error occurred
  499. -- Since 2.6
  500. -- ---------------------------------------------------------------------------------
  501. -- g_stat ()
  502. -- int g_stat (const gchar *filename,
  503. -- struct stat *buf);
  504. -- A wrapper for the POSIX stat() function. The stat() function returns information
  505. -- about a file.
  506. -- See the C library manual for more details about stat().
  507. -- filename : a pathname in the GLib file name encoding (UTF-8 on Windows)
  508. -- buf : a pointer to a stat struct, which will be filled with the file
  509. -- information
  510. -- Returns : 0 if the information was successfully retrieved, -1 if an error
  511. -- occurred
  512. -- Since 2.6
  513. -- ---------------------------------------------------------------------------------
  514. -- g_lstat ()
  515. -- int g_lstat (const gchar *filename,
  516. -- struct stat *buf);
  517. -- A wrapper for the POSIX lstat() function. The lstat() function is like stat()
  518. -- except that in the case of symbolic links, it returns information about the
  519. -- symbolic link itself and not the file that it refers to. If the system does not
  520. -- support symbolic links g_lstat() is identical to g_stat().
  521. -- See the C library manual for more details about lstat().
  522. -- filename : a pathname in the GLib file name encoding (UTF-8 on Windows)
  523. -- buf : a pointer to a stat struct, which will be filled with the file
  524. -- information
  525. -- Returns : 0 if the information was successfully retrieved, -1 if an error
  526. -- occurred
  527. -- Since 2.6
  528. -- ---------------------------------------------------------------------------------
  529. -- g_unlink ()
  530. -- int g_unlink (const gchar *filename);
  531. -- A wrapper for the POSIX unlink() function. The unlink() function deletes a name
  532. -- from the filesystem. If this was the last link to the file and no processes have
  533. -- it opened, the diskspace occupied by the file is freed.
  534. -- See your C library manual for more details about unlink(). Note that on Windows,
  535. -- it is in general not possible to delete files that are open to some process, or
  536. -- mapped into memory.
  537. -- filename : a pathname in the GLib file name encoding (UTF-8 on Windows)
  538. -- Returns : 0 if the name was successfully deleted, -1 if an error occurred
  539. -- Since 2.6
  540. -- ---------------------------------------------------------------------------------
  541. -- g_remove ()
  542. -- int g_remove (const gchar *filename);
  543. -- A wrapper for the POSIX remove() function. The remove() function deletes a name
  544. -- from the filesystem.
  545. -- See your C library manual for more details about how remove() works on your
  546. -- system. On Unix, remove() removes also directories, as it calls unlink() for
  547. -- files and rmdir() for directories. On Windows, although remove() in the C library
  548. -- only works for files, this function tries first remove() and then if that fails
  549. -- rmdir(), and thus works for both files and directories. Note however, that on
  550. -- Windows, it is in general not possible to remove a file that is open to some
  551. -- process, or mapped into memory.
  552. -- If this function fails on Windows you can't infer too much from the errno value.
  553. -- rmdir() is tried regardless of what caused remove() to fail. Any errno value set
  554. -- by remove() will be overwritten by that set by rmdir().
  555. -- filename : a pathname in the GLib file name encoding (UTF-8 on Windows)
  556. -- Returns : 0 if the file was successfully removed, -1 if an error occurred
  557. -- Since 2.6
  558. -- ---------------------------------------------------------------------------------
  559. -- g_rmdir ()
  560. -- int g_rmdir (const gchar *filename);
  561. -- A wrapper for the POSIX rmdir() function. The rmdir() function deletes a
  562. -- directory from the filesystem.
  563. -- See your C library manual for more details about how rmdir() works on your
  564. -- system.
  565. -- filename : a pathname in the GLib file name encoding (UTF-8 on Windows)
  566. -- Returns : 0 if the directory was successfully removed, -1 if an error occurred
  567. -- Since 2.6
  568. -- ---------------------------------------------------------------------------------
  569. -- g_fopen ()
  570. -- FILE* g_fopen (const gchar *filename,
  571. -- const gchar *mode);
  572. -- A wrapper for the POSIX fopen() function. The fopen() function opens a file and
  573. -- associates a new stream with it.
  574. -- See the C library manual for more details about fopen().
  575. -- filename : a pathname in the GLib file name encoding (UTF-8 on Windows)
  576. -- mode : a string describing the mode in which the file should be opened
  577. -- Returns : A FILE pointer if the file was successfully opened, or NULL if an
  578. -- error occurred
  579. -- Since 2.6
  580. -- ---------------------------------------------------------------------------------
  581. -- g_freopen ()
  582. -- FILE* g_freopen (const gchar *filename,
  583. -- const gchar *mode,
  584. -- FILE *stream);
  585. -- A wrapper for the POSIX freopen() function. The freopen() function opens a file
  586. -- and associates it with an existing stream.
  587. -- See the C library manual for more details about freopen().
  588. -- filename : a pathname in the GLib file name encoding (UTF-8 on Windows)
  589. -- mode : a string describing the mode in which the file should be opened
  590. -- stream : an existing stream which will be reused, or NULL
  591. -- Returns : A FILE pointer if the file was successfully opened, or NULL if an
  592. -- error occurred.
  593. -- Since 2.6
  594. -- ---------------------------------------------------------------------------------
  595. -- g_chmod ()
  596. -- int g_chmod (const gchar *filename,
  597. -- int mode);
  598. -- A wrapper for the POSIX chmod() function. The chmod() function is used to set the
  599. -- permissions of a file system object. Note that on Windows the file protection
  600. -- mechanism is not at all POSIX-like, and the underlying chmod() function in the C
  601. -- library just sets or clears the READONLY attribute. It does not touch any ACL.
  602. -- Software that needs to manage file permissions on Windows exactly should use the
  603. -- Win32 API.
  604. -- See the C library manual for more details about chmod().
  605. -- filename : a pathname in the GLib file name encoding (UTF-8 on Windows)
  606. -- mode : as in chmod()
  607. -- Returns : zero if the operation succeeded, -1 on error.
  608. -- Since 2.8
  609. -- ---------------------------------------------------------------------------------
  610. -- g_access ()
  611. -- int g_access (const gchar *filename,
  612. -- int mode);
  613. -- A wrapper for the POSIX access() function. This function is used to test a
  614. -- pathname for one or several of read, write or execute permissions, or just
  615. -- existence. On Windows, the underlying access() function in the C library only
  616. -- checks the READONLY attribute, and does not look at the ACL at all. Software that
  617. -- needs to handle file permissions on Windows more exactly should use the Win32
  618. -- API.
  619. -- See the C library manual for more details about access().
  620. -- filename : a pathname in the GLib file name encoding (UTF-8 on Windows)
  621. -- mode : as in access()
  622. -- Returns : zero if the pathname refers to an existing file system object that has
  623. -- all the tested permissions, or -1 otherwise or on error.
  624. -- Since 2.8
  625. -- ---------------------------------------------------------------------------------
  626. -- g_creat ()
  627. -- int g_creat (const gchar *filename,
  628. -- int mode);
  629. -- A wrapper for the POSIX creat() function. The creat() function is used to convert
  630. -- a pathname into a file descriptor, creating a file if necessar. Note that on
  631. -- POSIX systems file descriptors are implemented by the operating system. On
  632. -- Windows, it's the C library that implements creat() and file descriptors. The
  633. -- actual Windows API for opening files is something different.
  634. -- See the C library manual for more details about creat().
  635. -- filename : a pathname in the GLib file name encoding (UTF-8 on Windows)
  636. -- mode : as in creat()
  637. -- Returns : a new file descriptor, or -1 if an error occurred. The return value
  638. -- can be used exactly like the return value from creat().
  639. -- Since 2.8
  640. -- ---------------------------------------------------------------------------------
  641. -- g_chdir ()
  642. -- int g_chdir (const gchar *path);
  643. -- A wrapper for the POSIX chdir() function. The function changes the current
  644. -- directory of the process to path.
  645. -- See your C library manual for more details about chdir().
  646. -- path : a pathname in the GLib file name encoding (UTF-8 on Windows)
  647. -- Returns : 0 on success, -1 if an error occurred.
  648. -- Since 2.8
  649. end -- class GLIB_FILE_UTILITIES