Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:42:03

0001 /* gstdio.h - GFilename wrappers for C library functions
0002  *
0003  * Copyright 2004 Tor Lillqvist
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-or-later
0006  *
0007  * This library is free software; you can redistribute it and/or
0008  * modify it under the terms of the GNU Lesser General Public
0009  * License as published by the Free Software Foundation; either
0010  * version 2.1 of the License, or (at your option) any later version.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Lesser General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Lesser General Public License
0018  * along with this library; if not, see <http://www.gnu.org/licenses/>.
0019  */
0020 
0021 #ifndef __G_STDIO_H__
0022 #define __G_STDIO_H__
0023 
0024 #include <glib/gprintf.h>
0025 
0026 #include <errno.h>
0027 #include <sys/stat.h>
0028 
0029 G_BEGIN_DECLS
0030 
0031 #if (defined (__MINGW64_VERSION_MAJOR) || defined (_MSC_VER)) && !defined(_WIN64)
0032 
0033 /* Make it clear that we mean the struct with 32-bit st_size and
0034  * 32-bit st_*time fields as that is how the 32-bit GLib DLL normally
0035  * has been compiled. If you get a compiler warning when calling
0036  * g_stat(), do take it seriously and make sure that the type of
0037  * struct stat the code in GLib fills in matches the struct the type
0038  * of struct stat you pass to g_stat(). To avoid hassle, to get file
0039  * attributes just use the GIO API instead which doesn't use struct
0040  * stat.
0041  *
0042  * Sure, it would be nicer to use a struct with 64-bit st_size and
0043  * 64-bit st_*time fields, but changing that now would break ABI. And
0044  * in MinGW, a plain "struct stat" is the one with 32-bit st_size and
0045  * st_*time fields.
0046  */
0047 
0048 typedef struct _stat32 GStatBuf;
0049 
0050 #elif defined(__MINGW64_VERSION_MAJOR) && defined(_WIN64)
0051 
0052 typedef struct _stat64 GStatBuf;
0053 
0054 #else
0055 
0056 typedef struct stat GStatBuf;
0057 
0058 #endif
0059 
0060 #if defined(G_OS_UNIX) && !defined(G_STDIO_WRAP_ON_UNIX)
0061 
0062 /* Just pass on to the system functions, so there's no potential for data
0063  * format mismatches, especially with large file interfaces. 
0064  * A few functions can't be handled in this way, since they are not defined
0065  * in a portable system header that we could include here.
0066  *
0067  * G_STDIO_WRAP_ON_UNIX is not public API and its behaviour is not guaranteed
0068  * in future.
0069  */
0070 
0071 #ifndef __GTK_DOC_IGNORE__
0072 #define g_chmod   chmod
0073 #define g_open    open
0074 #define g_creat   creat
0075 #define g_rename  rename
0076 #define g_mkdir   mkdir
0077 #define g_stat    stat
0078 #define g_lstat   lstat
0079 #define g_remove  remove
0080 #define g_fopen   fopen
0081 #define g_freopen freopen
0082 #define g_fsync   fsync
0083 #define g_utime   utime
0084 #endif
0085 
0086 GLIB_AVAILABLE_IN_ALL
0087 int g_access (const gchar *filename,
0088           int          mode);
0089 
0090 GLIB_AVAILABLE_IN_ALL
0091 int g_chdir  (const gchar *path);
0092 
0093 GLIB_AVAILABLE_IN_ALL
0094 int g_unlink (const gchar *filename);
0095 
0096 GLIB_AVAILABLE_IN_ALL
0097 int g_rmdir  (const gchar *filename);
0098 
0099 #else /* ! G_OS_UNIX */
0100 
0101 /* Wrappers for C library functions that take pathname arguments. On
0102  * Unix, the pathname is a file name as it literally is in the file
0103  * system. On well-maintained systems with consistent users who know
0104  * what they are doing and no exchange of files with others this would
0105  * be a well-defined encoding, preferably UTF-8. On Windows, the
0106  * pathname is always in UTF-8, even if that is not the on-disk
0107  * encoding, and not the encoding accepted by the C library or Win32
0108  * API.
0109  */
0110 
0111 GLIB_AVAILABLE_IN_ALL
0112 int g_access    (const gchar *filename,
0113          int          mode);
0114 
0115 GLIB_AVAILABLE_IN_ALL
0116 int g_chmod     (const gchar *filename,
0117          int          mode);
0118 
0119 GLIB_AVAILABLE_IN_ALL
0120 int g_open      (const gchar *filename,
0121                  int          flags,
0122                  int          mode);
0123 
0124 GLIB_AVAILABLE_IN_ALL
0125 int g_creat     (const gchar *filename,
0126                  int          mode);
0127 
0128 GLIB_AVAILABLE_IN_ALL
0129 int g_rename    (const gchar *oldfilename,
0130                  const gchar *newfilename);
0131 
0132 GLIB_AVAILABLE_IN_ALL
0133 int g_mkdir     (const gchar *filename,
0134                  int          mode);
0135 
0136 GLIB_AVAILABLE_IN_ALL
0137 int g_chdir     (const gchar *path);
0138 
0139 GLIB_AVAILABLE_IN_ALL
0140 int g_stat      (const gchar *filename,
0141                  GStatBuf    *buf);
0142 
0143 GLIB_AVAILABLE_IN_ALL
0144 int g_lstat     (const gchar *filename,
0145                  GStatBuf    *buf);
0146 
0147 GLIB_AVAILABLE_IN_ALL
0148 int g_unlink    (const gchar *filename);
0149 
0150 GLIB_AVAILABLE_IN_ALL
0151 int g_remove    (const gchar *filename);
0152 
0153 GLIB_AVAILABLE_IN_ALL
0154 int g_rmdir     (const gchar *filename);
0155 
0156 GLIB_AVAILABLE_IN_ALL
0157 FILE *g_fopen   (const gchar *filename,
0158                  const gchar *mode);
0159 
0160 GLIB_AVAILABLE_IN_ALL
0161 FILE *g_freopen (const gchar *filename,
0162                  const gchar *mode,
0163                  FILE        *stream);
0164 
0165 GLIB_AVAILABLE_IN_2_64
0166 gint g_fsync    (gint fd);
0167 
0168 struct utimbuf;         /* Don't need the real definition of struct utimbuf when just
0169                  * including this header.
0170                  */
0171 
0172 GLIB_AVAILABLE_IN_ALL
0173 int g_utime     (const gchar    *filename,
0174          struct utimbuf *utb);
0175 
0176 #endif /* G_OS_UNIX */
0177 
0178 GLIB_AVAILABLE_IN_2_36
0179 gboolean g_close (gint       fd,
0180                   GError   **error);
0181 
0182 GLIB_AVAILABLE_STATIC_INLINE_IN_2_76
0183 static inline gboolean
0184 g_clear_fd (int     *fd_ptr,
0185             GError **error)
0186 {
0187   int fd = *fd_ptr;
0188 
0189   *fd_ptr = -1;
0190 
0191   if (fd < 0)
0192     return TRUE;
0193 
0194   /* Suppress "Not available before" warning */
0195   G_GNUC_BEGIN_IGNORE_DEPRECATIONS
0196   return g_close (fd, error);
0197   G_GNUC_END_IGNORE_DEPRECATIONS
0198 }
0199 
0200 /* g_autofd should be defined on the same compilers where g_autofree is
0201  * This avoids duplicating the feature-detection here. */
0202 #ifdef g_autofree
0203 #ifndef __GTK_DOC_IGNORE__
0204 /* Not public API */
0205 static inline void
0206 _g_clear_fd_ignore_error (int *fd_ptr)
0207 {
0208   /* Don't overwrite thread-local errno if closing the fd fails */
0209   int errsv = errno;
0210 
0211   /* Suppress "Not available before" warning */
0212   G_GNUC_BEGIN_IGNORE_DEPRECATIONS
0213 
0214   if (!g_clear_fd (fd_ptr, NULL))
0215     {
0216       /* Do nothing: we ignore all errors, except for EBADF which
0217        * is a programming error, checked for by g_close(). */
0218     }
0219 
0220   G_GNUC_END_IGNORE_DEPRECATIONS
0221 
0222   errno = errsv;
0223 }
0224 #endif
0225 
0226 #define g_autofd _GLIB_CLEANUP(_g_clear_fd_ignore_error) GLIB_AVAILABLE_MACRO_IN_2_76
0227 #endif
0228 
0229 G_END_DECLS
0230 
0231 #endif /* __G_STDIO_H__ */