Merge branch 'g-clear-pointer-no-side-effects' into 'master'
[glib.git] / glib / gstdio.h
blob94f4fa36fa62e10e2ba61656c3105210d7682c30
1 /* gstdio.h - GFilename wrappers for C library functions
3 * Copyright 2004 Tor Lillqvist
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.
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.
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/>.
19 #ifndef __G_STDIO_H__
20 #define __G_STDIO_H__
22 #include <glib/gprintf.h>
24 #include <sys/stat.h>
26 G_BEGIN_DECLS
28 #if (defined (__MINGW64_VERSION_MAJOR) || defined (_MSC_VER)) && !defined(_WIN64)
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.
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.
45 typedef struct _stat32 GStatBuf;
47 #elif defined(__MINGW64_VERSION_MAJOR) && defined(_WIN64)
49 typedef struct _stat64 GStatBuf;
51 #else
53 typedef struct stat GStatBuf;
55 #endif
57 #if defined(G_OS_UNIX) && !defined(G_STDIO_NO_WRAP_ON_UNIX)
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.
65 #ifndef __GTK_DOC_IGNORE__
66 #define g_chmod chmod
67 #define g_open open
68 #define g_creat creat
69 #define g_rename rename
70 #define g_mkdir mkdir
71 #define g_stat stat
72 #define g_lstat lstat
73 #define g_remove remove
74 #define g_fopen fopen
75 #define g_freopen freopen
76 #define g_utime utime
77 #endif
79 GLIB_AVAILABLE_IN_ALL
80 int g_access (const gchar *filename,
81 int mode);
83 GLIB_AVAILABLE_IN_ALL
84 int g_chdir (const gchar *path);
86 GLIB_AVAILABLE_IN_ALL
87 int g_unlink (const gchar *filename);
89 GLIB_AVAILABLE_IN_ALL
90 int g_rmdir (const gchar *filename);
92 #else /* ! G_OS_UNIX */
94 /* Wrappers for C library functions that take pathname arguments. On
95 * Unix, the pathname is a file name as it literally is in the file
96 * system. On well-maintained systems with consistent users who know
97 * what they are doing and no exchange of files with others this would
98 * be a well-defined encoding, preferably UTF-8. On Windows, the
99 * pathname is always in UTF-8, even if that is not the on-disk
100 * encoding, and not the encoding accepted by the C library or Win32
101 * API.
104 GLIB_AVAILABLE_IN_ALL
105 int g_access (const gchar *filename,
106 int mode);
108 GLIB_AVAILABLE_IN_ALL
109 int g_chmod (const gchar *filename,
110 int mode);
112 GLIB_AVAILABLE_IN_ALL
113 int g_open (const gchar *filename,
114 int flags,
115 int mode);
117 GLIB_AVAILABLE_IN_ALL
118 int g_creat (const gchar *filename,
119 int mode);
121 GLIB_AVAILABLE_IN_ALL
122 int g_rename (const gchar *oldfilename,
123 const gchar *newfilename);
125 GLIB_AVAILABLE_IN_ALL
126 int g_mkdir (const gchar *filename,
127 int mode);
129 GLIB_AVAILABLE_IN_ALL
130 int g_chdir (const gchar *path);
132 GLIB_AVAILABLE_IN_ALL
133 int g_stat (const gchar *filename,
134 GStatBuf *buf);
136 GLIB_AVAILABLE_IN_ALL
137 int g_lstat (const gchar *filename,
138 GStatBuf *buf);
140 GLIB_AVAILABLE_IN_ALL
141 int g_unlink (const gchar *filename);
143 GLIB_AVAILABLE_IN_ALL
144 int g_remove (const gchar *filename);
146 GLIB_AVAILABLE_IN_ALL
147 int g_rmdir (const gchar *filename);
149 GLIB_AVAILABLE_IN_ALL
150 FILE *g_fopen (const gchar *filename,
151 const gchar *mode);
153 GLIB_AVAILABLE_IN_ALL
154 FILE *g_freopen (const gchar *filename,
155 const gchar *mode,
156 FILE *stream);
158 struct utimbuf; /* Don't need the real definition of struct utimbuf when just
159 * including this header.
162 GLIB_AVAILABLE_IN_ALL
163 int g_utime (const gchar *filename,
164 struct utimbuf *utb);
166 #endif /* G_OS_UNIX */
168 GLIB_AVAILABLE_IN_2_36
169 gboolean g_close (gint fd,
170 GError **error);
172 G_END_DECLS
174 #endif /* __G_STDIO_H__ */