+2007-12-08 Hans Breuer <hans@breuer.org>
+
+ [gio compiles and links on win32, not sure how much already works]
+ * glocaldirectorymonitor.c : ifdefed out inotify emulation for win32
+ * glocalfile.c : use HAVE_UNISTD_H; implement file system size info
+ base on win32 API; prefer g_lstat() over lstat(); instead of
+ localtime_r() use an all GLib implementation on win32;
+ get_mount_info() still needs a win32 specifc implementation
+ * glocalfileinfo.c : use HAVE_*_H; start of implementation of
+ win32_get_file_user_info to get owner/group info without uid/gid
+ * glocalfileinputstream.c : include <io.h> on win32
+ * glocalfileoutputstream.c : include <io.h> on win32 and some S_IS*
+ definition, use g_win32_ftruncate() for G_OS_WIN32
+ * gwin32appinfo.c : optionalize a bunch on #ifdef AssocQueryString
+ it is available with mingw/w32api but a mess with the M$ Platform SDKs
+ see: http://mail.gnome.org/archives/gtk-devel-list/2007-December/msg00014.html
+ * makefile.msc : updated
+
2007-12-07 Alexander Larsson <alexl@redhat.com>
* glocalfileenumerator.c (_g_local_file_enumerator_new):
if (!klass->mount_notify)
{
+#ifdef G_OS_WIN32
+ g_warning ("G_OS_WIN32: no mount emulation");
+#else
GUnixMount *mount;
/* Emulate unmount detection */
local_monitor->mount_monitor = g_unix_mount_monitor_new ();
g_signal_connect (local_monitor->mount_monitor, "mounts_changed",
G_CALLBACK (mounts_changed), local_monitor);
+#endif
}
return obj;
GFile *file;
/* Emulate unmount detection */
-
+#ifdef G_OS_WIN32
+ mount = NULL;
+ g_warning ("G_OS_WIN32: no mount emulation");
+#else
mount = g_get_unix_mount_at (local_monitor->dirname, NULL);
is_mounted = mount != NULL;
if (mount)
g_unix_mount_free (mount);
+#endif
if (local_monitor->was_mounted != is_mounted)
{
#include <string.h>
#include <errno.h>
#include <fcntl.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
#if HAVE_SYS_STATFS_H
#include <sys/statfs.h>
#include <glib/gstdio.h>
#include "glibintl.h"
+#ifdef G_OS_WIN32
+#include <windows.h>
+#include <io.h>
+#include <direct.h>
+
+#ifndef S_ISDIR
+#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
+#endif
+#ifndef S_ISLNK
+#define S_ISLNK(m) (0)
+#endif
+#endif
+
#include "gioalias.h"
static void g_local_file_file_iface_init (GFileIface *iface);
GUnixMount *mount;
guint64 cache_time;
- if (lstat (path, &buf) != 0)
+ if (g_lstat (path, &buf) != 0)
return;
G_LOCK (mount_info_hash);
if (g_file_attribute_matcher_matches (attribute_matcher,
G_FILE_ATTRIBUTE_FS_FREE))
- g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FS_FREE, block_size * statfs_buffer.f_bavail);
+ {
+#ifdef G_OS_WIN32
+ gchar *localdir = g_path_get_dirname (local->filename);
+ wchar_t *wdirname = g_utf8_to_utf16 (localdir, -1, NULL, NULL, NULL);
+ ULARGE_INTEGER li;
+
+ g_free (localdir);
+ if (GetDiskFreeSpaceExW (wdirname, &li, NULL, NULL))
+ g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FS_FREE, (guint64)li.QuadPart);
+ g_free (wdirname);
+#else
+ g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FS_FREE, block_size * statfs_buffer.f_bavail);
+#endif
+ }
if (g_file_attribute_matcher_matches (attribute_matcher,
G_FILE_ATTRIBUTE_FS_SIZE))
- g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FS_SIZE, block_size * statfs_buffer.f_blocks);
-
+ {
+#ifdef G_OS_WIN32
+ gchar *localdir = g_path_get_dirname (local->filename);
+ wchar_t *wdirname = g_utf8_to_utf16 (localdir, -1, NULL, NULL, NULL);
+ ULARGE_INTEGER li;
+
+ g_free (localdir);
+ if (GetDiskFreeSpaceExW (wdirname, NULL, &li, NULL))
+ g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FS_SIZE, (guint64)li.QuadPart);
+ g_free (wdirname);
+#else
+ g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FS_SIZE, block_size * statfs_buffer.f_blocks);
+#endif
+ }
#ifdef USE_STATFS
fstype = get_fs_type (statfs_buffer.f_type);
if (fstype &&
if (g_file_attribute_matcher_matches (attribute_matcher,
G_FILE_ATTRIBUTE_FS_READONLY))
{
+#ifdef G_OS_WIN32
+ /* need to implement with *unix_mount* */
+#else
get_mount_info (info, local->filename, attribute_matcher);
+#endif
}
g_file_attribute_matcher_unref (attribute_matcher);
char *mountpoint;
GVolume *volume;
- if (lstat (local->filename, &buf) != 0)
+ if (g_lstat (local->filename, &buf) != 0)
{
g_set_error (error, G_IO_ERROR,
G_IO_ERROR_NOT_FOUND,
{
char *resolved, *canonical, *parent, *link2;
char symlink_value[4096];
+#ifdef G_OS_WIN32
+#else
ssize_t res;
+#endif
+#ifdef G_OS_WIN32
+#else
res = readlink (link, symlink_value, sizeof (symlink_value) - 1);
+
if (res == -1)
return g_strdup (link);
symlink_value[res] = 0;
+#endif
if (g_path_is_absolute (symlink_value))
return canonicalize_filename (symlink_value);
char *trashdir, *globaldir, *topdir, *infodir, *filesdir;
char *basename, *trashname, *trashfile, *infoname, *infofile;
char *original_name, *original_name_escaped;
- uid_t uid;
- char uid_str[32];
int i;
char *data;
gboolean is_homedir_trash;
- time_t t;
- struct tm now;
char delete_time[32];
int fd;
}
else
{
+#ifdef G_OS_WIN32
+ g_warning ("Recycle bin not implemented");
+#else
+ uid_t uid;
+ char uid_str[32];
+
uid = geteuid ();
g_snprintf (uid_str, sizeof (uid_str), "%lu", (unsigned long)uid);
trashdir = NULL;
}
}
+#endif
if (trashdir == NULL)
{
g_free (original_name);
g_free (topdir);
- t = time (NULL);
- localtime_r (&t, &now);
- delete_time[0] = 0;
- strftime(delete_time, sizeof (delete_time), "%Y-%m-%dT%H:%M:%S", &now);
+#ifdef G_OS_WIN32
+ {
+ GTimeVal now;
+ g_get_current_time (&now);
+ strncpy (delete_time, g_time_val_to_iso8601 (&now), sizeof (delete_time));
+ }
+#else
+ {
+ time_t t;
+ struct tm now;
+ t = time (NULL);
+ localtime_r (&t, &now);
+ delete_time[0] = 0;
+ strftime(delete_time, sizeof (delete_time), "%Y-%m-%dT%H:%M:%S", &now);
+ }
+#endif
data = g_strdup_printf ("[Trash Info]\nPath=%s\nDeletionDate=%s\n",
original_name_escaped, delete_time);
#include <config.h>
+#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
+#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
#include <fcntl.h>
#include <errno.h>
#ifdef HAVE_GRP_H
#include "glibintl.h"
+#ifdef G_OS_WIN32
+#include <windows.h>
+#include <io.h>
+#ifndef W_OK
+#define W_OK 2
+#endif
+#ifndef R_OK
+#define R_OK 4
+#endif
+#ifndef X_OK
+#define X_OK 0 /* not really */
+#endif
+#ifndef S_ISREG
+#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
+#endif
+#ifndef S_ISDIR
+#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
+#endif
+#ifndef S_IXUSR
+#define S_IXUSR _S_IEXEC
+#endif
+#endif
+
#include "glocalfileinfo.h"
#include "gioerror.h"
#include "gthemedicon.h"
guint32 bits[2];
unsigned char in[64];
};
-
+#ifndef G_OS_WIN32
typedef struct {
char *user_name;
char *real_name;
} UidData;
-
+#endif
G_LOCK_DEFINE_STATIC (uid_cache);
static GHashTable *uid_cache = NULL;
*/
if (res == 0)
{
+#ifdef S_ISVTX
parent_info->is_sticky = (statbuf.st_mode & S_ISVTX) != 0;
+#else
+ parent_info->is_sticky = FALSE;
+#endif
parent_info->owner = statbuf.st_uid;
parent_info->device = statbuf.st_dev;
}
{
if (parent_info->is_sticky)
{
+#ifndef G_OS_WIN32
uid_t uid = geteuid ();
if (uid == statbuf->st_uid ||
uid == parent_info->owner ||
uid == 0)
+#endif
writable = TRUE;
}
else
file_type = G_FILE_TYPE_REGULAR;
else if (S_ISDIR (statbuf->st_mode))
file_type = G_FILE_TYPE_DIRECTORY;
+#ifndef G_OS_WIN32
else if (S_ISCHR (statbuf->st_mode) ||
S_ISBLK (statbuf->st_mode) ||
S_ISFIFO (statbuf->st_mode)
#endif
)
file_type = G_FILE_TYPE_SPECIAL;
+#endif
#ifdef S_ISLNK
else if (S_ISLNK (statbuf->st_mode))
file_type = G_FILE_TYPE_SYMBOLIC_LINK;
return utf8_string;
}
-
+#ifndef G_OS_WIN32
static void
uid_data_free (UidData *data)
{
return res;
}
-
/* called with lock held */
static char *
lookup_gid_name (gid_t gid)
G_UNLOCK (gid_cache);
return res;
}
+#endif /* !G_OS_WIN32 */
static char *
get_content_type (const char *basename,
return g_strdup ("inode/symlink");
else if (S_ISDIR(statbuf->st_mode))
return g_strdup ("inode/directory");
+#ifndef G_OS_WIN32
else if (S_ISCHR(statbuf->st_mode))
return g_strdup ("inode/chardevice");
else if (S_ISBLK(statbuf->st_mode))
return g_strdup ("inode/blockdevice");
else if (S_ISFIFO(statbuf->st_mode))
return g_strdup ("inode/fifo");
+#endif
#ifdef S_ISSOCK
else if (S_ISSOCK(statbuf->st_mode))
return g_strdup ("inode/socket");
g_free (filename);
}
+void
+win32_get_file_user_info (const gchar* filename,
+ gchar **group_name,
+ gchar **user_name,
+ gchar **real_name)
+{
+ PSECURITY_DESCRIPTOR psd = NULL;
+ DWORD sd_size = 0; /* first call calculates the size rewuired */
+
+ wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
+ if ((GetFileSecurityW (wfilename,
+ GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION,
+ NULL,
+ sd_size,
+ &sd_size) || (ERROR_INSUFFICIENT_BUFFER == GetLastError())) &&
+ (psd = g_try_malloc (sd_size)) != NULL &&
+ GetFileSecurityW (wfilename,
+ GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION,
+ psd,
+ sd_size,
+ &sd_size))
+ {
+ PSID psid = 0;
+ SID_NAME_USE name_use; /* don't care? */
+ char *name = NULL;
+ DWORD name_len = 0;
+ if (user_name &&
+ GetSecurityDescriptorOwner (psd, &psid, NULL) &&
+ (LookupAccountSid (NULL, /* local machine */
+ psid,
+ name, &name_len,
+ NULL, NULL, /* no domain info yet */
+ &name_use) || (ERROR_INSUFFICIENT_BUFFER == GetLastError())) &&
+ (name = g_try_malloc (name_len)) != NULL &&
+ LookupAccountSid (NULL, /* local machine */
+ psid,
+ name, &name_len,
+ NULL, NULL, /* no domain info yet */
+ &name_use))
+ {
+ *user_name = name;
+ }
+ g_free (psd);
+ }
+ g_free (wfilename);
+}
GFileInfo *
_g_local_file_info_get (const char *basename,
if (g_file_attribute_matcher_matches (attribute_matcher,
G_FILE_ATTRIBUTE_OWNER_USER))
{
- char *name;
+ char *name = NULL;
+#ifdef G_OS_WIN32
+ win32_get_file_user_info (path, NULL, &name, NULL);
+#else
name = get_username_from_uid (statbuf.st_uid);
+#endif
if (name)
g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_USER, name);
g_free (name);
if (g_file_attribute_matcher_matches (attribute_matcher,
G_FILE_ATTRIBUTE_OWNER_USER_REAL))
{
- char *name;
-
+ char *name = NULL;
+#ifdef G_OS_WIN32
+ win32_get_file_user_info (path, NULL, NULL, &name);
+#else
name = get_realname_from_uid (statbuf.st_uid);
+#endif
if (name)
g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_USER_REAL, name);
g_free (name);
if (g_file_attribute_matcher_matches (attribute_matcher,
G_FILE_ATTRIBUTE_OWNER_GROUP))
{
- char *name;
-
+ char *name = NULL;
+#ifdef G_OS_WIN32
+ win32_get_file_user_info (path, &name, NULL, NULL);
+#else
name = get_groupname_from_gid (statbuf.st_gid);
+#endif
if (name)
g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_GROUP, name);
g_free (name);
#include "glocalfileinfo.h"
#include "glibintl.h"
+#ifdef G_OS_WIN32
+#include <io.h>
+#endif
+
#include "gioalias.h"
#define g_local_file_input_stream_get_type _g_local_file_input_stream_get_type
#include "glocalfileoutputstream.h"
#include "glocalfileinfo.h"
+#ifdef G_OS_WIN32
+#include <io.h>
+#ifndef S_ISDIR
+#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
+#endif
+#ifndef S_ISREG
+#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
+#endif
+#endif
+
#include "gioalias.h"
#define g_local_file_output_stream_get_type _g_local_file_output_stream_get_type
file = G_LOCAL_FILE_OUTPUT_STREAM (stream);
restart:
+#ifdef G_OS_WIN32
+ res = g_win32_ftruncate (file->priv->fd, size);
+#else
res = ftruncate (file->priv->fd, size);
+#endif
if (res == -1)
{
}
/* Truncate the file at the start */
+#ifdef G_OS_WIN32
+ if (g_win32_ftruncate (fd, 0) == -1)
+#else
if (ftruncate (fd, 0) == -1)
+#endif
{
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
#include "gcontenttypeprivate.h"
#include "gwin32appinfo.h"
#include "gioerror.h"
+#include "gfile.h"
#include <glib/gstdio.h>
#include "glibintl.h"
#define REAL_ASSOCSTR_FRIENDLYDOCNAME 3
#define REAL_ASSOCSTR_FRIENDLYAPPNAME 4
+#ifndef AssocQueryString
+#pragma message("AssocQueryString not available with SDK used")
+#endif
static void g_win32_app_info_iface_init (GAppInfoIface *iface);
g_desktop_app_info_new_from_id (wchar_t *id /* takes ownership */,
gboolean id_is_exename)
{
+#ifdef AssocQueryString
ASSOCF flags;
+#endif
wchar_t buffer[1024];
DWORD buffer_size;
GWin32AppInfo *info;
info->id_utf8 = g_utf16_to_utf8 (id, -1, NULL, NULL, NULL);
info->id_is_exename = id_is_exename;
+#ifdef AssocQueryString
flags = 0;
if (id_is_exename)
flags |= ASSOCF_INIT_BYEXENAME;
buffer,
&buffer_size) == S_OK)
info->name = g_utf16_to_utf8 (buffer, -1, NULL, NULL, NULL);
+#endif
if (info->name == NULL)
{
info->name = g_strdup (info->id_utf8);
}
+#ifdef AssocQueryString
if (AssocQueryKeyW(flags,
ASSOCKEY_APP,
info->id,
info->no_open_with = TRUE;
RegCloseKey (app_key);
}
+#endif
return G_APP_INFO (info);
}
GError **error)
{
GWin32AppInfo *info = G_WIN32_APP_INFO (appinfo);
+#ifdef AssocQueryString
ASSOCF flags;
+#endif
HKEY class_key;
SHELLEXECUTEINFOW exec_info = {0};
GList *l;
/* TODO: What might startup_id mean on win32? */
-
+#ifdef AssocQueryString
flags = 0;
if (info->id_is_exename)
flags |= ASSOCF_INIT_BYEXENAME;
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Can't find application"));
return FALSE;
}
+#endif
- for (l = file; l != NULL; l = l->next)
+ for (l = files; l != NULL; l = l->next)
{
char *path = g_file_get_path (l->data);
wchar_t *wfilename = g_utf8_to_utf16 (path, -1, NULL, NULL, NULL);
wtype = g_utf8_to_utf16 (content_type, -1, NULL, NULL, NULL);
/* Verify that we have some sort of app registered for this type */
+#ifdef AssocQueryString
buffer_size = 1024;
if (AssocQueryStringW (0,
REAL_ASSOCSTR_COMMAND,
&buffer_size) == S_OK)
/* Takes ownership of wtype */
return g_desktop_app_info_new_from_id (wtype, FALSE);
+#endif
g_free (wtype);
return NULL;
cd ..
INCLUDES = \
+ -FImsvc_recommended_pragmas.h \
-I .. -I ..\glib -I ..\gmodule -I . \
$(INTL_CFLAGS)
glocalfileinfo.obj \
glocalfileinputstream.obj \
glocalfileoutputstream.obj \
+ glocalfilemonitor.obj \
+ glocaldirectorymonitor.obj \
gwin32appinfo.obj \
\
gio-marshal.obj
$(CC) $(CFLAGS) -LD -Felibgio-$(PKG_VER).dll $(OBJECTS) \
..\glib\glib-2.0.lib ..\gobject\gobject-2.0.lib ..\gmodule\gmodule-2.0.lib \
$(INTL_LIBS) \
- user32.lib advapi32.lib wsock32.lib $(LDFLAGS) /def:$(PACKAGE).def
+ user32.lib advapi32.lib shell32.lib wsock32.lib $(LDFLAGS) /def:$(PACKAGE).def
.c.obj :
$(CC) $(CFLAGS) -GD -c $(PKG_CFLAGS) $<