[monkey-bubble: 721/753] Port to Windows, initial commit.
- From: Sven Herzberg <herzi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [monkey-bubble: 721/753] Port to Windows, initial commit.
- Date: Wed, 14 Jul 2010 22:56:18 +0000 (UTC)
commit 3c5e572503c65ab41922d9f83f067592c31fc049
Author: Tor Lillqvist <tml novell com>
Date: Mon Mar 28 15:45:07 2005 +0000
Port to Windows, initial commit.
2005-03-28 Tor Lillqvist <tml novell com>
Port to Windows, initial commit.
* configure.in: Bump version to 2.11.0 to distinguish from the
gnome-2-10 branch. Define Automake conditional OS_WIN32. Depend on
GLib 2.6 so that we can use the gstdio.h wrappers to make
non-ASCII path names work better on Win32.
* libgnome-zip.in: New file, to build libgnome distribution for
Win32.
* Makefile.am
* configure.in: Distribute and expand it.
* configure.in
* libgnome/libgnome-2.0.pc.in
* libgnome/gnome-init.c
* libgnome/gnome-open.c: Try to manage without gnome-vfs on Win32,
at least for now.
* libgnome/gnome-config.c
* libgnome/gnome-init.c
* libgnome/gnome-score.c
* libgnome/gnome-triggers.c: Use gstdio wrappers. Use GLib
pathname manipulation functions where applicable. Use gdir
functions. Accept both the canonical backslash and slash as path
compinent separators on Win32.
* libgnome/dllmain.c: New file. Contains the Win32 DLL entry
point, which is used here to implement installation location
independence. Sets up run-time paths to libdir, sysconfdir etc.
* libgnome/libgnome-private.h: New file. On Win32 undefs the
compile-time definitions of directory pathnames and defines them
to point to the run-time ones instead.
* libgnome/gnome-init.c
* libgnome/gnome-program.c
* libgnome/gnome-score.c: Include libgnome-private.h.
* libgnome/gnome-exec.c (gnome_execute_async_with_env_fds,
gnome_prepend_terminal_to_vector): Just stub out with g_warning()
on Win32 for now. Implement later if needed.
* libgnome/gnome-program.c: Dummy getuid/geteuid/getgid/getegid
definitions for Win32. No setuid or setgid concept.
* libgnome/gnome-score.c (log_score): Use ftruncate() on Unix,
_chsize() on Win32.
(gnome_score_child_thread, gnome_score_init): Use a thread on
Win32 where we have no fork().
(gnome_score_log): No setgid concept on Win32, no need to check.
* libgnome/gnome-triggers.c: Use g_spawn_sync() on Win32.
* libgnome/gnome-url.c (gnome_url_show_with_env): Use
ShellExecute() on Win32.
* libgnome/gnome-util.c (gnome_util_user_shell): Look for cmd.exe
or command.com on Win32.
* schemas/Makefile.am (install-data-local): Work around MSYS
feature on Win32. It converts environment variables that look like
search paths into the Windows format (with semicoon
delimiters). The GCONFIG_CONFIG_SOURCE would get mangled, so we
have to run gconftool-2 through temporary .bat file.
libgnome/gnome-score.c | 75 +++++++++++++++++++++++++++++++++++++++---------
1 files changed, 61 insertions(+), 14 deletions(-)
---
diff --git a/libgnome/gnome-score.c b/libgnome/gnome-score.c
index 830c5ea..41ac830 100644
--- a/libgnome/gnome-score.c
+++ b/libgnome/gnome-score.c
@@ -35,6 +35,7 @@
#include <stdlib.h>
#include <string.h>
#include <glib.h>
+#include <glib/gstdio.h>
#include <locale.h>
#ifdef HAVE_SYS_FSUID_H
#ifdef HAVE_SETFSGID
@@ -47,12 +48,24 @@
#include "gnome-score.h"
#include "gnome-util.h"
+#ifdef G_OS_WIN32
+#include <fcntl.h>
+#include <io.h>
+
+/* Microsoft's strtok() *is* thread-safe, it uses a thread-local
+ * buffer. "Use" the third argument to this macro so gcc doesn't
+ * complain about an unused variable, and we don't have to ifdef out
+ * the definition.
+ */
+#define strtok_r(s, delim, ptrptr) (*(ptrptr) = strtok (s, delim))
+#endif
+
+#include "libgnome-private.h"
+
#ifndef NSCORES
#define NSCORES 10
#endif
-#define SCORE_PATH LIBGNOME_LOCALSTATEDIR "/games"
-
struct command
{
gfloat score;
@@ -77,10 +90,13 @@ static gchar *
gnome_get_score_file_name (const gchar * progname, const gchar * level)
{
if (level)
- return g_strconcat (SCORE_PATH "/",
- progname, ".", level, ".scores", NULL);
+ return g_strconcat (LIBGNOME_LOCALSTATEDIR,
+ G_DIR_SEPARATOR_S "games" G_DIR_SEPARATOR_S,
+ progname, ".", level, ".scores", NULL);
else
- return g_strconcat (SCORE_PATH "/", progname, ".scores", NULL);
+ return g_strconcat (LIBGNOME_LOCALSTATEDIR,
+ G_DIR_SEPARATOR_S "games" G_DIR_SEPARATOR_S,
+ progname, ".scores", NULL);
}
/* This must be wrapped in push_c_locale on the caller */
@@ -129,7 +145,7 @@ log_score (const gchar * progname, const gchar * level, gchar * username,
game_score_file = gnome_get_score_file_name (progname, level);
- infile = fopen (game_score_file, "r");
+ infile = g_fopen (game_score_file, "r");
if (infile)
{
/* make sure we read values from files in a consistent manner */
@@ -202,8 +218,12 @@ log_score (const gchar * progname, const gchar * level, gchar * username,
retval = 0;
/* we dont create the file; it must already exist */
- truncate (game_score_file, 0);
- outfile = fopen (game_score_file, "r+");
+ outfile = g_fopen (game_score_file, "r+");
+#ifndef G_OS_WIN32
+ ftruncate (fileno (outfile), 0);
+#else
+ _chsize (fileno (outfile), 0);
+#endif
if (outfile)
{
@@ -224,7 +244,8 @@ log_score (const gchar * progname, const gchar * level, gchar * username,
}
static int
-gnome_score_child (void)
+gnome_score_child (int infileno,
+ int outfileno)
{
struct command cmd;
gchar *level;
@@ -243,9 +264,9 @@ gnome_score_child (void)
realname = g_strdup (g_get_user_name ());
}
- while (read (STDIN_FILENO, &cmd, sizeof cmd) == sizeof(cmd)) {
+ while (read (infileno, &cmd, sizeof cmd) == sizeof(cmd)) {
level = g_new (char, cmd.level);
- if (read (STDIN_FILENO, level, cmd.level) != cmd.level) {
+ if (read (outfileno, level, cmd.level) != cmd.level) {
g_free (realname);
return EXIT_FAILURE;
}
@@ -255,7 +276,7 @@ gnome_score_child (void)
}
retval = log_score (defgamename, level, realname, cmd.score,
cmd.ordering);
- if (write(STDOUT_FILENO, &retval, sizeof retval) != sizeof retval) {
+ if (write(outfileno, &retval, sizeof retval) != sizeof retval) {
g_free (realname);
return EXIT_FAILURE;
}
@@ -266,9 +287,24 @@ gnome_score_child (void)
return EXIT_SUCCESS;
}
+#ifdef G_OS_WIN32
+
+static gpointer
+gnome_score_child_thread (gpointer data)
+{
+ int *a = data;
+
+ gnome_score_child (a[0], a[1]);
+
+ return NULL;
+}
+
+#endif
+
static void
drop_perms (void)
{
+#ifndef G_OS_WIN32
gid_t gid = getegid ();
setregid (getgid (), getgid ()); /* on some os'es (eg linux) this
@@ -282,6 +318,7 @@ drop_perms (void)
"get a real OS :)\n");
setgid (getgid ());
}
+#endif
}
/*********************** external functions **********************************/
@@ -324,6 +361,7 @@ gnome_score_init (const gchar * gamename)
}
outfd = outpipe[1];
infd = inpipe[0];
+#ifndef G_OS_WIN32
switch (fork ())
{
case 0:
@@ -334,7 +372,7 @@ gnome_score_init (const gchar * gamename)
close(inpipe[1]);
close(outpipe[0]);
close(outpipe[1]);
- exit (gnome_score_child ());
+ exit (gnome_score_child (STDIN_FILENO, STDOUT_FILENO));
case -1:
close (inpipe[0]);
close (inpipe[1]);
@@ -347,6 +385,13 @@ gnome_score_init (const gchar * gamename)
close(outpipe[0]);
close(inpipe[1]);
drop_perms ();
+#else
+ {
+ int a[2] = { outpipe[0], inpipe[1] };
+ g_thread_create (gnome_score_child_thread, a, FALSE, NULL);
+ }
+#endif
+
return 0;
}
@@ -372,11 +417,13 @@ gnome_score_log (gfloat score,
struct command cmd;
gint retval;
+#ifndef G_OS_WIN32
if (getgid () != getegid ())
{
g_error ("gnome_score_init must be called first thing in main()\n");
abort ();
}
+#endif
if (infd == -1 || outfd == -1)
return 0;
@@ -435,7 +482,7 @@ gnome_score_get_notable (const gchar * gamename,
infile_name = gnome_get_score_file_name (realname, level);
- infile = fopen (infile_name, "r");
+ infile = g_fopen (infile_name, "r");
g_free (infile_name);
if (infile)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]