diff options
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | ChangeLog.ja | 16 | ||||
-rw-r--r-- | configure.in | 5 | ||||
-rw-r--r-- | src/about.c | 2 | ||||
-rw-r--r-- | src/action.c | 12 | ||||
-rw-r--r-- | src/addrcache.c | 4 | ||||
-rw-r--r-- | src/compose.c | 11 | ||||
-rw-r--r-- | src/inc.c | 5 | ||||
-rw-r--r-- | src/main.c | 14 | ||||
-rw-r--r-- | src/mbox.c | 6 | ||||
-rw-r--r-- | src/send_message.c | 6 | ||||
-rw-r--r-- | src/session.c | 19 | ||||
-rw-r--r-- | src/socket.c | 73 | ||||
-rw-r--r-- | src/socket.h | 4 | ||||
-rw-r--r-- | src/utils.c | 16 |
15 files changed, 179 insertions, 30 deletions
@@ -1,3 +1,19 @@ +2005-08-05 + + * src/addrcache.c + src/compose.c + src/inc.c + src/action.c + src/session.c + src/main.c + src/utils.c + src/send_message.c + src/mbox.c + src/about.c + src/socket.c + src/socket.h + configure.in: enabled compilation with MinGW. + 2005-08-04 * src/compose.c diff --git a/ChangeLog.ja b/ChangeLog.ja index cdfd0f42..0d121202 100644 --- a/ChangeLog.ja +++ b/ChangeLog.ja @@ -1,3 +1,19 @@ +2005-08-05 + + * src/addrcache.c + src/compose.c + src/inc.c + src/action.c + src/session.c + src/main.c + src/utils.c + src/send_message.c + src/mbox.c + src/about.c + src/socket.c + src/socket.h + configure.in: MinGW でのコンパイルができるようにした。 + 2005-08-04 * src/compose.c diff --git a/configure.in b/configure.in index 4f322d6a..25f81ba2 100644 --- a/configure.in +++ b/configure.in @@ -291,7 +291,8 @@ AC_HEADER_STDC AC_HEADER_SYS_WAIT AC_CHECK_HEADERS(fcntl.h sys/file.h unistd.h paths.h \ sys/param.h sys/utsname.h sys/select.h \ - wchar.h wctype.h) + wchar.h wctype.h \ + netdb.h) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST @@ -324,7 +325,7 @@ AC_CHECK_FUNCS(gethostname mkdir mktime socket strstr strchr \ wcsstr wcswcs iswalnum iswspace towlower \ wcslen wcscpy wcsncpy \ uname flock lockf inet_aton inet_addr \ - fchmod mkstemp) + fchmod mkstemp truncate getuid) AC_OUTPUT([ Makefile diff --git a/src/about.c b/src/about.c index 1bab06d7..16585857 100644 --- a/src/about.c +++ b/src/about.c @@ -116,7 +116,7 @@ static void about_create(void) gtk_major_version, gtk_minor_version, gtk_micro_version, glib_major_version, glib_minor_version, glib_micro_version, utsbuf.sysname, utsbuf.release, utsbuf.machine); -#elif G_OS_WIN32 +#elif defined(G_OS_WIN32) g_snprintf(buf, sizeof(buf), "GTK+ %d.%d.%d / GLib %d.%d.%d\n" "Operating System: %s", diff --git a/src/action.c b/src/action.c index 3949770f..1d7dbd0c 100644 --- a/src/action.c +++ b/src/action.c @@ -35,7 +35,9 @@ #include <string.h> #include <errno.h> #include <sys/types.h> -#include <sys/wait.h> +#if HAVE_SYS_WAIT_H +# include <sys/wait.h> +#endif #include <signal.h> #include <unistd.h> @@ -688,6 +690,7 @@ static gboolean execute_actions(gchar *action, GSList *msg_list, static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str, Children *children) { +#ifdef G_OS_UNIX gint chld_in[2], chld_out[2], chld_err[2], chld_status[2]; gchar *cmdline[4]; pid_t pid, gch_pid; @@ -845,10 +848,14 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str, } return child_info; +#else + return NULL; +#endif /* G_OS_UNIX */ } static void kill_children_cb(GtkWidget *widget, gpointer data) { +#ifdef G_OS_UNIX GSList *cur; Children *children = (Children *) data; ChildInfo *child_info; @@ -859,6 +866,7 @@ static void kill_children_cb(GtkWidget *widget, gpointer data) if (child_info->pid && kill(-child_info->pid, SIGTERM) < 0) perror("kill"); } +#endif /* G_OS_UNIX */ } static gint wait_for_children(Children *children) @@ -1156,7 +1164,9 @@ static void catch_status(gpointer data, gint source, GdkInputCondition cond) c = read(source, &buf, 1); debug_print("Child returned %c\n", buf); +#ifdef G_OS_UNIX waitpid(-child_info->pid, NULL, 0); +#endif childinfo_close_pipes(child_info); child_info->pid = 0; diff --git a/src/addrcache.c b/src/addrcache.c index 6a491256..28a65d58 100644 --- a/src/addrcache.c +++ b/src/addrcache.c @@ -194,7 +194,7 @@ gboolean addrcache_check_file( AddressCache *cache, gchar *path ) { struct stat filestat; retVal = TRUE; if( path ) { - if( 0 == lstat( path, &filestat ) ) { + if( 0 == stat( path, &filestat ) ) { if( filestat.st_mtime == cache->modifyTime ) retVal = FALSE; } } @@ -209,7 +209,7 @@ gboolean addrcache_mark_file( AddressCache *cache, gchar *path ) { gboolean retVal = FALSE; struct stat filestat; if( path ) { - if( 0 == lstat( path, &filestat ) ) { + if( 0 == stat( path, &filestat ) ) { cache->modifyTime = filestat.st_mtime; retVal = TRUE; } diff --git a/src/compose.c b/src/compose.c index b48f0cfb..0b971857 100644 --- a/src/compose.c +++ b/src/compose.c @@ -67,9 +67,10 @@ #include <sys/stat.h> #include <unistd.h> #include <time.h> -/* #include <sys/utsname.h> */ #include <stdlib.h> -#include <sys/wait.h> +#if HAVE_SYS_WAIT_H +# include <sys/wait.h> +#endif #include <signal.h> #include <errno.h> @@ -3397,7 +3398,6 @@ static gint compose_write_headers(Compose *compose, FILE *fp, const gchar *entry_str; gchar *str; gchar *name; - /* struct utsname utsbuf; */ g_return_val_if_fail(fp != NULL, -1); g_return_val_if_fail(charset != NULL, -1); @@ -3544,20 +3544,17 @@ static gint compose_write_headers(Compose *compose, FILE *fp, } /* Program version and system info */ - /* uname(&utsbuf); */ if (compose->to_list && !IS_IN_CUSTOM_HEADER("X-Mailer")) { fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n", prog_version, gtk_major_version, gtk_minor_version, gtk_micro_version, TARGET_ALIAS); - /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */ } if (compose->newsgroup_list && !IS_IN_CUSTOM_HEADER("X-Newsreader")) { fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n", prog_version, gtk_major_version, gtk_minor_version, gtk_micro_version, TARGET_ALIAS); - /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */ } /* custom headers */ @@ -5752,10 +5749,12 @@ static void compose_close_cb(gpointer data, guint action, GtkWidget *widget) Compose *compose = (Compose *)data; AlertValue val; +#ifdef G_OS_UNIX if (compose->exteditor_tag != -1) { if (!compose_ext_editor_kill(compose)) return; } +#endif if (compose->modified) { val = alertpanel(_("Save message"), @@ -33,11 +33,6 @@ #include <stdio.h> #include <unistd.h> #include <string.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/wait.h> -#include <signal.h> -#include <errno.h> #include "main.h" #include "inc.h" @@ -160,7 +160,10 @@ int main(int argc, char *argv[]) parse_cmd_opt(argc, argv); + sock_init(); + /* check and create unix domain socket for remote operation */ +#ifdef G_OS_UNIX lock_socket = prohibit_duplicate_launch(); if (lock_socket < 0) return 0; @@ -169,6 +172,7 @@ int main(int argc, char *argv[]) lock_socket_remove(); return 0; } +#endif gtk_set_locale(); gtk_init(&argc, &argv); @@ -318,10 +322,12 @@ int main(int argc, char *argv[]) folderview = mainwin->folderview; /* register the callback of unix domain socket input */ +#ifdef G_OS_UNIX lock_socket_tag = gdk_input_add(lock_socket, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, lock_socket_input_cb, mainwin); +#endif account_read_config_all(); @@ -542,6 +548,8 @@ void app_will_exit(GtkWidget *widget, gpointer data) ssl_done(); #endif + sock_cleanup(); + gtk_main_quit(); } @@ -562,7 +570,11 @@ static gchar *get_socket_name(void) if (filename == NULL) { filename = g_strdup_printf("%s%csylpheed-%d", g_get_tmp_dir(), G_DIR_SEPARATOR, +#if HAVE_GETUID getuid()); +#else + 0); +#endif } return filename; @@ -653,6 +665,7 @@ static gint prohibit_duplicate_launch(void) static gint lock_socket_remove(void) { +#ifdef G_OS_UNIX gchar *filename; if (lock_socket < 0) return -1; @@ -662,6 +675,7 @@ static gint lock_socket_remove(void) fd_close(lock_socket); filename = get_socket_name(); unlink(filename); +#endif return 0; } @@ -380,17 +380,23 @@ gint copy_mbox(const gchar *src, const gchar *dest) void empty_mbox(const gchar *mbox) { +#if HAVE_TRUNCATE if (truncate(mbox, 0) < 0) { +#endif FILE *fp; +#if HAVE_TRUNCATE FILE_OP_ERROR(mbox, "truncate"); +#endif if ((fp = fopen(mbox, "wb")) == NULL) { FILE_OP_ERROR(mbox, "fopen"); g_warning(_("can't truncate mailbox to zero.\n")); return; } fclose(fp); +#if HAVE_TRUNCATE } +#endif } /* read all messages in SRC, and store them into one MBOX file. */ diff --git a/src/send_message.c b/src/send_message.c index 3faef99d..fc67b209 100644 --- a/src/send_message.c +++ b/src/send_message.c @@ -31,7 +31,9 @@ #include <stdio.h> #include <string.h> #include <sys/types.h> -#include <sys/wait.h> +#if HAVE_SYS_WAIT_H +# include <sys/wait.h> +#endif #include "send_message.h" #include "session.h" @@ -348,9 +350,11 @@ static gint send_message_local(const gchar *command, FILE *fp) fd_close(child_stdin); +#ifdef G_OS_UNIX waitpid(pid, &status, 0); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) err = TRUE; +#endif g_spawn_close_pid(pid); diff --git a/src/session.c b/src/session.c index 237198d2..0aecb335 100644 --- a/src/session.c +++ b/src/session.c @@ -28,10 +28,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/types.h> #include <unistd.h> -#include <sys/signal.h> -#include <sys/wait.h> #include <time.h> #include <errno.h> @@ -102,6 +99,7 @@ void session_init(Session *session) gint session_connect(Session *session, const gchar *server, gushort port) { +#ifdef G_OS_UNIX session->server = g_strdup(server); session->port = port; @@ -114,6 +112,21 @@ gint session_connect(Session *session, const gchar *server, gushort port) } return 0; +#else + SockInfo *sock; + + session->server = g_strdup(server); + session->port = port; + + sock = sock_connect(server, port); + if (sock == NULL) { + g_warning("can't connect to server."); + session_close(session); + return -1; + } + + return session_connect_cb(sock, session); +#endif } static gint session_connect_cb(SockInfo *sock, gpointer data) diff --git a/src/socket.c b/src/socket.c index 2f6f4562..4572b97c 100644 --- a/src/socket.c +++ b/src/socket.c @@ -24,12 +24,18 @@ #include <glib.h> #include <sys/time.h> #include <sys/types.h> -#include <sys/wait.h> -#include <sys/socket.h> -#include <sys/un.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> +#ifdef G_OS_WIN32 +# include <winsock2.h> +#else +# if HAVE_SYS_WAIT_H +# include <sys/wait.h> +# endif +# include <sys/socket.h> +# include <sys/un.h> +# include <netinet/in.h> +# include <arpa/inet.h> +# include <netdb.h> +#endif /* G_OS_WIN32 */ #include <unistd.h> #include <stdio.h> #include <string.h> @@ -150,11 +156,24 @@ static gint sock_get_address_info_async_cancel (SockLookupData *lookup_data); gint sock_init(void) { +#ifdef G_OS_WIN32 + WSADATA wsadata; + gint result; + + result = WSAStartup(MAKEWORD(2, 2), &wsadata); + if (result != NO_ERROR) { + g_warning("WSAStartup() failed\n"); + return -1; + } +#endif return 0; } gint sock_cleanup(void) { +#ifdef G_OS_WIN32 + WSACleanup(); +#endif return 0; } @@ -166,6 +185,7 @@ gint sock_set_io_timeout(guint sec) gint fd_connect_unix(const gchar *path) { +#ifdef G_OS_UNIX gint sock; struct sockaddr_un addr; @@ -185,10 +205,14 @@ gint fd_connect_unix(const gchar *path) } return sock; +#else + return -1; +#endif } gint fd_open_unix(const gchar *path) { +#ifdef G_OS_UNIX gint sock; struct sockaddr_un addr; @@ -216,20 +240,28 @@ gint fd_open_unix(const gchar *path) } return sock; +#else + return -1; +#endif } gint fd_accept(gint sock) { +#ifdef G_OS_UNIX struct sockaddr_in caddr; guint caddr_len; caddr_len = sizeof(caddr); return accept(sock, (struct sockaddr *)&caddr, &caddr_len); +#else + return -1; +#endif } static gint set_nonblocking_mode(gint fd, gboolean nonblock) { +#ifdef G_OS_UNIX gint flags; flags = fcntl(fd, F_GETFL, 0); @@ -244,6 +276,9 @@ static gint set_nonblocking_mode(gint fd, gboolean nonblock) flags &= ~O_NONBLOCK; return fcntl(fd, F_SETFL, flags); +#else + return -1; +#endif } gint sock_set_nonblocking_mode(SockInfo *sock, gboolean nonblock) @@ -255,6 +290,7 @@ gint sock_set_nonblocking_mode(SockInfo *sock, gboolean nonblock) static gboolean is_nonblocking_mode(gint fd) { +#ifdef G_OS_UNIX gint flags; flags = fcntl(fd, F_GETFL, 0); @@ -264,6 +300,9 @@ static gboolean is_nonblocking_mode(gint fd) } return ((flags & O_NONBLOCK) != 0); +#else + return FALSE; +#endif } gboolean sock_is_nonblocking_mode(SockInfo *sock) @@ -327,7 +366,10 @@ static gboolean sock_watch_cb(GIOChannel *source, GIOCondition condition, { SockInfo *sock = (SockInfo *)data; - return sock->callback(sock, condition, sock->data); + if ((condition & sock->condition) == 0) + return TRUE; + + return sock->callback(sock, sock->condition, sock->data); } guint sock_add_watch(SockInfo *sock, GIOCondition condition, SockFunc func, @@ -554,15 +596,24 @@ static gint sock_connect_by_getaddrinfo(const gchar *hostname, gushort port) SockInfo *sock_connect(const gchar *hostname, gushort port) { +#ifdef G_OS_WIN32 + SOCKET sock; +#else gint sock; +#endif SockInfo *sockinfo; #ifdef INET6 if ((sock = sock_connect_by_getaddrinfo(hostname, port)) < 0) return NULL; #else +#ifdef G_OS_WIN32 + if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { + g_warning("socket() failed: %ld\n", WSAGetLastError()); +#else if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("socket"); +#endif /* G_OS_WIN32 */ return NULL; } @@ -1010,7 +1061,11 @@ gint fd_read(gint fd, gchar *buf, gint len) if (fd_check_io(fd, G_IO_IN) < 0) return -1; +#ifdef G_OS_WIN32 + return recv(fd, buf, len, 0); +#else return read(fd, buf, len); +#endif } #if USE_SSL @@ -1059,7 +1114,11 @@ gint fd_write(gint fd, const gchar *buf, gint len) if (fd_check_io(fd, G_IO_OUT) < 0) return -1; +#ifdef G_OS_WIN32 + return send(fd, buf, len, 0); +#else return write(fd, buf, len); +#endif } #if USE_SSL diff --git a/src/socket.h b/src/socket.h index 3865970b..5721a304 100644 --- a/src/socket.h +++ b/src/socket.h @@ -25,7 +25,9 @@ #endif #include <glib.h> -#include <netdb.h> +#if HAVE_NETDB_H +# include <netdb.h> +#endif typedef struct _SockInfo SockInfo; diff --git a/src/utils.c b/src/utils.c index 35dbffa0..26a43134 100644 --- a/src/utils.c +++ b/src/utils.c @@ -39,7 +39,9 @@ #include <unistd.h> #include <stdarg.h> #include <sys/types.h> -#include <sys/wait.h> +#if HAVE_SYS_WAIT_H +# include <sys/wait.h> +#endif #include <dirent.h> #include <time.h> @@ -1747,6 +1749,7 @@ gchar *get_tmp_file(void) const gchar *get_domain_name(void) { +#ifdef G_OS_UNIX static gchar *domain_name = NULL; if (!domain_name) { @@ -1770,6 +1773,9 @@ const gchar *get_domain_name(void) } return domain_name; +#else + return "unknown"; +#endif } off_t get_file_size(const gchar *file) @@ -1921,7 +1927,11 @@ gint change_dir(const gchar *dir) gint make_dir(const gchar *dir) { +#ifdef G_OS_WIN32 + if (mkdir(dir) < 0) { +#else if (mkdir(dir, S_IRWXU) < 0) { +#endif FILE_OP_ERROR(dir, "mkdir"); return -1; } @@ -2914,10 +2924,14 @@ gint execute_sync(gchar *const argv[]) return -1; } +#ifdef G_OS_UNIX if (WIFEXITED(status)) return WEXITSTATUS(status); else return -1; +#else + return status; +#endif } gint execute_command_line(const gchar *cmdline, gboolean async) |