[gtk+] Bug 660730: Use GStatBuf for portability
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Bug 660730: Use GStatBuf for portability
- Date: Mon, 3 Oct 2011 15:25:44 +0000 (UTC)
commit eb8c2dfae297f340279e2a1c848b14584f0c1dc7
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Mon Oct 3 23:25:33 2011 +0800
Bug 660730: Use GStatBuf for portability
Thanks to Kean Johnston for pointing this out.
There are a few places in GTK that use "struct stat",
and then g_stat(), rather than using GStatBuf.This breaks things on
Windows. Since the size of struct stat can vary depending on other
flags specified, this has the potential to cause overwrites and is
trivial to fix.
Based on patch submitted by Kean Johnston
gtk/gtkiconcache.c | 11 ++++++++---
gtk/gtkicontheme.c | 6 +++---
gtk/gtkrecentmanager.c | 4 ++--
gtk/updateiconcache.c | 8 ++++----
4 files changed, 17 insertions(+), 12 deletions(-)
---
diff --git a/gtk/gtkiconcache.c b/gtk/gtkiconcache.c
index ecaf6df..855b270 100644
--- a/gtk/gtkiconcache.c
+++ b/gtk/gtkiconcache.c
@@ -89,8 +89,8 @@ _gtk_icon_cache_new_for_path (const gchar *path)
gchar *cache_filename;
gint fd = -1;
- struct stat st;
- struct stat path_st;
+ GStatBuf st;
+ GStatBuf path_st;
CacheInfo info;
/* Check if we have a cache file */
@@ -107,7 +107,12 @@ _gtk_icon_cache_new_for_path (const gchar *path)
if (fd < 0)
goto done;
-
+
+#ifdef G_OS_WIN32
+#undef fstat /* Just in case */
+#define fstat _fstat32
+#endif
+
if (fstat (fd, &st) < 0 || st.st_size < 4)
goto done;
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index cdebec3..5d90596 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -979,7 +979,7 @@ insert_theme (GtkIconTheme *icon_theme, const char *theme_name)
GKeyFile *theme_file;
GError *error = NULL;
IconThemeDirMtime *dir_mtime;
- struct stat stat_buf;
+ GStatBuf stat_buf;
priv = icon_theme->priv;
@@ -1123,7 +1123,7 @@ load_themes (GtkIconTheme *icon_theme)
IconSuffix old_suffix, new_suffix;
GTimeVal tv;
IconThemeDirMtime *dir_mtime;
- struct stat stat_buf;
+ GStatBuf stat_buf;
priv = icon_theme->priv;
@@ -1948,7 +1948,7 @@ rescan_themes (GtkIconTheme *icon_theme)
IconThemeDirMtime *dir_mtime;
GList *d;
int stat_res;
- struct stat stat_buf;
+ GStatBuf stat_buf;
GTimeVal tv;
priv = icon_theme->priv;
diff --git a/gtk/gtkrecentmanager.c b/gtk/gtkrecentmanager.c
index dbe83fa..5aadf35 100644
--- a/gtk/gtkrecentmanager.c
+++ b/gtk/gtkrecentmanager.c
@@ -2037,7 +2037,7 @@ gboolean
gtk_recent_info_exists (GtkRecentInfo *info)
{
gchar *filename;
- struct stat stat_buf;
+ GStatBuf stat_buf;
gboolean retval = FALSE;
g_return_val_if_fail (info != NULL, FALSE);
@@ -2049,7 +2049,7 @@ gtk_recent_info_exists (GtkRecentInfo *info)
filename = g_filename_from_uri (info->uri, NULL, NULL);
if (filename)
{
- if (stat (filename, &stat_buf) == 0)
+ if (g_stat (filename, &stat_buf) == 0)
retval = TRUE;
g_free (filename);
diff --git a/gtk/updateiconcache.c b/gtk/updateiconcache.c
index ea5cbfe..6988215 100644
--- a/gtk/updateiconcache.c
+++ b/gtk/updateiconcache.c
@@ -73,11 +73,11 @@ static gchar *var_name = "-";
#include <ftw.h>
-static struct stat cache_stat;
+static GStatBuf cache_stat;
static gboolean cache_up_to_date;
static int check_dir_mtime (const char *dir,
- const struct stat *sb,
+ const GStatBuf *sb,
int tf)
{
if (tf != FTW_NS && sb->st_mtime > cache_stat.st_mtime)
@@ -118,7 +118,7 @@ static int check_dir_mtime (const char *dir,
gboolean
is_cache_up_to_date (const gchar *path)
{
- struct stat path_stat, cache_stat;
+ GStatBuf path_stat, cache_stat;
gchar *cache_path;
int retval;
@@ -1455,7 +1455,7 @@ build_cache (const gchar *path)
#endif
GHashTable *files;
FILE *cache;
- struct stat path_stat, cache_stat;
+ GStatBuf path_stat, cache_stat;
struct utimbuf utime_buf;
GList *directories = NULL;
int fd;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]