gfileutils.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* gfileutils.h - File utility functions
  2. *
  3. * Copyright 2000 Red Hat, Inc.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library 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 License
  16. * along with this library; if not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __G_FILEUTILS_H__
  19. #define __G_FILEUTILS_H__
  20. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  21. #error "Only <glib.h> can be included directly."
  22. #endif
  23. #include <glibconfig.h>
  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_2_56
  122. gchar *g_build_filename_valist (const gchar *first_element,
  123. va_list *args) G_GNUC_MALLOC;
  124. GLIB_AVAILABLE_IN_ALL
  125. gint g_mkdir_with_parents (const gchar *pathname,
  126. gint mode);
  127. #ifdef G_OS_WIN32
  128. /* On Win32, the canonical directory separator is the backslash, and
  129. * the search path separator is the semicolon. Note that also the
  130. * (forward) slash works as directory separator.
  131. */
  132. #define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/')
  133. #else /* !G_OS_WIN32 */
  134. #define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR)
  135. #endif /* !G_OS_WIN32 */
  136. GLIB_AVAILABLE_IN_ALL
  137. gboolean g_path_is_absolute (const gchar *file_name);
  138. GLIB_AVAILABLE_IN_ALL
  139. const gchar *g_path_skip_root (const gchar *file_name);
  140. GLIB_DEPRECATED_FOR(g_path_get_basename)
  141. const gchar *g_basename (const gchar *file_name);
  142. #define g_dirname g_path_get_dirname GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_path_get_dirname)
  143. GLIB_AVAILABLE_IN_ALL
  144. gchar *g_get_current_dir (void);
  145. GLIB_AVAILABLE_IN_ALL
  146. gchar *g_path_get_basename (const gchar *file_name) G_GNUC_MALLOC;
  147. GLIB_AVAILABLE_IN_ALL
  148. gchar *g_path_get_dirname (const gchar *file_name) G_GNUC_MALLOC;
  149. GLIB_AVAILABLE_IN_2_58
  150. gchar *g_canonicalize_filename (const gchar *filename,
  151. const gchar *relative_to) G_GNUC_MALLOC;
  152. G_END_DECLS
  153. #endif /* __G_FILEUTILS_H__ */