From 577ddebb831950cc9374bf2ef71b6b957efdd7d1 Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Fri, 25 Dec 2015 19:16:35 -0800 Subject: [PATCH] Do not use stat() and struct stat directly --- api/CMakeLists.txt | 1 - api/sourcefiles.mak | 1 - moo/Makefile.am | 6 ++++ moo/mooedit/mooedit-fileops.c | 1 - moo/moofileview/moofile-private.h | 23 ++++++------- moo/moofileview/moofile.c | 36 +++++++------------ moo/moofileview/moofolder.c | 8 ++--- moo/mooglib/moo-glib.c | 57 +++++++++++++++++++++++++++++++ moo/mooglib/moo-glib.h | 10 +++++- moo/mooglib/moo-stat.h | 30 ++++++++++++++++ moo/mooglib/moo-time.h | 16 +++++++++ moo/mooutils/Makefile.incl | 1 - moo/mooutils/moo-mime.c | 8 +++-- moo/mooutils/moo-mime.h | 6 ++-- moo/mooutils/mooappinput.c | 1 - moo/mooutils/moofileicon.c | 1 - moo/mooutils/moofilewatch.c | 31 ++++++++--------- moo/mooutils/moostat.h | 52 ---------------------------- moo/mooutils/mooutils-fs.c | 12 +++---- moo/mooutils/mooutils-fs.h | 10 ------ moo/mooutils/mooutils-misc.c | 1 - moo/mooutils/mooutils-win32.c | 7 ++-- moo/mooutils/mooutils.cmake | 1 - moo/mooutils/moowin32/ms/unistd.h | 5 --- moo/plugins/moofileselector.c | 9 +++-- moo/xdgmime/Makefile.incl | 8 ++++- moo/xdgmime/xdgmime.c | 17 +++++---- moo/xdgmime/xdgmime.h | 2 +- moo/xdgmime/xdgmimecache.c | 15 ++++---- moo/xdgmime/xdgmimecache.h | 2 +- moo/xdgmime/xdgmimeint.h | 21 +----------- 31 files changed, 210 insertions(+), 189 deletions(-) create mode 100644 moo/mooglib/moo-glib.c create mode 100644 moo/mooglib/moo-stat.h create mode 100644 moo/mooglib/moo-time.h delete mode 100644 moo/mooutils/moostat.h diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 4ca7d925..938a7402 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -253,7 +253,6 @@ SET(source_files ../moo/mooutils/mooprefspage.h ../moo/mooutils/moospawn.c ../moo/mooutils/moospawn.h - ../moo/mooutils/moostat.h ../moo/mooutils/moostock.c ../moo/mooutils/moostock.h ../moo/mooutils/moo-test-macros.h diff --git a/api/sourcefiles.mak b/api/sourcefiles.mak index 4a33b6df..5cceb40e 100644 --- a/api/sourcefiles.mak +++ b/api/sourcefiles.mak @@ -223,7 +223,6 @@ source_files = \ ../moo/mooutils/mooprefspage.h\ ../moo/mooutils/moospawn.c\ ../moo/mooutils/moospawn.h\ - ../moo/mooutils/moostat.h\ ../moo/mooutils/moostock.c\ ../moo/mooutils/moostock.h\ ../moo/mooutils/moo-test-macros.h\ diff --git a/moo/Makefile.am b/moo/Makefile.am index 70143309..80d4d880 100644 --- a/moo/Makefile.am +++ b/moo/Makefile.am @@ -20,6 +20,12 @@ moo_builddir = . moo_sources += moo-config.h +moo_sources += \ + mooglib/moo-glib.h \ + mooglib/moo-stat.h \ + mooglib/moo-time.h \ + mooglib/moo-glib.c + EXTRA_DIST += marshals.list built_moo_sources += marshals.h marshals.h: marshals.list diff --git a/moo/mooedit/mooedit-fileops.c b/moo/mooedit/mooedit-fileops.c index 8d45678e..9612c4a4 100644 --- a/moo/mooedit/mooedit-fileops.c +++ b/moo/mooedit/mooedit-fileops.c @@ -34,7 +34,6 @@ #include "mooutils/moocompat.h" #include #include -#include #include #ifdef HAVE_UNISTD_H #include diff --git a/moo/moofileview/moofile-private.h b/moo/moofileview/moofile-private.h index a5dee6a7..4e62bcfc 100644 --- a/moo/moofileview/moofile-private.h +++ b/moo/moofileview/moofile-private.h @@ -17,7 +17,6 @@ #define MOO_FILE_PRIVATE_H #include "moofileview/moofile.h" -#include #include G_BEGIN_DECLS @@ -39,17 +38,17 @@ typedef struct MooCollationKey MooCollationKey; struct _MooFile { - char *name; - char *link_target; - char *display_name; /* normalized */ - char *case_display_name; - MooCollationKey *collation_key; - MooFileInfo info; - MooFileFlags flags; - guint8 icon; - const char *mime_type; - int ref_count; - struct stat *statbuf; + char *name; + char *link_target; + char *display_name; /* normalized */ + char *case_display_name; + MooCollationKey *collation_key; + MooFileInfo info; + MooFileFlags flags; + guint8 icon; + const char *mime_type; + int ref_count; + struct MgwStatBuf *statbuf; }; diff --git a/moo/moofileview/moofile.c b/moo/moofileview/moofile.c index e7ef1b7b..564c1618 100644 --- a/moo/moofileview/moofile.c +++ b/moo/moofileview/moofile.c @@ -28,13 +28,13 @@ #include "mooutils/mooutils-misc.h" #include "mooutils/mootype-macros.h" #include "mooutils/mooutils-debug.h" -#include "mooutils/moostat.h" #include "marshals.h" #include "mooutils/moo-mime.h" #include +#include + #include #include -#include #ifdef HAVE_UNISTD_H #include #endif @@ -309,7 +309,7 @@ _moo_file_unref (MooFile *file) g_free (file->case_display_name); g_free (file->collation_key); g_free (file->link_target); - g_slice_free (struct stat, file->statbuf); + g_slice_free (MgwStatBuf, file->statbuf); g_slice_free (MooFile, file); } } @@ -334,9 +334,9 @@ _moo_file_stat (MooFile *file, errno = 0; if (!file->statbuf) - file->statbuf = g_slice_new (struct stat); + file->statbuf = g_slice_new (MgwStatBuf); - if (moo_lstat (fullname, file->statbuf) != 0) + if (mgw_lstat (fullname, file->statbuf) != 0) { if (errno == ENOENT) { @@ -362,8 +362,7 @@ _moo_file_stat (MooFile *file, } else { -#ifdef S_ISLNK - if (S_ISLNK (file->statbuf->st_mode)) + if (file->statbuf->islnk) { static char buf[1024]; gssize len; @@ -371,7 +370,7 @@ _moo_file_stat (MooFile *file, file->info |= MOO_FILE_INFO_IS_LINK; errno = 0; - if (moo_stat (fullname, file->statbuf) != 0) + if (mgw_stat (fullname, file->statbuf) != 0) { if (errno == ENOENT) { @@ -413,30 +412,21 @@ _moo_file_stat (MooFile *file, file->link_target = g_strndup (buf, len); } } -#endif } if ((file->info & MOO_FILE_INFO_EXISTS) && !(file->info & MOO_FILE_INFO_IS_LOCKED)) { - if (S_ISDIR (file->statbuf->st_mode)) + if (file->statbuf->isdir) file->info |= MOO_FILE_INFO_IS_DIR; -#ifdef S_ISBLK - else if (S_ISBLK (file->statbuf->st_mode)) + else if (file->statbuf->isblk) file->info |= MOO_FILE_INFO_IS_BLOCK_DEV; -#endif -#ifdef S_ISCHR - else if (S_ISCHR (file->statbuf->st_mode)) + else if (file->statbuf->ischr) file->info |= MOO_FILE_INFO_IS_CHAR_DEV; -#endif -#ifdef S_ISFIFO - else if (S_ISFIFO (file->statbuf->st_mode)) + else if (file->statbuf->isfifo) file->info |= MOO_FILE_INFO_IS_FIFO; -#endif -#ifdef S_ISSOCK - else if (S_ISSOCK (file->statbuf->st_mode)) + else if (file->statbuf->issock) file->info |= MOO_FILE_INFO_IS_SOCKET; -#endif } if (file->info & MOO_FILE_INFO_IS_DIR) @@ -457,7 +447,7 @@ void _moo_file_free_statbuf (MooFile *file) { g_return_if_fail (file != NULL); - g_slice_free (struct stat, file->statbuf); + g_slice_free (MgwStatBuf, file->statbuf); file->statbuf = NULL; file->flags &= ~MOO_FILE_HAS_STAT; } diff --git a/moo/moofileview/moofolder.c b/moo/moofileview/moofolder.c index e71cf278..5c44173a 100644 --- a/moo/moofileview/moofolder.c +++ b/moo/moofileview/moofolder.c @@ -23,9 +23,9 @@ #include "mooutils/mooutils-misc.h" #include "marshals.h" #include +#include #include #include -#include #ifdef HAVE_UNISTD_H #include #endif @@ -1036,10 +1036,10 @@ moo_file_get_type_string (MooFile *file) /* XXX */ static char * -get_size_string (struct stat *statbuf) +get_size_string (MgwStatBuf *statbuf) { g_return_val_if_fail (statbuf != NULL, NULL); - return g_strdup_printf ("%" G_GINT64_FORMAT, (gint64) statbuf->st_size); + return g_strdup_printf ("%" G_GUINT64_FORMAT, statbuf->size); } @@ -1059,7 +1059,7 @@ moo_file_get_mtime_string (MooFile *file) g_return_val_if_fail (file->statbuf != NULL, NULL); - if (strftime (buf, 1024, "%x %X", localtime (&file->statbuf->st_mtime))) + if (strftime (buf, 1024, "%x %X", mgw_localtime (&file->statbuf->mtime))) return g_strdup (buf); else return NULL; diff --git a/moo/mooglib/moo-glib.c b/moo/mooglib/moo-glib.c new file mode 100644 index 00000000..c258b5b5 --- /dev/null +++ b/moo/mooglib/moo-glib.c @@ -0,0 +1,57 @@ +#define MOO_DO_NOT_MANGLE_GLIB_FUNCTIONS +#include +#include +#include + +#include +#include + + +static mgw_time_t convert_time_t (time_t t) +{ + mgw_time_t result = { t }; + return result; +} + + +static void convert_g_stat_buf (const GStatBuf* gbuf, MgwStatBuf* mbuf) +{ + mbuf->atime = convert_time_t (gbuf->st_atime); + mbuf->mtime = convert_time_t (gbuf->st_mtime); + mbuf->ctime = convert_time_t (gbuf->st_ctime); + + mbuf->size = gbuf->st_size; + + mbuf->isreg = S_ISREG (gbuf->st_mode); + mbuf->isdir = S_ISDIR (gbuf->st_mode); + mbuf->islnk = S_ISLNK (gbuf->st_mode); + mbuf->issock = S_ISSOCK (gbuf->st_mode); + mbuf->isfifo = S_ISFIFO (gbuf->st_mode); + mbuf->ischr = S_ISCHR (gbuf->st_mode); + mbuf->isblk = S_ISBLK (gbuf->st_mode); +} + + +int mgw_stat (const gchar *filename, MgwStatBuf *buf) +{ + GStatBuf gbuf = { 0 }; + int result = g_stat (filename, &gbuf); + convert_g_stat_buf (&gbuf, buf); + return result; +} + + +int mgw_lstat (const gchar *filename, MgwStatBuf *buf) +{ + GStatBuf gbuf = { 0 }; + int result = g_lstat (filename, &gbuf); + convert_g_stat_buf (&gbuf, buf); + return result; +} + + +const struct tm *mgw_localtime(const mgw_time_t *timep) +{ + time_t t = timep->value; + return localtime(&t); +} diff --git a/moo/mooglib/moo-glib.h b/moo/mooglib/moo-glib.h index 470cec63..0d952bfe 100644 --- a/moo/mooglib/moo-glib.h +++ b/moo/mooglib/moo-glib.h @@ -3,6 +3,14 @@ #include #include -// Fun redefining and undefining things goes on here +#ifndef MOO_DO_NOT_MANGLE_GLIB_FUNCTIONS + +#undef g_stat +#undef g_lstat + +#define g_stat DO_NOT_USE_THIS_DIRECTLY_USE_MGW_WRAPPERS_INSTEAD +#define g_lstat DO_NOT_USE_THIS_DIRECTLY_USE_MGW_WRAPPERS_INSTEAD + +#endif // MOO_DO_NOT_MANGLE_GLIB_FUNCTIONS //#include diff --git a/moo/mooglib/moo-stat.h b/moo/mooglib/moo-stat.h new file mode 100644 index 00000000..81f6240d --- /dev/null +++ b/moo/mooglib/moo-stat.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include + +G_BEGIN_DECLS + +typedef struct MgwStatBuf MgwStatBuf; + +struct MgwStatBuf +{ + mgw_time_t atime; + mgw_time_t mtime; + mgw_time_t ctime; + + guint64 size; + + guint isreg : 1, // S_ISREG + isdir : 1, // S_ISDIR + islnk : 1, // S_ISLNK + issock : 1, // S_ISSOCK + isfifo : 1, // S_ISFIFO + ischr : 1, // S_ISCHR + isblk : 1; // S_ISBLK +}; + +int mgw_stat (const gchar *filename, MgwStatBuf *buf); +int mgw_lstat (const gchar *filename, MgwStatBuf *buf); + +G_END_DECLS diff --git a/moo/mooglib/moo-time.h b/moo/mooglib/moo-time.h new file mode 100644 index 00000000..d0b4aac6 --- /dev/null +++ b/moo/mooglib/moo-time.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +G_BEGIN_DECLS + +typedef struct mgw_time_t mgw_time_t; + +struct mgw_time_t +{ + gint64 value; +}; + +const struct tm *mgw_localtime(const mgw_time_t *timep); + +G_END_DECLS diff --git a/moo/mooutils/Makefile.incl b/moo/mooutils/Makefile.incl index 7eacfcaf..a4b720dd 100644 --- a/moo/mooutils/Makefile.incl +++ b/moo/mooutils/Makefile.incl @@ -100,7 +100,6 @@ moo_sources += \ mooutils/mooprefspage.h \ mooutils/moospawn.c \ mooutils/moospawn.h \ - mooutils/moostat.h \ mooutils/moostock.c \ mooutils/moostock.h \ mooutils/mootype-macros.h \ diff --git a/moo/mooutils/moo-mime.c b/moo/mooutils/moo-mime.c index ad591293..7f772661 100644 --- a/moo/mooutils/moo-mime.c +++ b/moo/mooutils/moo-mime.c @@ -16,6 +16,7 @@ #include "mooutils/moo-mime.h" #include "xdgmime/xdgmime.h" #include "mooutils/mooutils-fs.h" +#include #include G_LOCK_DEFINE (moo_mime); @@ -49,17 +50,18 @@ mime_type_intern (const char *mime) } const char * -moo_get_mime_type_for_file (const char *filename, - struct stat *statbuf) +moo_get_mime_type_for_file (const char *filename, + MgwStatBuf *statbuf) { const char *mime; char *filename_utf8 = NULL; + gboolean is_regular = statbuf ? statbuf->isreg : FALSE; if (filename) filename_utf8 = g_filename_display_name (filename); G_LOCK (moo_mime); - mime = mime_type_intern (xdg_mime_get_mime_type_for_file (filename_utf8, statbuf)); + mime = mime_type_intern (xdg_mime_get_mime_type_for_file (filename_utf8, statbuf ? &is_regular : NULL)); G_UNLOCK (moo_mime); g_free (filename_utf8); diff --git a/moo/mooutils/moo-mime.h b/moo/mooutils/moo-mime.h index dcbcf5d7..3c869c2b 100644 --- a/moo/mooutils/moo-mime.h +++ b/moo/mooutils/moo-mime.h @@ -20,16 +20,16 @@ G_BEGIN_DECLS - /* All public functions here are thread-safe */ +typedef struct MgwStatBuf MgwStatBuf; + #define MOO_MIME_TYPE_UNKNOWN (moo_mime_type_unknown ()) const char *moo_mime_type_unknown (void) G_GNUC_CONST; -struct stat; const char *moo_get_mime_type_for_file (const char *filename, - struct stat *statbuf); + MgwStatBuf *statbuf); const char *moo_get_mime_type_for_filename (const char *filename); gboolean moo_mime_type_is_subclass (const char *mime_type, const char *base); diff --git a/moo/mooutils/mooappinput.c b/moo/mooutils/mooappinput.c index 1709261c..dc915a40 100644 --- a/moo/mooutils/mooappinput.c +++ b/moo/mooutils/mooappinput.c @@ -33,7 +33,6 @@ #include #include #include -#include #endif #include diff --git a/moo/mooutils/moofileicon.c b/moo/mooutils/moofileicon.c index 2cc24172..6611e6da 100644 --- a/moo/mooutils/moofileicon.c +++ b/moo/mooutils/moofileicon.c @@ -22,7 +22,6 @@ #include "moo-pixbufs.h" #include #include -#include #include void diff --git a/moo/mooutils/moofilewatch.c b/moo/mooutils/moofilewatch.c index 65dc17d0..bd4e05e1 100644 --- a/moo/mooutils/moofilewatch.c +++ b/moo/mooutils/moofilewatch.c @@ -36,15 +36,12 @@ #endif #include -#include +#include #include #include -/* sys/stat.h macros */ -#include "mooutils/mooutils-fs.h" #include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-mem.h" #include "mooutils/moofilewatch.h" -#include "mooutils/moostat.h" #include "mooutils/mootype-macros.h" #include "marshals.h" #include "mooutils/mooutils-thread.h" @@ -73,7 +70,7 @@ typedef struct { GDestroyNotify notify; gpointer data; - struct stat statbuf; + MgwStatBuf statbuf; guint isdir : 1; guint alive : 1; @@ -505,7 +502,7 @@ watch_fam_start (MooFileWatch *watch, FAMNoExists (&watch->fam_connection); #endif - fam_socket = g_io_channel_unix_new (watch->fam_connection.fd); + fam_socket = moo_g_io_channel_unix_new (watch->fam_connection.fd); watch->fam_connection_watch = _moo_io_add_watch_full (fam_socket, MOO_FAM_SOCKET_WATCH_PRIORITY, G_IO_IN | G_IO_PRI | G_IO_HUP, @@ -804,14 +801,14 @@ watch_stat_start_monitor (MooFileWatch *watch, Monitor *monitor, GError **error) { - struct stat buf; + MgwStatBuf buf; g_return_val_if_fail (watch != NULL, FALSE); g_return_val_if_fail (monitor->filename != NULL, FALSE); errno = 0; - if (moo_stat (monitor->filename, &buf) != 0) + if (mgw_stat (monitor->filename, &buf) != 0) { int saved_errno = errno; g_set_error (error, MOO_FILE_WATCH_ERROR, @@ -820,7 +817,7 @@ watch_stat_start_monitor (MooFileWatch *watch, return FALSE; } - monitor->isdir = S_ISDIR (buf.st_mode) != 0; + monitor->isdir = buf.isdir; #ifdef __WIN32__ if (monitor->isdir) /* it's fatal on windows */ @@ -868,14 +865,14 @@ do_stat (MooFileWatch *watch) gboolean do_emit = FALSE; MooFileEvent event; Monitor *monitor; - time_t old; + mgw_time_t old; monitor = (Monitor*) g_hash_table_lookup (watch->requests, lid->data); if (!monitor || !monitor->alive) continue; - old = monitor->statbuf.st_mtime; + old = monitor->statbuf.mtime; errno = 0; @@ -883,7 +880,7 @@ do_stat (MooFileWatch *watch) event.filename = monitor->filename; event.error = NULL; - if (moo_stat (monitor->filename, &monitor->statbuf) != 0) + if (mgw_stat (monitor->filename, &monitor->statbuf) != 0) { if (errno == ENOENT) { @@ -903,7 +900,7 @@ do_stat (MooFileWatch *watch) do_emit = TRUE; } - else if (monitor->statbuf.st_mtime > old) + else if (monitor->statbuf.mtime.value > old.value) { event.code = MOO_FILE_EVENT_CHANGED; do_emit = TRUE; @@ -1122,11 +1119,11 @@ static void fam_thread_check_dir (FAMThread *thr, guint idx) { - struct stat buf; + MgwStatBuf buf; errno = 0; - if (moo_stat (thr->watches[idx].path, &buf) != 0 && + if (mgw_stat (thr->watches[idx].path, &buf) != 0 && errno == ENOENT) { fam_thread_event (MOO_FILE_EVENT_DELETED, @@ -1444,14 +1441,14 @@ watch_win32_start_monitor (MooFileWatch *watch, Monitor *monitor, GError **error) { - struct stat buf; + MgwStatBuf buf; g_return_val_if_fail (watch != NULL, FALSE); g_return_val_if_fail (monitor->filename != NULL, FALSE); errno = 0; - if (moo_stat (monitor->filename, &buf) != 0) + if (mgw_stat (monitor->filename, &buf) != 0) { int saved_errno = errno; g_set_error (error, MOO_FILE_WATCH_ERROR, diff --git a/moo/mooutils/moostat.h b/moo/mooutils/moostat.h deleted file mode 100644 index 3da184dd..00000000 --- a/moo/mooutils/moostat.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef MOO_STAT_H -#define MOO_STAT_H - -#include - -#undef MOO_G_STAT_BROKEN - -#if defined(G_OS_WIN32) && GLIB_CHECK_VERSION(2,22,0) && !GLIB_CHECK_VERSION(2,26,0) -#define MOO_G_STAT_BROKEN 1 -#endif - -#ifdef MOO_G_STAT_BROKEN - -inline static void _moo_check_stat_struct(void) -{ - struct _g_stat_struct statbuf; - // check that _g_stat_struct is the same as plain struct stat - _off_t *pofft = &statbuf.st_size; - time_t *ptimet = &statbuf.st_atime; - (void) pofft; - (void) ptimet; -} - -#endif - -G_BEGIN_DECLS - -inline static int moo_stat (const char *filename, struct stat *buf) -{ -#ifdef MOO_G_STAT_BROKEN - /* _moo_check_stat_struct above checks that struct stat is okay, - cast to void* is to avoid using glib's internal _g_stat_struct */ - return g_stat (filename, (struct _g_stat_struct*) buf); -#else - return g_stat (filename, buf); -#endif -} - -inline static int moo_lstat (const char *filename, struct stat *buf) -{ -#ifdef MOO_G_STAT_BROKEN - /* _moo_check_stat_struct above checks that struct stat is okay, - cast to void* is to avoid using glib's internal _g_stat_struct */ - return g_lstat (filename, (struct _g_stat_struct*) buf); -#else - return g_lstat (filename, buf); -#endif -} - -G_END_DECLS - -#endif /* MOO_STAT_H */ diff --git a/moo/mooutils/mooutils-fs.c b/moo/mooutils/mooutils-fs.c index c5161a22..d2916b76 100644 --- a/moo/mooutils/mooutils-fs.c +++ b/moo/mooutils/mooutils-fs.c @@ -18,20 +18,18 @@ #endif #include "mooutils/mooutils-fs.h" -#include "mooutils/moostat.h" #include "mooutils/mooutils-debug.h" #include "mooutils/mooutils-mem.h" #include "mooutils/mootype-macros.h" #include "mooutils/mooi18n.h" #include +#include +#include #include #include -#include #include #include -#include -#include #ifdef __WIN32__ #include @@ -368,14 +366,14 @@ gboolean _moo_create_dir (const char *path, GError **error) { - struct stat buf; + MgwStatBuf buf; char *utf8_path; g_return_val_if_fail (path != NULL, FALSE); errno = 0; - if (moo_stat (path, &buf) != 0 && errno != ENOENT) + if (mgw_stat (path, &buf) != 0 && errno != ENOENT) { int err_code = errno; utf8_path = g_filename_display_name (path); @@ -412,7 +410,7 @@ _moo_create_dir (const char *path, return TRUE; } - if (S_ISDIR (buf.st_mode)) + if (buf.isdir) return TRUE; utf8_path = g_filename_display_name (path); diff --git a/moo/mooutils/mooutils-fs.h b/moo/mooutils/mooutils-fs.h index 61f32020..4a019dce 100644 --- a/moo/mooutils/mooutils-fs.h +++ b/moo/mooutils/mooutils-fs.h @@ -19,16 +19,6 @@ #include #include -/* MSVC */ -#if defined(_WIN32) && !defined(__GNUC__) -#include -#include -#ifndef S_ISREG -#define S_ISREG(m) (((m) & (_S_IFMT)) == (_S_IFREG)) -#define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR)) -#endif -#endif - #ifndef O_BINARY #define O_BINARY 0x0 #endif diff --git a/moo/mooutils/mooutils-misc.c b/moo/mooutils/mooutils-misc.c index 8d8637c9..983bf1e8 100644 --- a/moo/mooutils/mooutils-misc.c +++ b/moo/mooutils/mooutils-misc.c @@ -35,7 +35,6 @@ #endif #include #include -#include #include #include #include diff --git a/moo/mooutils/mooutils-win32.c b/moo/mooutils/mooutils-win32.c index 80fb6432..33237e5c 100644 --- a/moo/mooutils/mooutils-win32.c +++ b/moo/mooutils/mooutils-win32.c @@ -41,12 +41,13 @@ #include "mooutils/moowin32/mingw/fnmatch.h" #include "mooutils/moowin32/mingw/sys/mman.h" #include +#include + #include #include #include #include #include -#include #include #include #include @@ -507,7 +508,7 @@ _moo_win32_mmap (gpointer start, int fd, guint64 offset) { - struct stat st; + MgwStatBuf st; HANDLE mapping; char *buffer; @@ -517,7 +518,7 @@ _moo_win32_mmap (gpointer start, g_return_val_if_fail (offset == 0, NULL); errno = 0; - if (fstat (fd, &st) != 0) + if (mgw_fstat (fd, &st) != 0) return MAP_FAILED; if ((guint64) st.st_size != length) diff --git a/moo/mooutils/mooutils.cmake b/moo/mooutils/mooutils.cmake index 21e2f2ea..7916e763 100644 --- a/moo/mooutils/mooutils.cmake +++ b/moo/mooutils/mooutils.cmake @@ -102,7 +102,6 @@ SET(mooutils_sources mooutils/mooprefspage.h mooutils/moospawn.c mooutils/moospawn.h - mooutils/moostat.h mooutils/moostock.c mooutils/moostock.h mooutils/mootype-macros.h diff --git a/moo/mooutils/moowin32/ms/unistd.h b/moo/mooutils/moowin32/ms/unistd.h index 92e6cf2b..1464e630 100644 --- a/moo/mooutils/moowin32/ms/unistd.h +++ b/moo/mooutils/moowin32/ms/unistd.h @@ -3,11 +3,6 @@ #include -#ifndef S_ISREG -#define S_ISREG(m) (((m) & (_S_IFMT)) == (_S_IFREG)) -#define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR)) -#endif - #define F_OK 0x0 #define R_OK 0x4 #define W_OK 0x2 diff --git a/moo/plugins/moofileselector.c b/moo/plugins/moofileselector.c index 7dec112e..41907497 100644 --- a/moo/plugins/moofileselector.c +++ b/moo/plugins/moofileselector.c @@ -35,20 +35,19 @@ #include "mooutils/mooi18n.h" #include "mooutils/moo-mime.h" #include "mooutils/moomenu.h" -#include "mooutils/moostat.h" #include "plugins/moofileselector-gxml.h" #include "mooutils/moohelp.h" #include "mooutils/mooatom.h" +#include +#include #ifdef MOO_ENABLE_HELP #include "moo-help-sections.h" #endif #include #include #include -#include #include #include -#include #define PREFS_LAST_DIR MOO_PLUGIN_PREFS_ROOT "/" MOO_FILE_SELECTOR_PLUGIN_ID "/last_dir" #define PREFS_HIDDEN_FILES MOO_PLUGIN_PREFS_ROOT "/" MOO_FILE_SELECTOR_PLUGIN_ID "/show_hidden_files" @@ -270,7 +269,7 @@ static void moo_file_selector_activate (MooFileView *fileview, const char *path) { - struct stat statbuf; + MgwStatBuf statbuf; MooFileSelector *filesel = MOO_FILE_SELECTOR (fileview); gboolean is_text = TRUE, is_exe = FALSE; @@ -278,7 +277,7 @@ moo_file_selector_activate (MooFileView *fileview, errno = 0; - if (moo_stat (path, &statbuf) != 0) + if (mgw_stat (path, &statbuf) != 0) { int err = errno; g_warning ("error in stat(%s): %s", path, g_strerror (err)); diff --git a/moo/xdgmime/Makefile.incl b/moo/xdgmime/Makefile.incl index e9a91b47..fd8e9606 100644 --- a/moo/xdgmime/Makefile.incl +++ b/moo/xdgmime/Makefile.incl @@ -1,4 +1,4 @@ -moo_sources += \ +xdgmime_sources = \ xdgmime/xdgmimealias.c \ xdgmime/xdgmimealias.h \ xdgmime/xdgmime.c \ @@ -14,3 +14,9 @@ moo_sources += \ xdgmime/xdgmimemagic.h \ xdgmime/xdgmimeparent.c \ xdgmime/xdgmimeparent.h + +if MOO_OS_WIN32 +EXTRA_DIST += $(xdgmime_sources) +else +moo_sources += $(xdgmime_sources) +endif diff --git a/moo/xdgmime/xdgmime.c b/moo/xdgmime/xdgmime.c index b450f38f..f93ba942 100644 --- a/moo/xdgmime/xdgmime.c +++ b/moo/xdgmime/xdgmime.c @@ -421,7 +421,7 @@ xdg_mime_get_mime_type_for_data (const void *data, const char * xdg_mime_get_mime_type_for_file (const char *file_name, - struct stat *statbuf) + int *is_regular) { const char *mime_type; /* currently, only a few globs occur twice, and none @@ -432,7 +432,7 @@ xdg_mime_get_mime_type_for_file (const char *file_name, unsigned char *data; int max_extent; int bytes_read; - struct stat buf; + int is_regular_here; const char *base_name; int n; @@ -444,7 +444,7 @@ xdg_mime_get_mime_type_for_file (const char *file_name, xdg_mime_init (); if (_xdg_mime_caches) - return _xdg_mime_cache_get_mime_type_for_file (file_name, statbuf); + return _xdg_mime_cache_get_mime_type_for_file (file_name, is_regular); base_name = _xdg_get_base_name (file_name); n = _xdg_glob_hash_lookup_file_name (global_hash, base_name, mime_types, 5); @@ -452,15 +452,18 @@ xdg_mime_get_mime_type_for_file (const char *file_name, if (n == 1) return mime_types[0]; - if (!statbuf) + if (!is_regular) { - if (XDG_MIME_STAT (file_name, &buf) != 0) + struct stat statbuf; + + if (XDG_MIME_STAT (file_name, &statbuf) != 0) return XDG_MIME_TYPE_UNKNOWN; - statbuf = &buf; + is_regular_here = S_ISREG (statbuf.st_mode); + is_regular = &is_regular_here; } - if (!S_ISREG (statbuf->st_mode)) + if (!*is_regular) return XDG_MIME_TYPE_UNKNOWN; /* FIXME: Need to make sure that max_extent isn't totally broken. This could diff --git a/moo/xdgmime/xdgmime.h b/moo/xdgmime/xdgmime.h index d3031a38..8fa3aa91 100644 --- a/moo/xdgmime/xdgmime.h +++ b/moo/xdgmime/xdgmime.h @@ -83,7 +83,7 @@ const char *xdg_mime_get_mime_type_for_data (const void *data, size_t len, int *result_prio); const char *xdg_mime_get_mime_type_for_file (const char *file_name, - struct stat *statbuf); + int *is_regular); const char *xdg_mime_get_mime_type_from_file_name (const char *file_name); int xdg_mime_get_mime_types_from_file_name(const char *file_name, const char *mime_types[], diff --git a/moo/xdgmime/xdgmimecache.c b/moo/xdgmime/xdgmimecache.c index b63348b8..fccd15c5 100644 --- a/moo/xdgmime/xdgmimecache.c +++ b/moo/xdgmime/xdgmimecache.c @@ -662,7 +662,7 @@ _xdg_mime_cache_get_mime_type_for_data (const void *data, const char * _xdg_mime_cache_get_mime_type_for_file (const char *file_name, - struct stat *statbuf) + int *is_regular) { const char *mime_type; const char *mime_types[10]; @@ -670,7 +670,7 @@ _xdg_mime_cache_get_mime_type_for_file (const char *file_name, unsigned char *data; int max_extent; int bytes_read; - struct stat buf; + int is_regular_here; const char *base_name; int n; @@ -686,15 +686,18 @@ _xdg_mime_cache_get_mime_type_for_file (const char *file_name, if (n == 1) return mime_types[0]; - if (!statbuf) + if (!is_regular) { - if (XDG_MIME_STAT (file_name, &buf) != 0) + struct stat statbuf; + + if (XDG_MIME_STAT (file_name, &statbuf) != 0) return XDG_MIME_TYPE_UNKNOWN; - statbuf = &buf; + is_regular_here = S_ISREG (statbuf.st_mode); + is_regular = &is_regular_here; } - if (!S_ISREG (statbuf->st_mode)) + if (!*is_regular) return XDG_MIME_TYPE_UNKNOWN; /* FIXME: Need to make sure that max_extent isn't totally broken. This could diff --git a/moo/xdgmime/xdgmimecache.h b/moo/xdgmime/xdgmimecache.h index f0589d36..34077cca 100644 --- a/moo/xdgmime/xdgmimecache.h +++ b/moo/xdgmime/xdgmimecache.h @@ -60,7 +60,7 @@ const char *_xdg_mime_cache_get_mime_type_for_data (const void *data, size_t len, int *result_prio); const char *_xdg_mime_cache_get_mime_type_for_file (const char *file_name, - struct stat *statbuf); + int *is_regular); int _xdg_mime_cache_get_mime_types_from_file_name (const char *file_name, const char *mime_types[], int n_mime_types); diff --git a/moo/xdgmime/xdgmimeint.h b/moo/xdgmime/xdgmimeint.h index c5ee7f96..376c3f8c 100644 --- a/moo/xdgmime/xdgmimeint.h +++ b/moo/xdgmime/xdgmimeint.h @@ -186,26 +186,7 @@ _xdg_reverse_ucs4 (xdg_unichar_t *source, int len) } #ifdef __WIN32__ -#include - -inline static int -_xdg_mime_stat (const char *path, - struct stat *buf) -{ - errno = 0; - return moo_stat (path, buf); -} - -inline static int -_xdg_mime_fstat (int fd, - struct stat *buf) -{ - errno = 0; - return fstat (fd, buf); -} - -#define XDG_MIME_STAT _xdg_mime_stat -#define XDG_MIME_FSTAT _xdg_mime_fstat +#error "xdgmime can't be used on windows" #else #define XDG_MIME_STAT stat #define XDG_MIME_FSTAT fstat