gstdio.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* gstdio.h - GFilename wrappers for C library functions
  2. *
  3. * Copyright 2004 Tor Lillqvist
  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_STDIO_H__
  19. #define __G_STDIO_H__
  20. #include <glib/gprintf.h>
  21. #include <sys/stat.h>
  22. G_BEGIN_DECLS
  23. #if (defined (__MINGW64_VERSION_MAJOR) || defined (_MSC_VER)) && !defined(_WIN64)
  24. /* Make it clear that we mean the struct with 32-bit st_size and
  25. * 32-bit st_*time fields as that is how the 32-bit GLib DLL normally
  26. * has been compiled. If you get a compiler warning when calling
  27. * g_stat(), do take it seriously and make sure that the type of
  28. * struct stat the code in GLib fills in matches the struct the type
  29. * of struct stat you pass to g_stat(). To avoid hassle, to get file
  30. * attributes just use the GIO API instead which doesn't use struct
  31. * stat.
  32. *
  33. * Sure, it would be nicer to use a struct with 64-bit st_size and
  34. * 64-bit st_*time fields, but changing that now would break ABI. And
  35. * in MinGW, a plain "struct stat" is the one with 32-bit st_size and
  36. * st_*time fields.
  37. */
  38. typedef struct _stat32 GStatBuf;
  39. #elif defined(__MINGW64_VERSION_MAJOR) && defined(_WIN64)
  40. typedef struct _stat64 GStatBuf;
  41. #else
  42. typedef struct stat GStatBuf;
  43. #endif
  44. #if defined(G_OS_UNIX) && !defined(G_STDIO_WRAP_ON_UNIX)
  45. /* Just pass on to the system functions, so there's no potential for data
  46. * format mismatches, especially with large file interfaces.
  47. * A few functions can't be handled in this way, since they are not defined
  48. * in a portable system header that we could include here.
  49. *
  50. * #G_STDIO_WRAP_ON_UNIX is not public API and its behaviour is not guaranteed
  51. * in future.
  52. */
  53. #ifndef __GTK_DOC_IGNORE__
  54. #define g_chmod chmod
  55. #define g_open open
  56. #define g_creat creat
  57. #define g_rename rename
  58. #define g_mkdir mkdir
  59. #define g_stat stat
  60. #define g_lstat lstat
  61. #define g_remove remove
  62. #define g_fopen fopen
  63. #define g_freopen freopen
  64. #define g_utime utime
  65. #endif
  66. GLIB_AVAILABLE_IN_ALL
  67. int g_access (const gchar *filename,
  68. int mode);
  69. GLIB_AVAILABLE_IN_ALL
  70. int g_chdir (const gchar *path);
  71. GLIB_AVAILABLE_IN_ALL
  72. int g_unlink (const gchar *filename);
  73. GLIB_AVAILABLE_IN_ALL
  74. int g_rmdir (const gchar *filename);
  75. #else /* ! G_OS_UNIX */
  76. /* Wrappers for C library functions that take pathname arguments. On
  77. * Unix, the pathname is a file name as it literally is in the file
  78. * system. On well-maintained systems with consistent users who know
  79. * what they are doing and no exchange of files with others this would
  80. * be a well-defined encoding, preferably UTF-8. On Windows, the
  81. * pathname is always in UTF-8, even if that is not the on-disk
  82. * encoding, and not the encoding accepted by the C library or Win32
  83. * API.
  84. */
  85. GLIB_AVAILABLE_IN_ALL
  86. int g_access (const gchar *filename,
  87. int mode);
  88. GLIB_AVAILABLE_IN_ALL
  89. int g_chmod (const gchar *filename,
  90. int mode);
  91. GLIB_AVAILABLE_IN_ALL
  92. int g_open (const gchar *filename,
  93. int flags,
  94. int mode);
  95. GLIB_AVAILABLE_IN_ALL
  96. int g_creat (const gchar *filename,
  97. int mode);
  98. GLIB_AVAILABLE_IN_ALL
  99. int g_rename (const gchar *oldfilename,
  100. const gchar *newfilename);
  101. GLIB_AVAILABLE_IN_ALL
  102. int g_mkdir (const gchar *filename,
  103. int mode);
  104. GLIB_AVAILABLE_IN_ALL
  105. int g_chdir (const gchar *path);
  106. GLIB_AVAILABLE_IN_ALL
  107. int g_stat (const gchar *filename,
  108. GStatBuf *buf);
  109. GLIB_AVAILABLE_IN_ALL
  110. int g_lstat (const gchar *filename,
  111. GStatBuf *buf);
  112. GLIB_AVAILABLE_IN_ALL
  113. int g_unlink (const gchar *filename);
  114. GLIB_AVAILABLE_IN_ALL
  115. int g_remove (const gchar *filename);
  116. GLIB_AVAILABLE_IN_ALL
  117. int g_rmdir (const gchar *filename);
  118. GLIB_AVAILABLE_IN_ALL
  119. FILE *g_fopen (const gchar *filename,
  120. const gchar *mode);
  121. GLIB_AVAILABLE_IN_ALL
  122. FILE *g_freopen (const gchar *filename,
  123. const gchar *mode,
  124. FILE *stream);
  125. struct utimbuf; /* Don't need the real definition of struct utimbuf when just
  126. * including this header.
  127. */
  128. GLIB_AVAILABLE_IN_ALL
  129. int g_utime (const gchar *filename,
  130. struct utimbuf *utb);
  131. #endif /* G_OS_UNIX */
  132. GLIB_AVAILABLE_IN_2_36
  133. gboolean g_close (gint fd,
  134. GError **error);
  135. G_END_DECLS
  136. #endif /* __G_STDIO_H__ */