Clarify use of struct stat on Windows

This commit is contained in:
Tor Lillqvist 2010-02-04 19:54:50 +02:00
parent 5589d2b455
commit 021643cda4
4 changed files with 76 additions and 18 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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. */

View File

@ -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);