gstdio.h 4.7 KB

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