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

source code of gtk/subprojects/glib/glib/gstdio.h