Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
gstdio.h
Go to the documentation of this file.
1/* gstdio.h - GFilename wrappers for C library functions
2 *
3 * Copyright 2004 Tor Lillqvist
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef __G_STDIO_H__
22#define __G_STDIO_H__
23
24#include <glib/gprintf.h>
25
26#include <errno.h>
27#include <sys/stat.h>
28
30
31#if (defined (__MINGW64_VERSION_MAJOR) || defined (_MSC_VER)) && !defined(_WIN64)
32
33/* Make it clear that we mean the struct with 32-bit st_size and
34 * 32-bit st_*time fields as that is how the 32-bit GLib DLL normally
35 * has been compiled. If you get a compiler warning when calling
36 * g_stat(), do take it seriously and make sure that the type of
37 * struct stat the code in GLib fills in matches the struct the type
38 * of struct stat you pass to g_stat(). To avoid hassle, to get file
39 * attributes just use the GIO API instead which doesn't use struct
40 * stat.
41 *
42 * Sure, it would be nicer to use a struct with 64-bit st_size and
43 * 64-bit st_*time fields, but changing that now would break ABI. And
44 * in MinGW, a plain "struct stat" is the one with 32-bit st_size and
45 * st_*time fields.
46 */
47
48typedef struct _stat32 GStatBuf;
49
50#elif defined(__MINGW64_VERSION_MAJOR) && defined(_WIN64)
51
52typedef struct _stat64 GStatBuf;
53
54#else
55
56typedef struct stat GStatBuf;
57
58#endif
59
60#if defined(G_OS_UNIX) && !defined(G_STDIO_WRAP_ON_UNIX) && !defined(__GI_SCANNER__)
61
62/* Just pass on to the system functions, so there's no potential for data
63 * format mismatches, especially with large file interfaces.
64 * A few functions can't be handled in this way, since they are not defined
65 * in a portable system header that we could include here.
66 *
67 * G_STDIO_WRAP_ON_UNIX is not public API and its behaviour is not guaranteed
68 * in future.
69 */
70
71#ifndef __GTK_DOC_IGNORE__
72#define g_chmod chmod
73#define g_open open
74#define g_creat creat
75#define g_rename rename
76#define g_mkdir mkdir
77#define g_stat stat
78#define g_lstat lstat
79#define g_remove remove
80#define g_fopen fopen
81#define g_freopen freopen
82#define g_fsync fsync
83#define g_utime utime
84#endif
85
87int g_access (const gchar *filename,
88 int mode);
89
91int g_chdir (const gchar *path);
92
94int g_unlink (const gchar *filename);
95
97int g_rmdir (const gchar *filename);
98
99#else /* ! G_OS_UNIX */
100
101/* Wrappers for C library functions that take pathname arguments. On
102 * Unix, the pathname is a file name as it literally is in the file
103 * system. On well-maintained systems with consistent users who know
104 * what they are doing and no exchange of files with others this would
105 * be a well-defined encoding, preferably UTF-8. On Windows, the
106 * pathname is always in UTF-8, even if that is not the on-disk
107 * encoding, and not the encoding accepted by the C library or Win32
108 * API.
109 */
110
112int g_access (const gchar *filename,
113 int mode);
114
116int g_chmod (const gchar *filename,
117 int mode);
118
120int g_open (const gchar *filename,
121 int flags,
122 int mode);
123
125int g_creat (const gchar *filename,
126 int mode);
127
129int g_rename (const gchar *oldfilename,
130 const gchar *newfilename);
131
133int g_mkdir (const gchar *filename,
134 int mode);
135
137int g_chdir (const gchar *path);
138
140int g_stat (const gchar *filename,
141 GStatBuf *buf);
142
144int g_lstat (const gchar *filename,
145 GStatBuf *buf);
146
148int g_unlink (const gchar *filename);
149
151int g_remove (const gchar *filename);
152
154int g_rmdir (const gchar *filename);
155
157FILE *g_fopen (const gchar *filename,
158 const gchar *mode);
159
161FILE *g_freopen (const gchar *filename,
162 const gchar *mode,
163 FILE *stream);
164
166gint g_fsync (gint fd);
167
168struct utimbuf; /* Don't need the real definition of struct utimbuf when just
169 * including this header.
170 */
171
173int g_utime (const gchar *filename,
174 struct utimbuf *utb);
175
176#endif /* G_OS_UNIX */
177
180 GError **error);
181
183static inline gboolean
184g_clear_fd (int *fd_ptr,
185 GError **error)
186{
187 int fd = *fd_ptr;
188
189 *fd_ptr = -1;
190
191 if (fd < 0)
192 return TRUE;
193
194 /* Suppress "Not available before" warning */
196 return g_close (fd, error);
198}
199
200/* g_autofd should be defined on the same compilers where g_autofree is
201 * This avoids duplicating the feature-detection here. */
202#ifdef g_autofree
203#ifndef __GTK_DOC_IGNORE__
204/* Not public API */
205static inline void
206_g_clear_fd_ignore_error (int *fd_ptr)
207{
208 /* Don't overwrite thread-local errno if closing the fd fails */
209 int errsv = errno;
210
211 /* Suppress "Not available before" warning */
213
214 if (!g_clear_fd (fd_ptr, NULL))
215 {
216 /* Do nothing: we ignore all errors, except for EBADF which
217 * is a programming error, checked for by g_close(). */
218 }
219
221
222 errno = errsv;
223}
224#endif
225
226#define g_autofd _GLIB_CLEANUP(_g_clear_fd_ignore_error) GLIB_AVAILABLE_MACRO_IN_2_76
227#endif
228
230
231#endif /* __G_STDIO_H__ */
#define GLIB_AVAILABLE_IN_2_36
#define GLIB_AVAILABLE_IN_ALL
#define GLIB_AVAILABLE_IN_2_64
#define GLIB_AVAILABLE_STATIC_INLINE_IN_2_76
#define NULL
Definition gmacros.h:924
#define G_END_DECLS
Definition gmacros.h:910
#define G_BEGIN_DECLS
Definition gmacros.h:909
#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS
Definition gmacros.h:771
#define TRUE
Definition gmacros.h:933
#define G_GNUC_END_IGNORE_DEPRECATIONS
Definition gmacros.h:772
#define g_creat
Definition gstdio.h:74
#define g_lstat
Definition gstdio.h:78
GLIB_AVAILABLE_IN_ALL int g_unlink(const gchar *filename)
#define g_freopen
Definition gstdio.h:81
#define g_fopen
Definition gstdio.h:80
#define g_stat
Definition gstdio.h:77
GLIB_AVAILABLE_IN_2_36 gboolean g_close(gint fd, GError **error)
#define g_mkdir
Definition gstdio.h:76
GLIB_AVAILABLE_IN_ALL int g_rmdir(const gchar *filename)
#define g_rename
Definition gstdio.h:75
typedefG_BEGIN_DECLS struct stat GStatBuf
Definition gstdio.h:56
static GLIB_AVAILABLE_STATIC_INLINE_IN_2_76 gboolean g_clear_fd(int *fd_ptr, GError **error)
Definition gstdio.h:184
#define g_fsync
Definition gstdio.h:82
#define g_utime
Definition gstdio.h:83
GLIB_AVAILABLE_IN_ALL int g_access(const gchar *filename, int mode)
#define g_remove
Definition gstdio.h:79
#define g_chmod
Definition gstdio.h:72
#define g_open
Definition gstdio.h:73
GLIB_AVAILABLE_IN_ALL int g_chdir(const gchar *path)
gint gboolean
Definition gtypes.h:56
G_BEGIN_DECLS typedef char gchar
Definition gtypes.h:52
int gint
Definition gtypes.h:55
static void error(LoadState *S, const char *why)