diff options
author | Tor Lillqvist <tml@iki.fi> | 2010-03-21 20:04:18 +0200 |
---|---|---|
committer | Tor Lillqvist <tml@iki.fi> | 2010-03-30 19:22:39 +0300 |
commit | 1229281d95802c4c190284c7d331f67194a2553e (patch) | |
tree | f4f3b00a31efa65c05120ce80f831f2e48a06133 | |
parent | e7763678b56e3be073cc55d707a6e92fc2055ee0 (diff) | |
download | glib-1229281d95802c4c190284c7d331f67194a2553e.tar.gz |
Define a public documented type for the struct stat used by g_stat()
Define GStatBuf as the type used by g_stat() and g_lstat(). Replaces
the non-public struct tag _g_stat_struct. Mostly relevant for Windows
where there are several variants of stat-style structs. On POSIX, is
just another name for struct stat.
Actually, also on many POSIX systems there are in fact several
variants of struct stat and corresponding stat() and lstat()
functions, but as g_stat and g_lstat are normally on POSIX just macros
that expand to stat and lstat, this should not cause a problem. It's
only when it's the actual g_stat() or g_lstat() implementation inside
GLib that gets called that one needs to be sure the passed struct is
the same as what GLib expects.)
-rw-r--r-- | gio/giomodule.c | 6 | ||||
-rw-r--r-- | gio/glocalfile.c | 23 | ||||
-rw-r--r-- | gio/glocalfileinfo.c | 7 | ||||
-rw-r--r-- | glib/gstdio.c | 32 | ||||
-rw-r--r-- | glib/gstdio.h | 38 |
5 files changed, 42 insertions, 64 deletions
diff --git a/gio/giomodule.c b/gio/giomodule.c index 1f2e0bc2d..3f9203803 100644 --- a/gio/giomodule.c +++ b/gio/giomodule.c @@ -270,11 +270,7 @@ g_io_modules_scan_all_in_directory (const char *dirname) const gchar *name; char *filename; GDir *dir; -#ifdef G_OS_WIN32 - struct _g_stat_struct statbuf; -#else - struct stat statbuf; -#endif + GStatBuf statbuf; char *data; time_t cache_mtime; GHashTable *cache; diff --git a/gio/glocalfile.c b/gio/glocalfile.c index ec290e7a3..57dad0763 100644 --- a/gio/glocalfile.c +++ b/gio/glocalfile.c @@ -107,11 +107,6 @@ #include "gioalias.h" -/* See gstdio.h */ -#ifndef G_OS_WIN32 -#define _g_stat_struct stat -#endif - static void g_local_file_file_iface_init (GFileIface *iface); static GFileAttributeInfoList *local_writable_attributes = NULL; @@ -741,7 +736,7 @@ get_mount_info (GFileInfo *fs_info, const char *path, GFileAttributeMatcher *matcher) { - struct _g_stat_struct buf; + GStatBuf buf; gboolean got_info; gpointer info_as_ptr; guint mount_info; @@ -1052,7 +1047,7 @@ g_local_file_find_enclosing_mount (GFile *file, GError **error) { GLocalFile *local = G_LOCAL_FILE (file); - struct _g_stat_struct buf; + GStatBuf buf; char *mountpoint; GMount *mount; @@ -1098,7 +1093,7 @@ g_local_file_set_display_name (GFile *file, { GLocalFile *local, *new_local; GFile *new_file, *parent; - struct _g_stat_struct statbuf; + GStatBuf statbuf; GVfsClass *class; GVfs *vfs; int errsv; @@ -1516,7 +1511,7 @@ get_parent (const char *path, dev_t *parent_dev) { char *parent, *tmp; - struct _g_stat_struct parent_stat; + GStatBuf parent_stat; int num_recursions; char *path_copy; @@ -1725,12 +1720,12 @@ _g_local_file_has_trash_dir (const char *dirname, dev_t dir_dev) char *topdir, *globaldir, *trashdir, *tmpname; uid_t uid; char uid_str[32]; - struct _g_stat_struct global_stat, trash_stat; + GStatBuf global_stat, trash_stat; gboolean res; if (g_once_init_enter (&home_dev_set)) { - struct _g_stat_struct home_stat; + GStatBuf home_stat; g_stat (g_get_home_dir (), &home_stat); home_dev = home_stat.st_dev; @@ -1792,7 +1787,7 @@ g_local_file_trash (GFile *file, GError **error) { GLocalFile *local = G_LOCAL_FILE (file); - struct _g_stat_struct file_stat, home_stat; + GStatBuf file_stat, home_stat; const char *homedir; char *trashdir, *topdir, *infodir, *filesdir; char *basename, *trashname, *trashfile, *infoname, *infofile; @@ -1802,7 +1797,7 @@ g_local_file_trash (GFile *file, gboolean is_homedir_trash; char delete_time[32]; int fd; - struct _g_stat_struct trash_stat, global_stat; + GStatBuf trash_stat, global_stat; char *dirname, *globaldir; GVfsClass *class; GVfs *vfs; @@ -2207,7 +2202,7 @@ g_local_file_move (GFile *source, GError **error) { GLocalFile *local_source, *local_destination; - struct _g_stat_struct statbuf; + GStatBuf statbuf; gboolean destination_exist, source_is_dir; char *backup_name; int res; diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c index a913e826d..6b5226792 100644 --- a/gio/glocalfileinfo.c +++ b/gio/glocalfileinfo.c @@ -96,11 +96,6 @@ #include "gioalias.h" -/* See gstdio.h */ -#ifndef G_OS_WIN32 -#define _g_stat_struct stat -#endif - struct ThumbMD5Context { guint32 buf[4]; guint32 bits[2]; @@ -793,7 +788,7 @@ _g_local_file_info_get_parent_info (const char *dir, GFileAttributeMatcher *attribute_matcher, GLocalParentFileInfo *parent_info) { - struct _g_stat_struct statbuf; + GStatBuf statbuf; int res; parent_info->extra_data = NULL; diff --git a/glib/gstdio.c b/glib/gstdio.c index 542a95e1a..82549f58d 100644 --- a/glib/gstdio.c +++ b/glib/gstdio.c @@ -438,6 +438,20 @@ g_chdir (const gchar *path) * not look at the ACL at all. Thus on Windows the protection bits in * the st_mode field are a fabrication of little use. * + * On Windows the Microsoft C libraries have several variants of the + * <structname>stat</structname> struct and stat() function with names + * like "_stat", "_stat32", "_stat32i64" and "_stat64i32". The one + * used here is for 32-bit code the one with 32-bit size and time + * fields, specifically called "_stat32". + * + * In Microsoft's compiler, by default "struct stat" means one with + * 64-bit time fields while in MinGW "struct stat" is the legacy one + * with 32-bit fields. To hopefully clear up this messs, the gstdio.h + * header defines a type GStatBuf which is the appropriate struct type + * depending on the platform and/or compiler being used. On POSIX it + * is just "struct stat", but note that even on POSIX platforms, + * "stat" might be a macro. + * * See your C library manual for more details about stat(). * * Returns: 0 if the information was successfully retrieved, -1 if an error @@ -446,13 +460,8 @@ g_chdir (const gchar *path) * Since: 2.6 */ int -g_stat (const gchar *filename, -#ifdef G_OS_WIN32 - struct _g_stat_struct *buf -#else - struct stat *buf -#endif - ) +g_stat (const gchar *filename, + GStatBuf *buf) { #ifdef G_OS_WIN32 wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL); @@ -505,13 +514,8 @@ g_stat (const gchar *filename, * Since: 2.6 */ int -g_lstat (const gchar *filename, -#ifdef G_OS_WIN32 - struct _g_stat_struct *buf -#else - struct stat *buf -#endif - ) +g_lstat (const gchar *filename, + GStatBuf *buf) { #ifdef HAVE_LSTAT /* This can't be Win32, so don't do the widechar dance. */ diff --git a/glib/gstdio.h b/glib/gstdio.h index b61bc6bf1..cc094cbb3 100644 --- a/glib/gstdio.h +++ b/glib/gstdio.h @@ -89,12 +89,6 @@ int g_mkdir (const gchar *filename, int g_chdir (const gchar *path); -#ifdef G_OS_WIN32 - -/* The _g_stat_struct struct tag is an internal implementation detail - * and not part of the public GLib API. - */ - #if defined (_MSC_VER) && !defined(_WIN64) /* Make it clear that we mean the struct with 32-bit st_size and @@ -102,35 +96,29 @@ int g_chdir (const gchar *path); * has been compiled. If you get a compiler warning when calling * g_stat(), do take it seriously and make sure that the type of * struct stat the code in GLib fills in matches the struct the type - * of struct stat you pass to g_stat(). To avoid hassle, just use the - * GIO API instead which doesn't use struct stat to get file - * attributes, . + * of struct stat you pass to g_stat(). To avoid hassle, to get file + * attributes just use the GIO API instead which doesn't use struct + * stat. + * + * Sure, it would be nicer to use a struct with 64-bit st_size and + * 64-bit st_*time fields, but changing that now would break ABI. And + * in MinGW, a plain "struct stat" is the one with 32-bit st_size and + * st_*time fields. */ -#define _g_stat_struct _stat32 + +typedef struct _stat32 GStatBuf; #else -#define _g_stat_struct _stat +typedef struct stat GStatBuf; #endif -int g_stat (const gchar *filename, - struct _g_stat_struct *buf); - -int g_lstat (const gchar *filename, - struct _g_stat_struct *buf); - -#else - -/* No _g_stat_struct used on Unix */ - int g_stat (const gchar *filename, - struct stat *buf); + GStatBuf *buf); int g_lstat (const gchar *filename, - struct stat *buf); - -#endif + GStatBuf *buf); int g_unlink (const gchar *filename); |