gfileutils.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* gfileutils.h - File utility functions
  2. *
  3. * Copyright 2000 Red Hat, Inc.
  4. *
  5. * GLib is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU Lesser General Public License as
  7. * published by the Free Software Foundation; either version 2 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * GLib is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with GLib; see the file COPYING.LIB. If not,
  17. * see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __G_FILEUTILS_H__
  20. #define __G_FILEUTILS_H__
  21. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  22. #error "Only <glib.h> can be included directly."
  23. #endif
  24. #include <glib/gerror.h>
  25. G_BEGIN_DECLS
  26. #define G_FILE_ERROR g_file_error_quark ()
  27. typedef enum
  28. {
  29. G_FILE_ERROR_EXIST,
  30. G_FILE_ERROR_ISDIR,
  31. G_FILE_ERROR_ACCES,
  32. G_FILE_ERROR_NAMETOOLONG,
  33. G_FILE_ERROR_NOENT,
  34. G_FILE_ERROR_NOTDIR,
  35. G_FILE_ERROR_NXIO,
  36. G_FILE_ERROR_NODEV,
  37. G_FILE_ERROR_ROFS,
  38. G_FILE_ERROR_TXTBSY,
  39. G_FILE_ERROR_FAULT,
  40. G_FILE_ERROR_LOOP,
  41. G_FILE_ERROR_NOSPC,
  42. G_FILE_ERROR_NOMEM,
  43. G_FILE_ERROR_MFILE,
  44. G_FILE_ERROR_NFILE,
  45. G_FILE_ERROR_BADF,
  46. G_FILE_ERROR_INVAL,
  47. G_FILE_ERROR_PIPE,
  48. G_FILE_ERROR_AGAIN,
  49. G_FILE_ERROR_INTR,
  50. G_FILE_ERROR_IO,
  51. G_FILE_ERROR_PERM,
  52. G_FILE_ERROR_NOSYS,
  53. G_FILE_ERROR_FAILED
  54. } GFileError;
  55. /* For backward-compat reasons, these are synced to an old
  56. * anonymous enum in libgnome. But don't use that enum
  57. * in new code.
  58. */
  59. typedef enum
  60. {
  61. G_FILE_TEST_IS_REGULAR = 1 << 0,
  62. G_FILE_TEST_IS_SYMLINK = 1 << 1,
  63. G_FILE_TEST_IS_DIR = 1 << 2,
  64. G_FILE_TEST_IS_EXECUTABLE = 1 << 3,
  65. G_FILE_TEST_EXISTS = 1 << 4
  66. } GFileTest;
  67. GLIB_AVAILABLE_IN_ALL
  68. GQuark g_file_error_quark (void);
  69. /* So other code can generate a GFileError */
  70. GLIB_AVAILABLE_IN_ALL
  71. GFileError g_file_error_from_errno (gint err_no);
  72. GLIB_AVAILABLE_IN_ALL
  73. gboolean g_file_test (const gchar *filename,
  74. GFileTest test);
  75. GLIB_AVAILABLE_IN_ALL
  76. gboolean g_file_get_contents (const gchar *filename,
  77. gchar **contents,
  78. gsize *length,
  79. GError **error);
  80. GLIB_AVAILABLE_IN_ALL
  81. gboolean g_file_set_contents (const gchar *filename,
  82. const gchar *contents,
  83. gssize length,
  84. GError **error);
  85. GLIB_AVAILABLE_IN_ALL
  86. gchar *g_file_read_link (const gchar *filename,
  87. GError **error);
  88. /* Wrapper / workalike for mkdtemp() */
  89. GLIB_AVAILABLE_IN_2_30
  90. gchar *g_mkdtemp (gchar *tmpl);
  91. GLIB_AVAILABLE_IN_2_30
  92. gchar *g_mkdtemp_full (gchar *tmpl,
  93. gint mode);
  94. /* Wrapper / workalike for mkstemp() */
  95. GLIB_AVAILABLE_IN_ALL
  96. gint g_mkstemp (gchar *tmpl);
  97. GLIB_AVAILABLE_IN_ALL
  98. gint g_mkstemp_full (gchar *tmpl,
  99. gint flags,
  100. gint mode);
  101. /* Wrappers for g_mkstemp and g_mkdtemp() */
  102. GLIB_AVAILABLE_IN_ALL
  103. gint g_file_open_tmp (const gchar *tmpl,
  104. gchar **name_used,
  105. GError **error);
  106. GLIB_AVAILABLE_IN_2_30
  107. gchar *g_dir_make_tmp (const gchar *tmpl,
  108. GError **error);
  109. GLIB_AVAILABLE_IN_ALL
  110. gchar *g_build_path (const gchar *separator,
  111. const gchar *first_element,
  112. ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
  113. GLIB_AVAILABLE_IN_ALL
  114. gchar *g_build_pathv (const gchar *separator,
  115. gchar **args) G_GNUC_MALLOC;
  116. GLIB_AVAILABLE_IN_ALL
  117. gchar *g_build_filename (const gchar *first_element,
  118. ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
  119. GLIB_AVAILABLE_IN_ALL
  120. gchar *g_build_filenamev (gchar **args) G_GNUC_MALLOC;
  121. GLIB_AVAILABLE_IN_ALL
  122. gint g_mkdir_with_parents (const gchar *pathname,
  123. gint mode);
  124. #ifdef G_OS_WIN32
  125. /* On Win32, the canonical directory separator is the backslash, and
  126. * the search path separator is the semicolon. Note that also the
  127. * (forward) slash works as directory separator.
  128. */
  129. #define G_DIR_SEPARATOR '\\'
  130. #define G_DIR_SEPARATOR_S "\\"
  131. #define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/')
  132. #define G_SEARCHPATH_SEPARATOR ';'
  133. #define G_SEARCHPATH_SEPARATOR_S ";"
  134. #else /* !G_OS_WIN32 */
  135. #define G_DIR_SEPARATOR '/'
  136. #define G_DIR_SEPARATOR_S "/"
  137. #define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR)
  138. #define G_SEARCHPATH_SEPARATOR ':'
  139. #define G_SEARCHPATH_SEPARATOR_S ":"
  140. #endif /* !G_OS_WIN32 */
  141. GLIB_AVAILABLE_IN_ALL
  142. gboolean g_path_is_absolute (const gchar *file_name);
  143. GLIB_AVAILABLE_IN_ALL
  144. const gchar *g_path_skip_root (const gchar *file_name);
  145. GLIB_DEPRECATED_FOR(g_path_get_basename)
  146. const gchar *g_basename (const gchar *file_name);
  147. #ifndef G_DISABLE_DEPRECATED
  148. #define g_dirname g_path_get_dirname
  149. #endif
  150. GLIB_AVAILABLE_IN_ALL
  151. gchar *g_get_current_dir (void);
  152. GLIB_AVAILABLE_IN_ALL
  153. gchar *g_path_get_basename (const gchar *file_name) G_GNUC_MALLOC;
  154. GLIB_AVAILABLE_IN_ALL
  155. gchar *g_path_get_dirname (const gchar *file_name) G_GNUC_MALLOC;
  156. #ifdef G_OS_WIN32
  157. #define g_file_test g_file_test_utf8
  158. #define g_file_get_contents g_file_get_contents_utf8
  159. #define g_mkstemp g_mkstemp_utf8
  160. #define g_file_open_tmp g_file_open_tmp_utf8
  161. #define g_get_current_dir g_get_current_dir_utf8
  162. GLIB_AVAILABLE_IN_ALL
  163. gboolean g_file_test_utf8 (const gchar *filename,
  164. GFileTest test);
  165. GLIB_AVAILABLE_IN_ALL
  166. gboolean g_file_get_contents_utf8 (const gchar *filename,
  167. gchar **contents,
  168. gsize *length,
  169. GError **error);
  170. GLIB_AVAILABLE_IN_ALL
  171. gint g_mkstemp_utf8 (gchar *tmpl);
  172. GLIB_AVAILABLE_IN_ALL
  173. gint g_file_open_tmp_utf8 (const gchar *tmpl,
  174. gchar **name_used,
  175. GError **error);
  176. GLIB_AVAILABLE_IN_ALL
  177. gchar *g_get_current_dir_utf8 (void);
  178. #endif /* G_OS_WIN32 */
  179. G_END_DECLS
  180. #endif /* __G_FILEUTILS_H__ */