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