[glib] Clarify use of struct stat on Windows
- From: Tor Lillqvist <tml src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glib] Clarify use of struct stat on Windows
- Date: Thu, 4 Feb 2010 17:59:42 +0000 (UTC)
commit 021643cda4f9b13fd72e898165744e9aefb346cd
Author: Tor Lillqvist <tml iki fi>
Date: Thu Feb 4 19:54:50 2010 +0200
Clarify use of struct stat on Windows
gio/glocalfile.c | 23 ++++++++++++++---------
gio/glocalfileinfo.c | 10 ++++++----
glib/gstdio.c | 24 +++++++++++++++++++-----
glib/gstdio.h | 37 +++++++++++++++++++++++++++++++++++++
4 files changed, 76 insertions(+), 18 deletions(-)
---
diff --git a/gio/glocalfile.c b/gio/glocalfile.c
index d6eea13..a0b7cb3 100644
--- a/gio/glocalfile.c
+++ b/gio/glocalfile.c
@@ -107,6 +107,11 @@
#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;
@@ -736,7 +741,7 @@ get_mount_info (GFileInfo *fs_info,
const char *path,
GFileAttributeMatcher *matcher)
{
- struct stat buf;
+ struct _g_stat_struct buf;
gboolean got_info;
gpointer info_as_ptr;
guint mount_info;
@@ -1047,7 +1052,7 @@ g_local_file_find_enclosing_mount (GFile *file,
GError **error)
{
GLocalFile *local = G_LOCAL_FILE (file);
- struct stat buf;
+ struct _g_stat_struct buf;
char *mountpoint;
GMount *mount;
@@ -1093,7 +1098,7 @@ g_local_file_set_display_name (GFile *file,
{
GLocalFile *local, *new_local;
GFile *new_file, *parent;
- struct stat statbuf;
+ struct _g_stat_struct statbuf;
int errsv;
parent = g_file_get_parent (file);
@@ -1504,7 +1509,7 @@ get_parent (const char *path,
dev_t *parent_dev)
{
char *parent, *tmp;
- struct stat parent_stat;
+ struct _g_stat_struct parent_stat;
int num_recursions;
char *path_copy;
@@ -1713,12 +1718,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 stat global_stat, trash_stat;
+ struct _g_stat_struct global_stat, trash_stat;
gboolean res;
if (g_once_init_enter (&home_dev_set))
{
- struct stat home_stat;
+ struct _g_stat_struct home_stat;
g_stat (g_get_home_dir (), &home_stat);
home_dev = home_stat.st_dev;
@@ -1780,7 +1785,7 @@ g_local_file_trash (GFile *file,
GError **error)
{
GLocalFile *local = G_LOCAL_FILE (file);
- struct stat file_stat, home_stat;
+ struct _g_stat_struct file_stat, home_stat;
const char *homedir;
char *trashdir, *topdir, *infodir, *filesdir;
char *basename, *trashname, *trashfile, *infoname, *infofile;
@@ -1790,7 +1795,7 @@ g_local_file_trash (GFile *file,
gboolean is_homedir_trash;
char delete_time[32];
int fd;
- struct stat trash_stat, global_stat;
+ struct _g_stat_struct trash_stat, global_stat;
char *dirname, *globaldir;
if (g_lstat (local->filename, &file_stat) != 0)
@@ -2188,7 +2193,7 @@ g_local_file_move (GFile *source,
GError **error)
{
GLocalFile *local_source, *local_destination;
- struct stat statbuf;
+ struct _g_stat_struct statbuf;
gboolean destination_exist, source_is_dir;
char *backup_name;
int res;
diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c
index 0eb16db..a913e82 100644
--- a/gio/glocalfileinfo.c
+++ b/gio/glocalfileinfo.c
@@ -96,6 +96,11 @@
#include "gioalias.h"
+/* See gstdio.h */
+#ifndef G_OS_WIN32
+#define _g_stat_struct stat
+#endif
+
struct ThumbMD5Context {
guint32 buf[4];
guint32 bits[2];
@@ -788,10 +793,7 @@ _g_local_file_info_get_parent_info (const char *dir,
GFileAttributeMatcher *attribute_matcher,
GLocalParentFileInfo *parent_info)
{
- /* Use plain struct stat for now as long as we only look at the
- * S_ISVTX bit which doesn't exist on Win32 anyway.
- */
- struct stat statbuf;
+ struct _g_stat_struct statbuf;
int res;
parent_info->extra_data = NULL;
diff --git a/glib/gstdio.c b/glib/gstdio.c
index 4971d9b..542a95e 100644
--- a/glib/gstdio.c
+++ b/glib/gstdio.c
@@ -51,6 +51,10 @@
#error Please port this to your operating system
#endif
+#if defined (_MSC_VER) && !defined(_WIN64)
+#undef _wstat
+#define _wstat _wstat32
+#endif
/**
* g_access:
@@ -442,8 +446,13 @@ g_chdir (const gchar *path)
* Since: 2.6
*/
int
-g_stat (const gchar *filename,
- struct stat *buf)
+g_stat (const gchar *filename,
+#ifdef G_OS_WIN32
+ struct _g_stat_struct *buf
+#else
+ struct stat *buf
+#endif
+ )
{
#ifdef G_OS_WIN32
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
@@ -464,7 +473,7 @@ g_stat (const gchar *filename,
(!g_path_is_absolute (filename) || len > g_path_skip_root (filename) - filename))
wfilename[len] = '\0';
- retval = _wstat (wfilename, (struct _stat *) buf);
+ retval = _wstat (wfilename, buf);
save_errno = errno;
g_free (wfilename);
@@ -496,8 +505,13 @@ g_stat (const gchar *filename,
* Since: 2.6
*/
int
-g_lstat (const gchar *filename,
- struct stat *buf)
+g_lstat (const gchar *filename,
+#ifdef G_OS_WIN32
+ struct _g_stat_struct *buf
+#else
+ struct stat *buf
+#endif
+ )
{
#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 f71a4e3..b61bc6b 100644
--- a/glib/gstdio.h
+++ b/glib/gstdio.h
@@ -89,12 +89,49 @@ 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
+ * 32-bit st_*time fields as that is how the 32-bit GLib DLL normally
+ * 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, .
+ */
+#define _g_stat_struct _stat32
+
+#else
+
+#define _g_stat_struct _stat
+
+#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);
int g_lstat (const gchar *filename,
struct stat *buf);
+#endif
+
int g_unlink (const gchar *filename);
int g_remove (const gchar *filename);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]