--- egg/egg-secure-memory.c	2012-11-12 07:30:20 +0000
+++ egg/egg-secure-memory.c	2013-10-21 19:20:38 +0000
@@ -32,7 +32,12 @@
 #include "egg-secure-memory.h"
 
 #include <sys/types.h>
+#ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>
+#endif
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
 #include <stddef.h>
 #include <string.h>
 #include <stdio.h>
@@ -188,9 +193,18 @@
 	
 	/* Create a new pool */
 	if (pool == NULL) {
+#ifdef G_OS_UNIX
 		len = getpagesize () * 2;
 		pages = mmap (0, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
 		if (pages == MAP_FAILED)
+#elif defined(G_OS_WIN32)
+		SYSTEM_INFO system_info;
+		GetSystemInfo (&system_info);
+
+		len = system_info.dwPageSize * 2;
+		pages = VirtualAlloc (NULL, (size_t)len, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
+		if (pages == NULL)
+#endif
 			return NULL;
 
 		/* Fill in the block header, and inlude in block list */
@@ -254,7 +268,11 @@
 		VALGRIND_DESTROY_MEMPOOL (pool);
 #endif
 
+#ifdef G_OS_UNIX
 		munmap (pool, pool->length);
+#elif defined(G_OS_WIN32)
+		VirtualFree (pool, 0, MEM_RELEASE);
+#endif
 		return;
 	}
 
@@ -861,7 +879,13 @@
 	ASSERT (during_tag);
 
 	/* Make sure sz is a multiple of the page size */
+#ifdef G_OS_UNIX
 	pgsize = getpagesize ();
+#elif defined(G_OS_WIN32)
+	SYSTEM_INFO system_info;
+	GetSystemInfo (&system_info);
+	pgsize = system_info.dwPageSize;
+#endif
 	*sz = (*sz + pgsize -1) & ~(pgsize - 1);
 	
 #if defined(HAVE_MLOCK)
@@ -902,7 +926,14 @@
 sec_release_pages (void *pages, size_t sz)
 {
 	ASSERT (pages);
+#ifdef G_OS_UNIX
 	ASSERT (sz % getpagesize () == 0);
+#elif defined(G_OS_WIN32)
+	SYSTEM_INFO system_info;
+	GetSystemInfo (&system_info);
+	ASSERT (sz % system_info.dwPageSize == 0);
+
+#endif
 	
 #if defined(HAVE_MLOCK)
 	if (munlock (pages, sz) < 0 && egg_secure_warnings)
@@ -914,7 +945,7 @@
 	DEBUG_ALLOC ("gkr-secure-memory: freed block ", sz);
 	
 #else
-	ASSERT (FALSE);
+	ASSERT (0);
 #endif
 }
 
--- egg/egg-asn1x.c	2012-11-12 07:30:20 +0000
+++ egg/egg-asn1x.c	2013-10-16 09:37:13 +0000
@@ -1842,6 +1842,22 @@
  * VALUE READ/WRITE
  */
 
+#ifndef HAVE_GMTIME_R
+struct tm*
+gmtime_r (const time_t *const timep, struct tm *p_tm)
+{
+	static struct tm* tmp;
+	tmp = gmtime (timep);
+	if (tmp)
+	{
+		memcpy (p_tm, tmp, sizeof(struct tm));
+		tmp = p_tm;
+	}
+
+	return tmp;
+}
+#endif
+
 static int
 two_to_four_digit_year (int year)
 {
--- egg/egg-asn1x.h	2012-11-12 07:30:20 +0000
+++ egg/egg-asn1x.h	2013-10-16 09:37:19 +0000
@@ -264,4 +264,8 @@
 		                     egg_asn1x_message (node) ? \
 		                     egg_asn1x_message (node) : "[no message]")
 
+#ifndef HAVE_GMTIME_R
+		extern struct tm* gmtime_r (const time_t *const timep, struct tm *p_tm);
+#endif
+
 #endif /*EGG_ASN1X_H_*/
--- egg/egg-armor.c	2012-09-19 09:01:27 +0000
+++ egg/egg-armor.c	2013-10-16 10:02:39 +0000
@@ -60,6 +60,19 @@
 #define ARMOR_PREF_END      "-----END "
 #define ARMOR_PREF_END_L    9
 
+#ifndef HAVE_MEMRCHR
+void*
+memrchr (const void *s, int c, size_t n)
+{
+	const unsigned char *src = s + n;
+	unsigned char uc = c;
+	while (--src >= (unsigned char *) s)
+		if (*src == uc)
+			return (void *) src;
+	return NULL;
+}
+#endif
+
 static void
 parse_header_lines (const gchar *hbeg,
                     const gchar *hend,
--- egg/tests/test-asn1x.c	2012-11-12 07:30:20 +0000
+++ egg/tests/test-asn1x.c	2013-10-16 09:55:04 +0000
@@ -27,7 +27,9 @@
 #include "egg/egg-asn1-defs.h"
 #include "egg/egg-testing.h"
 
+#ifdef HAVE_PWD_H
 #include <pwd.h>
+#endif
 #include <stdlib.h>
 #include <unistd.h>
 
--- gck/gck-slot.c	2012-10-27 13:03:06 +0000
+++ gck/gck-slot.c	2013-10-23 06:16:02 +0000
@@ -645,6 +645,129 @@
 	return token_info;
 }
 
+#ifndef HAVE_GMTIME_R
+struct tm*
+gmtime_r (const time_t *const timep, struct tm *p_tm)
+{
+	static struct tm *tmp;
+	tmp = gmtime (timep);
+	if (tmp)
+	{
+		memcpy (p_tm, tmp, sizeof(struct tm));
+		tmp = p_tm;
+	}
+
+	return tmp;
+}
+#endif
+
+#ifndef HAVE_TIMEGM
+time_t
+timegm (struct tm *p_tm)
+{
+	time_t tp;
+	time_t tz; char* tzc;
+
+	 tz = _timezone;
+	 tzc = (char *)&tz;
+	 _timezone = 0;
+
+	tp = mktime (p_tm);
+
+	 _timezone = *(time_t *)tzc;
+
+	return tp;
+}
+#endif
+
+#ifndef HAVE_STRPTIME
+int
+date_get_num (const char **pp, int n_min, int n_max, int len_max)
+{
+	int i, val, c;
+	const char *p;
+
+	p = *pp;
+	val = 0;
+	for(i = 0; i < len_max; i++) {
+		c = *p;
+		if (!(c >= '0' && c <= '9'))
+			break;
+		val = (val * 10) + c - '0';
+		p++;
+	}
+	/* no number read ? */
+	if (p == *pp)
+		return -1;
+	if (val < n_min || val > n_max)
+		return -1;
+	*pp = p;
+	return val;
+}
+
+const char *
+strptime (const char *p, const char *fmt, struct tm *dt)
+{
+	int c, val;
+
+	for(;;) {
+		c = *fmt++;
+		if (c == '\0') {
+			return p;
+		} else if (c == '%') {
+			c = *fmt++;
+			switch(c) {
+			case 'H':
+				val = date_get_num(&p, 0, 23, 2);
+				if (val == -1)
+					return NULL;
+				dt->tm_hour = val;
+				break;
+			case 'M':
+				val = date_get_num(&p, 0, 59, 2);
+				if (val == -1)
+					return NULL;
+				dt->tm_min = val;
+				break;
+			case 'S':
+				val = date_get_num(&p, 0, 59, 2);
+				if (val == -1)
+					return NULL;
+				dt->tm_sec = val;
+				break;
+			case 'Y':
+				val = date_get_num(&p, 0, 9999, 4);
+				if (val == -1)
+					return NULL;
+				dt->tm_year = val - 1900;
+				break;
+			case 'm':
+				val = date_get_num(&p, 1, 12, 2);
+				if (val == -1)
+					return NULL;
+				dt->tm_mon = val - 1;
+				break;
+			case 'd':
+				val = date_get_num(&p, 1, 31, 2);
+				if (val == -1)
+					return NULL;
+				dt->tm_mday = val;
+				break;
+			case '%':
+				goto match;
+			default:
+				return NULL;
+			}
+		} else {
+			match:
+				if (c != *p)
+					return NULL;
+				p++;
+			}
+		}
+}
+#endif
+
 void
 _gck_token_info_to_pkcs11 (GckTokenInfo *token_info, CK_TOKEN_INFO_PTR info)
 {
--- gck/gck-private.h	2012-09-19 09:01:28 +0000
+++ gck/gck-private.h	2013-10-21 19:58:38 +0000
@@ -210,4 +210,15 @@
 void               _gck_call_async_object                (GckCall *call,
                                                            gpointer object);
 
+#ifndef HAVE_GMTIME_R
+		extern struct tm* gmtime_r (const time_t *const timep, struct tm *p_tm);
+#endif
+#ifndef HAVE_TIMEGM
+		extern time_t timegm (struct tm *p_tm);
+#endif
+#ifndef HAVE_STRPTIME
+		extern int date_get_num (const char **pp, int n_min, int n_max, int len_max);
+		extern const char* strptime (const char *p, const char *fmt, struct tm *dt);
+#endif
+
 #endif /* GCK_PRIVATE_H_ */
--- gcr/gcr-gnupg-collection.c	2011-10-06 08:06:09 +0000
+++ gcr/gcr-gnupg-collection.c	2013-10-21 20:28:35 +0000
@@ -36,7 +36,9 @@
 #include "gcr-record.h"
 #include "gcr-util.h"
 
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <string.h>
 
 enum {
--- gcr/gcr-gnupg-process.c	2012-09-19 09:01:28 +0000
+++ gcr/gcr-gnupg-process.c	2013-10-22 05:48:43 +0000
@@ -31,11 +31,23 @@
 
 #include <glib/gi18n-lib.h>
 
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
 #include <fcntl.h>
 #include <errno.h>
 #include <string.h>
 
+#ifndef G_OS_UNIX
+#define WIFEXITED(x) ((unsigned)(x) < 259)
+#define WEXITSTATUS(x) ((x) & 0xff)
+#define WIFSIGNALED(x) ((unsigned)(x) > 259)
+#define WTERMSIG(x) SIGTERM
+#endif
+
 /**
  * GcrGnupgProcessFlags:
  * @GCR_GNUPG_PROCESS_NONE: No flags
@@ -895,6 +907,7 @@
 static void
 on_gnupg_process_child_setup (gpointer user_data)
 {
+#ifdef G_OS_UNIX 
 	int *child_fds = user_data;
 	long val;
 	guint i;
@@ -910,6 +923,7 @@
 			fcntl (child_fds[i], F_SETFD, val & ~FD_CLOEXEC);
 		}
 	}
+#endif
 }
 
 static void
@@ -930,7 +944,11 @@
 	if (gnupg_source->child_pid) {
 		_gcr_debug ("sending term signal to process: %d",
 		            (int)gnupg_source->child_pid);
+#if defined(G_OS_UNIX)
 		kill (gnupg_source->child_pid, SIGTERM);
+#elif defined(G_OS_WIN32)
+		TerminateProcess ((HANDLE)(gnupg_source->child_pid),0);
+#endif
 	}
 }
 
@@ -999,14 +1017,22 @@
 	child_fds[FD_ERROR] = 2;
 
 	if (flags & GCR_GNUPG_PROCESS_WITH_STATUS) {
+#if defined(G_OS_UNIX)
 		if (pipe (status_fds) < 0)
+#elif defined(G_OS_WIN32)
+		if (_pipe (status_fds, 4096, _O_BINARY) < 0)
+#endif
 			g_return_if_reached ();
 		child_fds[FD_STATUS] = status_fds[1];
 		g_ptr_array_add (args, g_strdup ("--status-fd"));
 		g_ptr_array_add (args, g_strdup_printf ("%d", child_fds[FD_STATUS]));
 	}
 	if (flags & GCR_GNUPG_PROCESS_WITH_ATTRIBUTES) {
+#if defined(G_OS_UNIX)
 		if (pipe (attribute_fds) < 0)
+#elif defined(G_OS_WIN32)
+		if (_pipe (attribute_fds, 4096, _O_BINARY) < 0)
+#endif
 			g_return_if_reached ();
 		child_fds[FD_ATTRIBUTE] = attribute_fds[1];
 		g_ptr_array_add (args, g_strdup ("--attribute-fd"));
@@ -1035,11 +1061,11 @@
 
 	if (_gcr_debugging) {
 		gchar *command = g_strjoinv (" ", (gchar**)args->pdata);
-		gchar *environ = g_strjoinv (", ", (gchar**)envs->pdata);
+		gchar *environment = g_strjoinv (", ", (gchar**)envs->pdata);
 		_gcr_debug ("running command: %s", command);
-		_gcr_debug ("process environment: %s", environ);
+		_gcr_debug ("process environment: %s", environment);
 		g_free (command);
-		g_free (environ);
+		g_free (environment);
 	}
 
 	g_spawn_async_with_pipes (self->pv->directory, (gchar**)args->pdata,
--- gcr/gcr-prompt-dialog.c	2012-11-12 07:30:20 +0000
+++ gcr/gcr-prompt-dialog.c	2013-10-22 07:21:16 +0000
@@ -30,7 +30,12 @@
 #include "gcr-secure-entry-buffer.h"
 
 #include <gtk/gtk.h>
+#if defined(GDK_WINDOWING_X11)
 #include <gdk/gdkx.h>
+#endif
+#if defined(GDK_WINDOWING_WIN32)
+#include <gdk/gdkwin32.h>
+#endif
 #include <glib/gi18n.h>
 
 /**
@@ -148,7 +153,11 @@
 	}
 
 	display = gtk_widget_get_display (GTK_WIDGET (self));
+#if defined(GDK_WINDOWING_X11)
 	transient_for = gdk_x11_window_foreign_new_for_display (display, (Window)handle);
+#elif defined(GDK_WINDOWING_WIN32)
+	transient_for = gdk_win32_window_foreign_new_for_display (display, (HWND)handle);
+#endif
 	if (transient_for == NULL) {
 		g_warning ("caller-window property doesn't represent a window on current display: %s",
 		           self->pv->caller_window);
--- gcr/gcr-prompter-tool.c	2012-11-12 07:30:20 +0000
+++ gcr/gcr-prompter-tool.c	2013-10-22 07:17:23 +0000
@@ -31,13 +31,17 @@
 
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
+#ifdef GDK_WINDOWING_X11
 #include <gdk/gdkx.h>
+#endif
 #include <pango/pango.h>
 
 #include <locale.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef HAVE_SYSLOG_H
 #include <syslog.h>
+#endif
 
 #define QUIT_TIMEOUT 10
 
@@ -139,6 +143,7 @@
              const gchar *message,
              gpointer user_data)
 {
+#ifdef HAVE_SYSLOG_H
 	int level;
 
 	/* Note that crit and err are the other way around in syslog */
@@ -172,6 +177,7 @@
 		syslog (level, "%s: %s", log_domain, message);
 	else
 		syslog (level, "%s", message);
+#endif
 
 	/* And then to default handler for aborting and stuff like that */
 	g_log_default_handler (log_domain, log_level, message, user_data);
@@ -180,9 +186,11 @@
 static void
 printerr_handler (const gchar *string)
 {
+#ifdef HAVE_SYSLOG_H
 	/* Print to syslog and stderr */
 	syslog (LOG_WARNING, "%s", string);
 	fprintf (stderr, "%s", string);
+#endif
 }
 
 static void
@@ -192,7 +200,9 @@
 	                       G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING |
 	                       G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO;
 
+#ifdef HAVE_SYSLOG_H
 	openlog ("gcr-prompter", LOG_PID, LOG_AUTH);
+#endif
 
 	g_log_set_handler (NULL, flags, log_handler, NULL);
 	g_log_set_handler ("Glib", flags, log_handler, NULL);
--- gcr/gcr-record.c	2012-09-19 09:01:28 +0000
+++ gcr/gcr-record.c	2013-10-22 06:46:21 +0000
@@ -861,3 +861,91 @@
 
 	return result;
 }
+
+#ifndef HAVE_STRPTIME
+int
+date_get_num (const char **pp, int n_min, int n_max, int len_max)
+{
+	int i, val, c;
+	const char *p;
+
+	p = *pp;
+	val = 0;
+	for(i = 0; i < len_max; i++) {
+		c = *p;
+		if (!(c >= '0' && c <= '9'))
+			break;
+		val = (val * 10) + c - '0';
+		p++;
+	}
+	/* no number read ? */
+	if (p == *pp)
+		return -1;
+	if (val < n_min || val > n_max)
+		return -1;
+	*pp = p;
+	return val;
+}
+
+const char *
+strptime (const char *p, const char *fmt, struct tm *dt)
+{
+	int c, val;
+
+	for(;;) {
+		c = *fmt++;
+		if (c == '\0') {
+			return p;
+		} else if (c == '%') {
+			c = *fmt++;
+			switch(c) {
+			case 'H':
+				val = date_get_num(&p, 0, 23, 2);
+				if (val == -1)
+					return NULL;
+				dt->tm_hour = val;
+				break;
+			case 'M':
+				val = date_get_num(&p, 0, 59, 2);
+				if (val == -1)
+					return NULL;
+				dt->tm_min = val;
+				break;
+			case 'S':
+				val = date_get_num(&p, 0, 59, 2);
+				if (val == -1)
+					return NULL;
+				dt->tm_sec = val;
+				break;
+			case 'Y':
+				val = date_get_num(&p, 0, 9999, 4);
+				if (val == -1)
+					return NULL;
+				dt->tm_year = val - 1900;
+				break;
+			case 'm':
+				val = date_get_num(&p, 1, 12, 2);
+				if (val == -1)
+					return NULL;
+				dt->tm_mon = val - 1;
+				break;
+			case 'd':
+				val = date_get_num(&p, 1, 31, 2);
+				if (val == -1)
+					return NULL;
+				dt->tm_mday = val;
+				break;
+			case '%':
+				goto match;
+			default:
+				return NULL;
+			}
+		} else {
+			match:
+				if (c != *p)
+					return NULL;
+				p++;
+			}
+		}
+}
+#endif
\ No newline at end of file
--- gcr/gcr-record.h	2011-10-06 08:06:09 +0000
+++ gcr/gcr-record.h	2013-10-22 06:48:16 +0000
@@ -275,6 +275,10 @@
 
 GcrRecord *    _gcr_records_find                (GPtrArray *records,
                                                  GQuark schema);
+#ifndef HAVE_STRPTIME
+		extern int date_get_num (const char **pp, int n_min, int n_max, int len_max);
+		extern const char* strptime (const char *p, const char *fmt, struct tm *dt);
+#endif
 
 G_END_DECLS
 
--- gcr/tests/frob-prompt.c	2012-11-12 07:30:20 +0000
+++ gcr/tests/frob-prompt.c	2013-10-23 06:48:28 +0000
@@ -27,15 +27,48 @@
 #include "gcr/gcr-base.h"
 
 #include <gtk/gtk.h>
+#ifdef GDK_WINDOWING_X11
 #include <gdk/gdkx.h>
+#endif
+#ifdef GDK_WINDOWING_WIN32
+#include <gdk/gdkwin32.h>
+#endif
 
+#if defined(HAVE_ERR_H)
 #include <err.h>
+#else
+#include <errno.h>
+#endif
+#include <stdlib.h>
 
 static const gchar *file_name = NULL;
 static gchar *prompt_type = NULL;
 static gint prompt_delay = 0;
 static gboolean prompt_window = FALSE;
 
+#ifndef HAVE_ERR_H
+extern void errx (int eval, char *format, ...);
+
+void errx (int eval, char *format, ...)
+{
+	va_list ap;
+	va_start (ap, format);
+	vfprintf (stderr, format, ap);
+	va_end (ap);
+
+	if (errno)
+	{
+		fprintf (stderr, ": ");
+		perror (NULL);
+		fprintf (stderr, "errno=%d\n", errno);
+	}
+	else
+		fprintf (stderr, "\n");
+
+	exit (1);
+}
+#endif
+
 static void
 prompt_perform (GtkWidget *parent)
 {
@@ -72,7 +105,11 @@
 		errx (1, "couldn't create prompt: %s", error->message);
 
 	if (parent) {
+#if defined(GDK_WINDOWING_X11)
 		caller_id = g_strdup_printf ("%lu", (gulong)GDK_WINDOW_XID (gtk_widget_get_window (parent)));
+#elif defined(GDK_WINDOWING_WIN32)
+		caller_id = g_strdup_printf ("%lu", (gulong)GDK_WINDOW_HWND (gtk_widget_get_window (parent)));
+#endif
 		gcr_prompt_set_caller_window (GCR_PROMPT (prompt), caller_id);
 		g_free (caller_id);
 	}
--- gcr/tests/frob-system-prompt.c	2012-11-12 07:30:20 +0000
+++ gcr/tests/frob-system-prompt.c	2013-10-22 07:46:51 +0000
@@ -26,7 +26,12 @@
 #include "gcr/gcr.h"
 
 #include <gtk/gtk.h>
+#ifdef GDK_WINDOWING_X11
 #include <gdk/gdkx.h>
+#endif
+#ifdef GDK_WINDOWING_WIN32
+#include <gdk/gdkwin32.h>
+#endif
 
 #include <unistd.h>
 #include <string.h>
@@ -53,7 +58,11 @@
 	gcr_prompt_set_message (GCR_PROMPT (prompt), "This is the message");
 	gcr_prompt_set_description (GCR_PROMPT (prompt), "This is the description");
 
+#if defined(GDK_WINDOWING_X11)
 	caller_id = g_strdup_printf ("%lu", (gulong)GDK_WINDOW_XID (gtk_widget_get_window (parent)));
+#elif defined(GDK_WINDOWING_WIN32)
+	caller_id = g_strdup_printf ("%lu", (gulong)GDK_WINDOW_HWND (gtk_widget_get_window (parent)));
+#endif
 	gcr_prompt_set_caller_window (GCR_PROMPT (prompt), caller_id);
 	g_free (caller_id);
 
