[gio compiles and links on win32, not sure how much already works] ifdefed

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


svn path=/trunk/; revision=6070
This commit is contained in:
Hans Breuer 2007-12-08 12:01:06 +00:00 committed by Hans Breuer
parent ef602a8cdd
commit a33f8a7564
8 changed files with 251 additions and 26 deletions

View File

@ -1,3 +1,21 @@
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):

View File

@ -112,6 +112,9 @@ g_local_directory_monitor_constructor (GType type,
if (!klass->mount_notify)
{
#ifdef G_OS_WIN32
g_warning ("G_OS_WIN32: no mount emulation");
#else
GUnixMount *mount;
/* Emulate unmount detection */
@ -126,6 +129,7 @@ g_local_directory_monitor_constructor (GType type,
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;
@ -165,13 +169,17 @@ mounts_changed (GUnixMountMonitor *mount_monitor,
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)
{

View File

@ -27,7 +27,9 @@
#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>
@ -77,6 +79,19 @@
#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);
@ -683,7 +698,7 @@ get_mount_info (GFileInfo *fs_info,
GUnixMount *mount;
guint64 cache_time;
if (lstat (path, &buf) != 0)
if (g_lstat (path, &buf) != 0)
return;
G_LOCK (mount_info_hash);
@ -797,11 +812,36 @@ g_local_file_query_filesystem_info (GFile *file,
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 &&
@ -813,7 +853,11 @@ g_local_file_query_filesystem_info (GFile *file,
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);
@ -831,7 +875,7 @@ g_local_file_find_enclosing_volume (GFile *file,
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,
@ -1114,12 +1158,19 @@ expand_symlink (const char *link)
{
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);
@ -1355,13 +1406,9 @@ g_local_file_trash (GFile *file,
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;
@ -1403,6 +1450,12 @@ g_local_file_trash (GFile *file,
}
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);
@ -1464,6 +1517,7 @@ g_local_file_trash (GFile *file,
trashdir = NULL;
}
}
#endif
if (trashdir == NULL)
{
@ -1564,10 +1618,22 @@ g_local_file_trash (GFile *file,
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);

View File

@ -22,11 +22,15 @@
#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
@ -56,6 +60,29 @@
#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"
@ -69,12 +96,12 @@ struct ThumbMD5Context {
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;
@ -769,7 +796,11 @@ _g_local_file_info_get_parent_info (const char *dir,
*/
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;
}
@ -808,11 +839,13 @@ get_access_rights (GFileAttributeMatcher *attribute_matcher,
{
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
@ -847,6 +880,7 @@ set_info_from_stat (GFileInfo *info,
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)
@ -855,6 +889,7 @@ set_info_from_stat (GFileInfo *info,
#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;
@ -977,7 +1012,7 @@ convert_pwd_string_to_utf8 (char *pwd_str)
return utf8_string;
}
#ifndef G_OS_WIN32
static void
uid_data_free (UidData *data)
{
@ -1075,7 +1110,6 @@ get_realname_from_uid (uid_t uid)
return res;
}
/* called with lock held */
static char *
lookup_gid_name (gid_t gid)
@ -1125,6 +1159,7 @@ get_groupname_from_gid (gid_t gid)
G_UNLOCK (gid_cache);
return res;
}
#endif /* !G_OS_WIN32 */
static char *
get_content_type (const char *basename,
@ -1140,12 +1175,14 @@ 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");
@ -1228,6 +1265,52 @@ get_thumbnail_attributes (const char *path,
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,
@ -1416,9 +1499,13 @@ _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);
@ -1427,9 +1514,12 @@ _g_local_file_info_get (const char *basename,
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);
@ -1438,9 +1528,12 @@ _g_local_file_info_get (const char *basename,
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);

View File

@ -37,6 +37,10 @@
#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

View File

@ -38,6 +38,16 @@
#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
@ -365,7 +375,11 @@ g_local_file_output_stream_truncate (GFileOutputStream *stream,
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)
{
@ -805,7 +819,11 @@ handle_overwrite_open (const char *filename,
}
/* 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),

View File

@ -27,6 +27,7 @@
#include "gcontenttypeprivate.h"
#include "gwin32appinfo.h"
#include "gioerror.h"
#include "gfile.h"
#include <glib/gstdio.h>
#include "glibintl.h"
@ -45,6 +46,9 @@
#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);
@ -97,7 +101,9 @@ static GAppInfo *
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;
@ -108,6 +114,7 @@ g_desktop_app_info_new_from_id (wchar_t *id /* takes ownership */,
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;
@ -129,6 +136,7 @@ g_desktop_app_info_new_from_id (wchar_t *id /* takes ownership */,
buffer,
&buffer_size) == S_OK)
info->name = g_utf16_to_utf8 (buffer, -1, NULL, NULL, NULL);
#endif
if (info->name == NULL)
{
@ -139,6 +147,7 @@ g_desktop_app_info_new_from_id (wchar_t *id /* takes ownership */,
info->name = g_strdup (info->id_utf8);
}
#ifdef AssocQueryString
if (AssocQueryKeyW(flags,
ASSOCKEY_APP,
info->id,
@ -150,6 +159,7 @@ g_desktop_app_info_new_from_id (wchar_t *id /* takes ownership */,
info->no_open_with = TRUE;
RegCloseKey (app_key);
}
#endif
return G_APP_INFO (info);
}
@ -245,13 +255,15 @@ g_win32_app_info_launch (GAppInfo *appinfo,
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;
@ -265,8 +277,9 @@ g_win32_app_info_launch (GAppInfo *appinfo,
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);
@ -593,6 +606,7 @@ g_app_info_get_default_for_type (const char *content_type,
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,
@ -602,6 +616,7 @@ g_app_info_get_default_for_type (const char *content_type,
&buffer_size) == S_OK)
/* Takes ownership of wtype */
return g_desktop_app_info_new_from_id (wtype, FALSE);
#endif
g_free (wtype);
return NULL;

View File

@ -16,6 +16,7 @@ sub-one:
cd ..
INCLUDES = \
-FImsvc_recommended_pragmas.h \
-I .. -I ..\glib -I ..\gmodule -I . \
$(INTL_CFLAGS)
@ -120,6 +121,8 @@ OBJECTS = \
glocalfileinfo.obj \
glocalfileinputstream.obj \
glocalfileoutputstream.obj \
glocalfilemonitor.obj \
glocaldirectorymonitor.obj \
gwin32appinfo.obj \
\
gio-marshal.obj
@ -248,7 +251,7 @@ libgio-$(PKG_VER).dll : $(OBJECTS) $(PACKAGE).def
$(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) $<