2005-08-19 [paul] 1.9.13cvs38
authorPaul Mangan <paul@claws-mail.org>
Fri, 19 Aug 2005 09:30:30 +0000 (09:30 +0000)
committerPaul Mangan <paul@claws-mail.org>
Fri, 19 Aug 2005 09:30:30 +0000 (09:30 +0000)
sync with main:

* src/account.c
* src/action.c
* src/addrbook.c
* src/addrcache.c
* src/addrharvest.c
* src/addrindex.c
* src/codeconv.c
* src/compose.c
* src/crash.c
* src/exporthtml.c
* src/exportldif.c
* src/folder.c
* src/image_viewer.c
* src/inc.c
* src/inc.h
* src/jpilot.c
* src/ldif.c
* src/main.c
* src/matcher.c
* src/mbox.c
* src/messageview.c
* src/mh.c
* src/mimeview.c
* src/msgcache.c
* src/mutt.c
* src/news.c
* src/partial_download.c
* src/pine.c
* src/pop.c
* src/prefs_actions.c
* src/prefs_common.c
* src/prefs_customheader.c
* src/prefs_display_header.c
* src/prefs_gtk.c
* src/prefs_themes.c
* src/procheader.c
* src/procmime.c
* src/procmsg.c
* src/recv.c
* src/send_message.c
* src/simple-gettext.c
* src/sourcewindow.c
* src/textview.c
* src/vcard.c
* src/common/defs.h
* src/common/log.c
* src/common/plugin.c
* src/common/prefs.c
* src/common/session.c
* src/common/session.h
* src/common/socket.c
* src/common/socket.h
* src/common/ssl_certificate.c
* src/common/template.c
* src/common/utils.c
* src/common/utils.h
* src/common/xml.c
* src/gtk/about.c
added wrappers for C library function that
take pathname arguments.
enabled compilation with MinGW.
use GDir instead of directly using opendir().
added rename_force().

61 files changed:
ChangeLog-gtk2.claws
PATCHSETS
configure.ac
src/account.c
src/action.c
src/addrbook.c
src/addrcache.c
src/addrharvest.c
src/addrindex.c
src/codeconv.c
src/common/defs.h
src/common/log.c
src/common/plugin.c
src/common/prefs.c
src/common/session.c
src/common/session.h
src/common/socket.c
src/common/socket.h
src/common/ssl_certificate.c
src/common/template.c
src/common/utils.c
src/common/utils.h
src/common/xml.c
src/compose.c
src/crash.c
src/exporthtml.c
src/exportldif.c
src/folder.c
src/gtk/about.c
src/image_viewer.c
src/inc.c
src/inc.h
src/jpilot.c
src/ldif.c
src/main.c
src/matcher.c
src/mbox.c
src/messageview.c
src/mh.c
src/mimeview.c
src/msgcache.c
src/mutt.c
src/news.c
src/partial_download.c
src/pine.c
src/pop.c
src/prefs_actions.c
src/prefs_common.c
src/prefs_customheader.c
src/prefs_display_header.c
src/prefs_gtk.c
src/prefs_themes.c
src/procheader.c
src/procmime.c
src/procmsg.c
src/recv.c
src/send_message.c
src/simple-gettext.c
src/sourcewindow.c
src/textview.c
src/vcard.c

index d4a006a..0fa1b51 100644 (file)
@@ -1,3 +1,71 @@
+2005-08-19 [paul]      1.9.13cvs38
+
+       sync with main:
+
+       * src/account.c
+       * src/action.c
+       * src/addrbook.c
+       * src/addrcache.c
+       * src/addrharvest.c
+       * src/addrindex.c
+       * src/codeconv.c
+       * src/compose.c
+       * src/crash.c
+       * src/exporthtml.c
+       * src/exportldif.c
+       * src/folder.c
+       * src/image_viewer.c
+       * src/inc.c
+       * src/inc.h
+       * src/jpilot.c
+       * src/ldif.c
+       * src/main.c
+       * src/matcher.c
+       * src/mbox.c
+       * src/messageview.c
+       * src/mh.c
+       * src/mimeview.c
+       * src/msgcache.c
+       * src/mutt.c
+       * src/news.c
+       * src/partial_download.c
+       * src/pine.c
+       * src/pop.c
+       * src/prefs_actions.c
+       * src/prefs_common.c
+       * src/prefs_customheader.c
+       * src/prefs_display_header.c
+       * src/prefs_gtk.c
+       * src/prefs_themes.c
+       * src/procheader.c
+       * src/procmime.c
+       * src/procmsg.c
+       * src/recv.c
+       * src/send_message.c
+       * src/simple-gettext.c
+       * src/sourcewindow.c
+       * src/textview.c
+       * src/vcard.c
+       * src/common/defs.h
+       * src/common/log.c
+       * src/common/plugin.c
+       * src/common/prefs.c
+       * src/common/session.c
+       * src/common/session.h
+       * src/common/socket.c
+       * src/common/socket.h
+       * src/common/ssl_certificate.c
+       * src/common/template.c
+       * src/common/utils.c
+       * src/common/utils.h
+       * src/common/xml.c
+       * src/gtk/about.c
+       added wrappers for C library function that
+               take pathname arguments.
+               enabled compilation with MinGW.
+               use GDir instead of directly using opendir().
+               added rename_force().
+
 2005-08-19 [paul]      1.9.13cvs37
        
        patches by Colin:
index 57aae2b..d9b4119 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.61.2.35 -r 1.61.2.36 src/account.c;  cvs diff -u -r 1.60.2.25 -r 1.60.2.26 src/addressbook.c;  cvs diff -u -r 1.395.2.111 -r 1.395.2.112 src/summaryview.c;  cvs diff -u -r 1.1.4.8 -r 1.1.4.9 src/gtk/gtksctree.c;  cvs diff -u -r 1.1.4.2 -r 1.1.4.3 src/gtk/gtksctree.h;  ) > 1.9.13cvs35.patchset
 ( cvs diff -u -r 1.1.2.25 -r 1.1.2.26 commitHelper;  cvs diff -u -r 1.15.2.2 -r 1.15.2.3 src/addrcache.c;  cvs diff -u -r 1.6.10.6 -r 1.6.10.7 src/addrharvest.c;  cvs diff -u -r 1.28.2.6 -r 1.28.2.7 src/addrindex.c;  cvs diff -u -r 1.382.2.149 -r 1.382.2.150 src/compose.c;  cvs diff -u -r 1.14.2.9 -r 1.14.2.10 src/grouplistdialog.c;  cvs diff -u -r 1.115.2.48 -r 1.115.2.49 src/main.c;  cvs diff -u -r 1.274.2.55 -r 1.274.2.56 src/mainwindow.c;  cvs diff -u -r 1.16.2.24 -r 1.16.2.25 src/msgcache.c;  cvs diff -u -r 1.6.10.1 -r 1.6.10.2 src/mutt.c;  cvs diff -u -r 1.6.2.1 -r 1.6.2.2 src/pine.c;  cvs diff -u -r 1.105.2.30 -r 1.105.2.31 src/prefs_account.c;  cvs diff -u -r 1.3.2.22 -r 1.3.2.23 src/prefs_themes.c;  cvs diff -u -r 1.25.2.15 -r 1.25.2.16 src/stock_pixmap.c;  cvs diff -u -r 1.395.2.112 -r 1.395.2.113 src/summaryview.c;  cvs diff -u -r 1.4.2.15 -r 1.4.2.16 src/gtk/about.c;  cvs diff -u -r 1.1.4.8 -r 1.1.4.9 src/gtk/logwindow.c;  cvs diff -u -r 1.1.2.2 -r 1.1.2.3 src/plugins/pgpcore/select-keys.c;  ) > 1.9.13cvs36.patchset
 ( cvs diff -u -r 1.382.2.150 -r 1.382.2.151 src/compose.c;  cvs diff -u -r 1.213.2.50 -r 1.213.2.51 src/folder.c;  cvs diff -u -r 1.18.2.9 -r 1.18.2.10 src/jpilot.c;  cvs diff -u -r 1.150.2.37 -r 1.150.2.38 src/procmsg.c;  cvs diff -u -r 1.60.2.14 -r 1.60.2.15 src/procmsg.h;  cvs diff -u -r 1.395.2.113 -r 1.395.2.114 src/summaryview.c;  ) > 1.9.13cvs37.patchset
+( cvs diff -u -r 1.61.2.36 -r 1.61.2.37 src/account.c;  cvs diff -u -r 1.12.2.24 -r 1.12.2.25 src/action.c;  cvs diff -u -r 1.22.2.3 -r 1.22.2.4 src/addrbook.c;  cvs diff -u -r 1.15.2.3 -r 1.15.2.4 src/addrcache.c;  cvs diff -u -r 1.6.10.7 -r 1.6.10.8 src/addrharvest.c;  cvs diff -u -r 1.28.2.7 -r 1.28.2.8 src/addrindex.c;  cvs diff -u -r 1.65.2.34 -r 1.65.2.35 src/codeconv.c;  cvs diff -u -r 1.382.2.151 -r 1.382.2.152 src/compose.c;  cvs diff -u -r 1.23.2.11 -r 1.23.2.12 src/crash.c;  cvs diff -u -r 1.5.2.5 -r 1.5.2.6 src/exporthtml.c;  cvs diff -u -r 1.1.4.5 -r 1.1.4.6 src/exportldif.c;  cvs diff -u -r 1.213.2.51 -r 1.213.2.52 src/folder.c;  cvs diff -u -r 1.1.2.4 -r 1.1.2.5 src/image_viewer.c;  cvs diff -u -r 1.149.2.30 -r 1.149.2.31 src/inc.c;  cvs diff -u -r 1.29.2.4 -r 1.29.2.5 src/inc.h;  cvs diff -u -r 1.18.2.10 -r 1.18.2.11 src/jpilot.c;  cvs diff -u -r 1.12.2.2 -r 1.12.2.3 src/ldif.c;  cvs diff -u -r 1.115.2.49 -r 1.115.2.50 src/main.c;  cvs diff -u -r 1.75.2.7 -r 1.75.2.8 src/matcher.c;  cvs diff -u -r 1.28.2.6 -r 1.28.2.7 src/mbox.c;  cvs diff -u -r 1.94.2.61 -r 1.94.2.62 src/messageview.c;  cvs diff -u -r 1.79.2.16 -r 1.79.2.17 src/mh.c;  cvs diff -u -r 1.83.2.35 -r 1.83.2.36 src/mimeview.c;  cvs diff -u -r 1.16.2.25 -r 1.16.2.26 src/msgcache.c;  cvs diff -u -r 1.6.10.2 -r 1.6.10.3 src/mutt.c;  cvs diff -u -r 1.101.2.12 -r 1.101.2.13 src/news.c;  cvs diff -u -r 1.1.2.6 -r 1.1.2.7 src/partial_download.c;  cvs diff -u -r 1.6.2.2 -r 1.6.2.3 src/pine.c;  cvs diff -u -r 1.56.2.37 -r 1.56.2.38 src/pop.c;  cvs diff -u -r 1.60.2.19 -r 1.60.2.20 src/prefs_actions.c;  cvs diff -u -r 1.204.2.50 -r 1.204.2.51 src/prefs_common.c;  cvs diff -u -r 1.16.2.11 -r 1.16.2.12 src/prefs_customheader.c;  cvs diff -u -r 1.16.2.11 -r 1.16.2.12 src/prefs_display_header.c;  cvs diff -u -r 1.10.2.12 -r 1.10.2.13 src/prefs_gtk.c;  cvs diff -u -r 1.3.2.23 -r 1.3.2.24 src/prefs_themes.c;  cvs diff -u -r 1.47.2.22 -r 1.47.2.23 src/procheader.c;  cvs diff -u -r 1.49.2.53 -r 1.49.2.54 src/procmime.c;  cvs diff -u -r 1.150.2.38 -r 1.150.2.39 src/procmsg.c;  cvs diff -u -r 1.17.2.4 -r 1.17.2.5 src/recv.c;  cvs diff -u -r 1.17.2.16 -r 1.17.2.17 src/send_message.c;  cvs diff -u -r 1.1 -r 1.2 src/simple-gettext.c;  cvs diff -u -r 1.9.2.13 -r 1.9.2.14 src/sourcewindow.c;  cvs diff -u -r 1.96.2.69 -r 1.96.2.70 src/textview.c;  cvs diff -u -r 1.14.2.3 -r 1.14.2.4 src/vcard.c;  cvs diff -u -r 1.9.2.12 -r 1.9.2.13 src/common/defs.h;  cvs diff -u -r 1.6.2.3 -r 1.6.2.4 src/common/log.c;  cvs diff -u -r 1.13.2.5 -r 1.13.2.6 src/common/plugin.c;  cvs diff -u -r 1.5.2.1 -r 1.5.2.2 src/common/prefs.c;  cvs diff -u -r 1.23.2.5 -r 1.23.2.6 src/common/session.c;  cvs diff -u -r 1.8.2.3 -r 1.8.2.4 src/common/session.h;  cvs diff -u -r 1.13.2.13 -r 1.13.2.14 src/common/socket.c;  cvs diff -u -r 1.13.2.1 -r 1.13.2.2 src/common/socket.h;  cvs diff -u -r 1.4.2.1 -r 1.4.2.2 src/common/ssl_certificate.c;  cvs diff -u -r 1.2.4.11 -r 1.2.4.12 src/common/template.c;  cvs diff -u -r 1.36.2.39 -r 1.36.2.40 src/common/utils.c;  cvs diff -u -r 1.20.2.21 -r 1.20.2.22 src/common/utils.h;  cvs diff -u -r 1.1.4.9 -r 1.1.4.10 src/common/xml.c;  cvs diff -u -r 1.4.2.16 -r 1.4.2.17 src/gtk/about.c;  ) > 1.9.13cvs38.patchset
index ceb69ba..2a8d1b2 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=13
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=37
+EXTRA_VERSION=38
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 7e43593..006da42 100644 (file)
@@ -184,7 +184,7 @@ void account_read_config_all(void)
        debug_print("Reading all config for each account...\n");
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
-       if ((fp = fopen(rcpath, "rb")) == NULL) {
+       if ((fp = g_fopen(rcpath, "rb")) == NULL) {
                if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
                g_free(rcpath);
                return;
index 7f15b7c..e284f41 100644 (file)
@@ -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>
 
@@ -764,6 +766,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], *ret_str;
        pid_t pid, gch_pid;
@@ -935,10 +938,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;
@@ -949,6 +956,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)
@@ -1274,7 +1282,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;
 
index b6111be..182f51a 100644 (file)
@@ -22,7 +22,6 @@
 #include <glib.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <dirent.h>
 #include <sys/stat.h>
 #include <math.h>
 #include <setjmp.h>
@@ -1259,7 +1258,7 @@ gint addrbook_write_to(AddressBookFile *book, gchar *newFile)
 
        book->retVal = MGU_OPEN_FILE;
 #ifdef DEV_STANDALONE
-       fp = fopen(fileSpec, "wb");
+       fp = g_fopen(fileSpec, "wb");
        g_free(fileSpec);
        if (fp) {
                fputs("<?xml version=\"1.0\" ?>\n", fp);
@@ -1887,8 +1886,8 @@ ItemFolder *addrbook_remove_folder_delete(AddressBookFile *book,
  */
 GList *addrbook_get_bookfile_list(AddressBookFile *book) {
        gchar *adbookdir;
-       DIR *dp;
-       struct dirent *entry;
+       GDir *dir;
+       const gchar *dir_name;
        struct stat statbuf;
        gchar buf[WORK_BUFLEN];
        gchar numbuf[WORK_BUFLEN];
@@ -1915,7 +1914,7 @@ GList *addrbook_get_bookfile_list(AddressBookFile *book) {
        adbookdir = g_strdup(buf);
        strcat(buf, ADDRBOOK_PREFIX);
 
-       if ((dp = opendir(adbookdir)) == NULL) {
+       if( ( dir = g_dir_open( adbookdir, 0, NULL ) ) == NULL ) {
                book->retVal = MGU_OPEN_DIRECTORY;
                g_free(adbookdir);
                return NULL;
@@ -1926,25 +1925,25 @@ GList *addrbook_get_bookfile_list(AddressBookFile *book) {
        lennum = FILE_NUMDIGITS + lenpre;
        maxval = -1;
 
-       while ((entry = readdir(dp)) != NULL) {
+       while( ( dir_name = g_dir_read_name( dir ) ) != NULL ) {
                gchar *endptr = NULL;
                gint i;
                gboolean flg;
 
                strcpy(buf, adbookdir);
-               strcat(buf, entry->d_name);
+               strcat( buf, dir_name );
                stat(buf, &statbuf);
                if (S_ISREG(statbuf.st_mode)) {
                        if (strncmp(
-                               entry->d_name,
+                               dir_name,
                                ADDRBOOK_PREFIX, lenpre) == 0)
                        {
                                if (strncmp(
-                                       (entry->d_name) + lennum,
+                                       (dir_name) + lennum,
                                        ADDRBOOK_SUFFIX, lensuf) == 0)
                                {
                                        strncpy(numbuf,
-                                               (entry->d_name) + lenpre,
+                                               (dir_name) + lenpre,
                                                FILE_NUMDIGITS);
                                        numbuf[FILE_NUMDIGITS] = '\0';
                                        flg = TRUE;
@@ -1961,14 +1960,14 @@ GList *addrbook_get_bookfile_list(AddressBookFile *book) {
                                                        if (val > maxval) maxval = val;
                                                        fileList = g_list_append(
                                                                fileList,
-                                                               g_strdup(entry->d_name));
+                                                               g_strdup(dir_name));
                                                }
                                        }
                                }
                        }
                }
        }
-       closedir(dp);
+       g_dir_close( dir );
        g_free(adbookdir);
 
        book->maxValue = maxval; 
index 8807839..33a675a 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "mgutils.h"
 #include "addrcache.h"
+#include "utils.h"
 
 #define ID_TIME_OFFSET             998000000
 #define ADDRCACHE_MAX_SEARCH_COUNT 1000
@@ -268,7 +269,7 @@ gboolean addrcache_check_file( AddressCache *cache, gchar *path ) {
        struct stat filestat;
        retVal = TRUE;
        if( path ) {
-               if( 0 == stat( path, &filestat ) ) {
+               if( 0 == g_stat( path, &filestat ) ) {
                        if( filestat.st_mtime == cache->modifyTime ) retVal = FALSE;
                }
        }
@@ -283,7 +284,7 @@ gboolean addrcache_mark_file( AddressCache *cache, gchar *path ) {
        gboolean retVal = FALSE;
        struct stat filestat;
        if( path ) {
-               if( 0 == stat( path, &filestat ) ) {
+               if( 0 == g_stat( path, &filestat ) ) {
                        cache->modifyTime = filestat.st_mtime;
                        retVal = TRUE;
                }
index f99a147..4d87449 100644 (file)
@@ -679,7 +679,7 @@ static gint addrharvest_readfile(
        GSList *list;
        gboolean done;
 
-       msgFile = fopen( fileName, "rb" );
+       msgFile = g_fopen( fileName, "rb" );
        if( ! msgFile ) {
                /* Cannot open file */
                retVal = MGU_OPEN_FILE;
index d20d584..d80d4c4 100644 (file)
@@ -38,6 +38,7 @@
 #include "xml.h"
 #include "addrquery.h"
 #include "addr_compl.h"
+#include "utils.h"
 
 #ifndef DEV_STANDALONE
 #include "prefs_gtk.h"
@@ -1711,7 +1712,7 @@ gint addrindex_write_to( AddressIndex *addrIndex, const gchar *newFile ) {
        fileSpec = g_strconcat( addrIndex->filePath, G_DIR_SEPARATOR_S, newFile, NULL );
        addrIndex->retVal = MGU_OPEN_FILE;
 #ifdef DEV_STANDALONE
-       fp = fopen( fileSpec, "wb" );
+       fp = g_fopen( fileSpec, "wb" );
        g_free( fileSpec );
        if( fp ) {
                fputs( "<?xml version=\"1.0\" ?>\n", fp );
index d2d636a..f02603d 100644 (file)
@@ -1022,7 +1022,11 @@ static const struct {
        {"ja_JP.ujis"   , C_EUC_JP      , C_ISO_2022_JP},
        {"ja_JP.SJIS"   , C_SHIFT_JIS   , C_ISO_2022_JP},
        {"ja_JP.JIS"    , C_ISO_2022_JP , C_ISO_2022_JP},
+#ifdef G_OS_WIN32
+       {"ja_JP"        , C_SHIFT_JIS   , C_ISO_2022_JP},
+#else
        {"ja_JP"        , C_EUC_JP      , C_ISO_2022_JP},
+#endif
        {"ko_KR.EUC-KR" , C_EUC_KR      , C_EUC_KR},
        {"ko_KR"        , C_EUC_KR      , C_EUC_KR},
        {"zh_CN.GB2312" , C_GB2312      , C_GB2312},
@@ -1404,10 +1408,14 @@ const gchar *conv_get_current_locale(void)
 {
        const gchar *cur_locale;
 
+#ifdef G_OS_WIN32
+       cur_locale = g_win32_getlocale();
+#else
        cur_locale = g_getenv("LC_ALL");
        if (!cur_locale) cur_locale = g_getenv("LC_CTYPE");
        if (!cur_locale) cur_locale = g_getenv("LANG");
        if (!cur_locale) cur_locale = setlocale(LC_CTYPE, NULL);
+#endif /* G_OS_WIN32 */
 
        debug_print("current locale: %s\n",
                    cur_locale ? cur_locale : "(none)");
index 3163a3a..b126775 100644 (file)
 #  include "config.h"
 #endif
 
+#include <glibconfig.h>
+
+#ifdef G_OS_WIN32
+#  include <glib/gwin32.h>
+#endif
+
 #if HAVE_PATHS_H
 #  include <paths.h>
 #endif
 #define QUEUE_DIR              "queue"
 #define DRAFT_DIR              "draft"
 #define TRASH_DIR              "trash"
-#ifndef CLAWS /* easier to sync */
-#define RC_DIR                 ".sylpheed"
-#else
-#define RC_DIR                 CFG_RC_DIR      
-#endif /* CLAWS */
+#define RC_DIR                 CFG_RC_DIR
 #define NEWS_CACHE_DIR         "newscache"
 #define IMAP_CACHE_DIR         "imapcache"
 #define MBOX_CACHE_DIR         "mboxcache"
 #define CACHE_VERSION          24
 #define MARK_VERSION           2
 
-#define DEFAULT_SIGNATURE      ".signature"
+#ifdef G_OS_WIN32
+#  define DEFAULT_SIGNATURE    "signature.txt"
+#else
+#  define DEFAULT_SIGNATURE    ".signature"
+#endif
 #define DEFAULT_INC_PATH       "/usr/bin/mh/inc"
 #define DEFAULT_INC_PROGRAM    "inc"
 /* #define DEFAULT_INC_PATH    "/usr/bin/imget" */
index 665bdfc..8f85147 100644 (file)
@@ -56,7 +56,7 @@ void set_log_file(const gchar *filename)
                g_free(backupname);
        }
 
-       log_fp = fopen(filename, "wb");
+       log_fp = g_fopen(filename, "wb");
        if (!log_fp)
                FILE_OP_ERROR(filename, "fopen");
 }
index da25e5c..65bcf99 100644 (file)
@@ -128,7 +128,7 @@ static gint plugin_load_deps(const gchar *filename, gchar **error)
        deps_file = g_strconcat(tmp, ".deps", NULL);
        g_free(tmp);
        
-       fp = fopen(deps_file, "rb");
+       fp = g_fopen(deps_file, "rb");
        g_free(deps_file);
        
        if (!fp)
index 6bd2708..e76bb02 100644 (file)
@@ -42,7 +42,7 @@ PrefFile *prefs_read_open(const gchar *path)
 
        g_return_val_if_fail(path != NULL, NULL);
 
-       if ((fp = fopen(path, "rb")) == NULL) {
+       if ((fp = g_fopen(path, "rb")) == NULL) {
                FILE_OP_ERROR(path, "fopen");
                return NULL;
        }
@@ -79,7 +79,7 @@ PrefFile *prefs_write_open(const gchar *path)
        }
 
        tmppath = g_strconcat(path, ".tmp", NULL);
-       if ((fp = fopen(tmppath, "wb")) == NULL) {
+       if ((fp = g_fopen(tmppath, "wb")) == NULL) {
                FILE_OP_ERROR(tmppath, "fopen");
                g_free(tmppath);
                return NULL;
@@ -164,7 +164,7 @@ gint prefs_file_close(PrefFile *pfile)
        tmppath = g_strconcat(path, ".tmp", NULL);
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(tmppath, "fclose");
-               unlink(tmppath);
+               g_unlink(tmppath);
                g_free(path);
                g_free(tmppath);
                return -1;
@@ -174,7 +174,7 @@ gint prefs_file_close(PrefFile *pfile)
                bakpath = g_strconcat(path, ".bak", NULL);
                if (rename(path, bakpath) < 0) {
                        FILE_OP_ERROR(path, "rename");
-                       unlink(tmppath);
+                       g_unlink(tmppath);
                        g_free(path);
                        g_free(tmppath);
                        g_free(bakpath);
@@ -184,7 +184,7 @@ gint prefs_file_close(PrefFile *pfile)
 
        if (rename(tmppath, path) < 0) {
                FILE_OP_ERROR(tmppath, "rename");
-               unlink(tmppath);
+               g_unlink(tmppath);
                g_free(path);
                g_free(tmppath);
                g_free(bakpath);
@@ -216,7 +216,7 @@ gint prefs_file_close_revert(PrefFile *pfile)
                tmppath = g_strconcat(pfile->path, ".tmp", NULL);
        fclose(pfile->fp);
        if (pfile->writing) {
-               if (unlink(tmppath) < 0) FILE_OP_ERROR(tmppath, "unlink");
+               if (g_unlink(tmppath) < 0) FILE_OP_ERROR(tmppath, "unlink");
                g_free(tmppath);
        }
        g_free(pfile->path);
@@ -279,7 +279,7 @@ gint prefs_set_block_label(PrefFile *pfile, const gchar *label)
                        }
                }
        } else {
-               if ((pfile->orig_fp = fopen(pfile->path, "rb")) != NULL) {
+               if ((pfile->orig_fp = g_fopen(pfile->path, "rb")) != NULL) {
                        gboolean block_matched = FALSE;
 
                        while (fgets(buf, sizeof(buf), pfile->orig_fp) != NULL) {
index ae25c08..d4c5dbc 100644 (file)
 #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 <sys/time.h>
 #include <time.h>
 #include <errno.h>
 
@@ -75,7 +71,7 @@ void session_init(Session *session)
        session->state = SESSION_READY;
        session->last_access_time = time(NULL);
 
-       gettimeofday(&session->tv_prev, NULL);
+       g_get_current_time(&session->tv_prev);
 
        session->conn_id = 0;
 
@@ -116,6 +112,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;
 
@@ -128,6 +125,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)
@@ -295,11 +307,13 @@ static gint session_close(Session *session)
 {
        g_return_val_if_fail(session != NULL, -1);
 
+#ifdef G_OS_UNIX
        if (session->conn_id > 0) {
                sock_connect_async_cancel(session->conn_id);
                session->conn_id = 0;
                debug_print("session (%p): connection cancelled\n", session);
        }
+#endif
 
        session_set_timeout(session, 0);
 
@@ -418,7 +432,7 @@ gint session_send_data(Session *session, const guchar *data, guint size)
        session->write_data = data;
        session->write_data_p = session->write_data;
        session->write_data_len = size;
-       gettimeofday(&session->tv_prev, NULL);
+       g_get_current_time(&session->tv_prev);
 
        ret = session_write_data_cb(session->sock, G_IO_OUT, session);
 
@@ -440,7 +454,7 @@ gint session_recv_data(Session *session, guint size, const gchar *terminator)
 
        g_free(session->read_data_terminator);
        session->read_data_terminator = g_strdup(terminator);
-       gettimeofday(&session->tv_prev, NULL);
+       g_get_current_time(&session->tv_prev);
 
        if (session->read_buf_len > 0)
                g_idle_add(session_recv_data_idle_cb, session);
@@ -628,16 +642,16 @@ static gboolean session_read_data_cb(SockInfo *source, GIOCondition condition,
 
        /* incomplete read */
        if (!complete) {
-               struct timeval tv_cur;
+               GTimeVal tv_cur;
 
-               gettimeofday(&tv_cur, NULL);
+               g_get_current_time(&tv_cur);
                if (tv_cur.tv_sec - session->tv_prev.tv_sec > 0 ||
                    tv_cur.tv_usec - session->tv_prev.tv_usec >
                    UI_REFRESH_INTERVAL) {
                        session->recv_data_progressive_notify
                                (session, data_buf->len, 0,
                                 session->recv_data_progressive_notify_data);
-                       gettimeofday(&session->tv_prev, NULL);
+                       g_get_current_time(&session->tv_prev);
                }
                return TRUE;
        }
@@ -799,9 +813,9 @@ static gboolean session_write_data_cb(SockInfo *source,
                session->state = SESSION_ERROR;
                return FALSE;
        } else if (ret > 0) {
-               struct timeval tv_cur;
+               GTimeVal tv_cur;
 
-               gettimeofday(&tv_cur, NULL);
+               g_get_current_time(&tv_cur);
                if (tv_cur.tv_sec - session->tv_prev.tv_sec > 0 ||
                    tv_cur.tv_usec - session->tv_prev.tv_usec >
                    UI_REFRESH_INTERVAL) {
@@ -811,7 +825,7 @@ static gboolean session_write_data_cb(SockInfo *source,
                                 session->write_data_p - session->write_data,
                                 write_data_len,
                                 session->send_data_progressive_notify_data);
-                       gettimeofday(&session->tv_prev, NULL);
+                       g_get_current_time(&session->tv_prev);
                }
                return TRUE;
        }
index 840bff9..4a6517c 100644 (file)
@@ -27,7 +27,6 @@
 #include <glib.h>
 
 #include <time.h>
-#include <sys/time.h>
 #include <unistd.h>
 
 #include "socket.h"
@@ -102,7 +101,7 @@ struct _Session
        SessionState state;
 
        time_t last_access_time;
-       struct timeval tv_prev;
+       GTimeVal tv_prev;
 
        gint conn_id;
 
index ef9ac27..4d56e5c 100644 (file)
 #include <glib.h>
 #include <sys/time.h>
 #include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <sys/un.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <resolv.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/stat.h>
+#  include <sys/un.h>
+#  include <netinet/in.h>
+#  include <arpa/inet.h>
+#  include <resolv.h>
+#  include <netdb.h>
+#endif /* G_OS_WIN32 */
 #include <unistd.h>
 #include <stdio.h>
 #include <string.h>
@@ -135,6 +141,7 @@ static gint sock_connect_by_getaddrinfo     (const gchar    *hostname,
 static SockInfo *sockinfo_from_fd(const gchar *hostname,
                                  gushort port,
                                  gint sock);
+#ifdef G_OS_UNIX
 static void sock_address_list_free             (GList          *addr_list);
 
 static gboolean sock_connect_async_cb          (GIOChannel     *source,
@@ -155,7 +162,31 @@ static SockLookupData *sock_get_address_info_async
                                                 SockAddrFunc    func,
                                                 gpointer        data);
 static gint sock_get_address_info_async_cancel (SockLookupData *lookup_data);
+#endif /* G_OS_UNIX */
+
+
+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;
+}
 
 gint sock_set_io_timeout(guint sec)
 {
@@ -184,6 +215,7 @@ void refresh_resolvers(void)
 
 gint fd_connect_unix(const gchar *path)
 {
+#ifdef G_OS_UNIX
        gint sock;
        struct sockaddr_un addr;
 
@@ -203,10 +235,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;
 
@@ -234,20 +270,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;
-       gint caddr_len;
+       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);
@@ -262,6 +306,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)
@@ -273,6 +320,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);
@@ -282,6 +330,9 @@ static gboolean is_nonblocking_mode(gint fd)
        }
 
        return ((flags & O_NONBLOCK) != 0);
+#else
+       return FALSE;
+#endif
 }
 
 gboolean sock_is_nonblocking_mode(SockInfo *sock)
@@ -351,10 +402,10 @@ static gboolean sock_watch_cb(GIOChannel *source, GIOCondition condition,
 {
        SockInfo *sock = (SockInfo *)data;
 
-       if (!sock || !sock->callback || !sock->data) {
-               return FALSE;
-       }
-       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,
@@ -410,12 +461,14 @@ static gint fd_check_io(gint fd, GIOCondition cond)
        }
 }
 
+#ifdef G_OS_UNIX
 static sigjmp_buf jmpenv;
 
 static void timeout_handler(gint sig)
 {
        siglongjmp(jmpenv, 1);
 }
+#endif
 
 static gint sock_connect_with_timeout(gint sock,
                                      const struct sockaddr *serv_addr,
@@ -423,6 +476,7 @@ static gint sock_connect_with_timeout(gint sock,
                                      guint timeout_secs)
 {
        gint ret;
+#ifdef G_OS_UNIX
        void (*prev_handler)(gint);
        
        alarm(0);
@@ -434,11 +488,14 @@ static gint sock_connect_with_timeout(gint sock,
                return -1;
        }
        alarm(timeout_secs);
+#endif
 
        ret = connect(sock, serv_addr, addrlen);
 
+#ifdef G_OS_UNIX
        alarm(0);
        signal(SIGALRM, prev_handler);
+#endif
 
        return ret;
 }
@@ -446,6 +503,7 @@ static gint sock_connect_with_timeout(gint sock,
 struct hostent *my_gethostbyname(const gchar *hostname)
 {
        struct hostent *hp;
+#ifdef G_OS_UNIX
        void (*prev_handler)(gint);
        
        alarm(0);
@@ -458,17 +516,22 @@ struct hostent *my_gethostbyname(const gchar *hostname)
                return NULL;
        }
        alarm(io_timeout);
+#endif
 
        if ((hp = gethostbyname(hostname)) == NULL) {
+#ifdef G_OS_UNIX
                alarm(0);
                signal(SIGALRM, prev_handler);
+#endif
                fprintf(stderr, "%s: unknown host.\n", hostname);
                errno = 0;
                return NULL;
        }
 
+#ifdef G_OS_UNIX
        alarm(0);
        signal(SIGALRM, prev_handler);
+#endif
 
        return hp;
 }
@@ -603,14 +666,24 @@ SockInfo *sock_connect_cmd(const gchar *hostname, const gchar *tunnelcmd)
 
 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;
        }
 
@@ -624,6 +697,7 @@ SockInfo *sock_connect(const gchar *hostname, gushort port)
        return sockinfo_from_fd(hostname, port, sock);
 }
 
+#ifdef G_OS_UNIX
 static void sock_address_list_free(GList *addr_list)
 {
        GList *cur;
@@ -645,7 +719,7 @@ static gboolean sock_connect_async_cb(GIOChannel *source,
        SockConnectData *conn_data = (SockConnectData *)data;
        gint fd;
        gint val;
-       gint len;
+       guint len;
        SockInfo *sockinfo;
 
        if (conn_data->io_tag == 0 && conn_data->channel == NULL)
@@ -1022,6 +1096,7 @@ static gint sock_get_address_info_async_cancel(SockLookupData *lookup_data)
 
        return 0;
 }
+#endif /* G_OS_UNIX */
 
 
 static SockInfo *sockinfo_from_fd(const gchar *hostname,
@@ -1057,7 +1132,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_OPENSSL
@@ -1113,7 +1192,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_OPENSSL
index 2f0cbd9..d7ffa22 100644 (file)
@@ -25,7 +25,9 @@
 #endif
 
 #include <glib.h>
-#include <netdb.h>
+#if HAVE_NETDB_H
+#  include <netdb.h>
+#endif
 
 typedef struct _SockInfo       SockInfo;
 
@@ -67,6 +69,9 @@ struct _SockInfo
        GIOCondition condition;
 };
 
+gint sock_init                         (void);
+gint sock_cleanup                      (void);
+
 gint sock_set_io_timeout               (guint sec);
 
 gint sock_set_nonblocking_mode         (SockInfo *sock, gboolean nonblock);
@@ -79,9 +84,11 @@ struct hostent *my_gethostbyname     (const gchar *hostname);
 
 SockInfo *sock_connect                 (const gchar *hostname, gushort port);
 SockInfo *sock_connect_cmd             (const gchar *hostname, const gchar *tunnelcmd);
+#ifdef G_OS_UNIX
 gint sock_connect_async                        (const gchar *hostname, gushort port,
                                         SockConnectFunc func, gpointer data);
 gint sock_connect_async_cancel         (gint id);
+#endif
 
 /* Basic I/O functions */
 gint sock_printf       (SockInfo *sock, const gchar *format, ...)
index d37c62f..a2f6dc3 100644 (file)
@@ -111,7 +111,7 @@ static void ssl_certificate_save (SSLCertificate *cert)
                          cert->host, ".", port, ".cert", NULL);
 
        g_free(port);
-       fp = fopen(file, "wb");
+       fp = g_fopen(file, "wb");
        if (fp == NULL) {
                g_free(file);
                debug_print("Can't save certificate !\n");
@@ -233,7 +233,7 @@ void ssl_certificate_delete_from_disk(SSLCertificate *cert)
        file = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, 
                          "certs", G_DIR_SEPARATOR_S,
                          cert->host, ".", buf, ".cert", NULL);
-       unlink (file);
+       g_unlink (file);
        g_free(buf);
        g_free(file);
 }
@@ -263,7 +263,7 @@ SSLCertificate *ssl_certificate_find_lookup (gchar *host, gushort port, gboolean
                          fqdn_host, ".", buf, ".cert", NULL);
 
        g_free(buf);
-       fp = fopen(file, "rb");
+       fp = g_fopen(file, "rb");
        if (fp == NULL) {
                g_free(file);
                g_free(fqdn_host);
index 70edd03..7677f76 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Sylpheed templates subsystem 
  * Copyright (C) 2001 Alexander Barinov
- * Copyright (C) 2001 Hiroyuki Yamamoto
+ * Copyright (C) 2001-2005 Hiroyuki Yamamoto
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -23,7 +23,6 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <stdio.h>
-#include <dirent.h>
 #include <sys/stat.h>
 #include <ctype.h>
 
@@ -40,7 +39,7 @@ static Template *template_load(gchar *filename)
        gchar buf[BUFFSIZE];
        gint bytes_read;
 
-       if ((fp = fopen(filename, "rb")) == NULL) {
+       if ((fp = g_fopen(filename, "rb")) == NULL) {
                FILE_OP_ERROR(filename, "fopen");
                return NULL;
        }
@@ -125,8 +124,8 @@ GSList *template_read_config(void)
 {
        const gchar *path;
        gchar *filename;
-       DIR *dp;
-       struct dirent *de;
+       GDir *dir;
+       const gchar *dir_name;
        struct stat s;
        Template *tmpl;
        GSList *tmpl_list = NULL;
@@ -140,18 +139,16 @@ GSList *template_read_config(void)
                        return NULL;
        }
 
-       if ((dp = opendir(path)) == NULL) {
-               FILE_OP_ERROR(path, "opendir");
+       if ((dir = g_dir_open(path, 0, NULL)) == NULL) {
+               g_warning("failed to open directory: %s\n", path);
                return NULL;
        }
 
-       while ((de = readdir(dp)) != NULL) {
-               if (*de->d_name == '.') continue;
-
+       while ((dir_name = g_dir_read_name(dir)) != NULL) {
                filename = g_strconcat(path, G_DIR_SEPARATOR_S,
-                                      de->d_name, NULL);
+                                      dir_name, NULL);
 
-               if (stat(filename, &s) != 0 || !S_ISREG(s.st_mode) ) {
+               if (g_stat(filename, &s) != 0 || !S_ISREG(s.st_mode) ) {
                        debug_print("%s:%d %s is not an ordinary file\n",
                                    __FILE__, __LINE__, filename);
                        continue;
@@ -164,7 +161,7 @@ GSList *template_read_config(void)
                g_free(filename);
        }
 
-       closedir(dp);
+       g_dir_close(dir);
 
        return tmpl_list;
 }
@@ -201,7 +198,7 @@ void template_write_config(GSList *tmpl_list)
                filename = g_strconcat(path, G_DIR_SEPARATOR_S,
                                       itos(tmpl_num), NULL);
 
-               if ((fp = fopen(filename, "wb")) == NULL) {
+               if ((fp = g_fopen(filename, "wb")) == NULL) {
                        FILE_OP_ERROR(filename, "fopen");
                        g_free(filename);
                        return;
index 646788d..5e67221 100644 (file)
 #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>
 #include <regex.h>
 #include <sys/utsname.h>
 
+#ifdef G_OS_WIN32
+#  include <direct.h>
+#  include <io.h>
+#endif
+
 #include "utils.h"
 #include "socket.h"
 #include "../codeconv.h"
 
 static gboolean debug_mode = FALSE;
 
-static void hash_free_strings_func(gpointer key, gpointer value, gpointer data);
+
+#if !GLIB_CHECK_VERSION(2, 7, 0) && !defined(G_OS_UNIX)
+gint g_chdir(const gchar *path)
+{
+#ifdef G_OS_WIN32
+       if (G_WIN32_HAVE_WIDECHAR_API()) {
+               wchar_t *wpath;
+               gint retval;
+               gint save_errno;
+
+               wpath = g_utf8_to_utf16(path, -1, NULL, NULL, NULL);
+               if (wpath == NULL) {
+                       errno = EINVAL;
+                       return -1;
+               }
+
+               retval = _wchdir(wpath);
+               save_errno = errno;
+
+               g_free(wpath);
+
+               errno = save_errno;
+               return retval;
+       } else {
+               gchar *cp_path;
+               gint retval;
+               gint save_errno;
+
+               cp_path = g_locale_from_utf8(path, -1, NULL, NULL, NULL);
+               if (cp_path == NULL) {
+                       errno = EINVAL;
+                       return -1;
+               }
+
+               retval = chdir(cp_path);
+               save_errno = errno;
+
+               g_free(cp_path);
+
+               errno = save_errno;
+               return retval;
+       }
+#else
+       return chdir(path);
+#endif
+}
+
+gint g_chmod(const gchar *path, gint mode)
+{
+#ifdef G_OS_WIN32
+       if (G_WIN32_HAVE_WIDECHAR_API()) {
+               wchar_t *wpath;
+               gint retval;
+               gint save_errno;
+
+               wpath = g_utf8_to_utf16(path, -1, NULL, NULL, NULL);
+               if (wpath == NULL) {
+                       errno = EINVAL;
+                       return -1;
+               }
+
+               retval = _wchmod(wpath, mode);
+               save_errno = errno;
+
+               g_free(wpath);
+
+               errno = save_errno;
+               return retval;
+       } else {
+               gchar *cp_path;
+               gint retval;
+               gint save_errno;
+
+               cp_path = g_locale_from_utf8(path, -1, NULL, NULL, NULL);
+               if (cp_path == NULL) {
+                       errno = EINVAL;
+                       return -1;
+               }
+
+               retval = chmod(cp_path, mode);
+               save_errno = errno;
+
+               g_free(cp_path);
+
+               errno = save_errno;
+               return retval;
+       }
+#else
+       return chmod(path, mode);
+#endif
+}
+#endif /* GLIB_CHECK_VERSION && G_OS_UNIX */
 
 void list_free_strings(GList *list)
 {
@@ -123,9 +221,9 @@ guint str_case_hash(gconstpointer key)
        guint h = *p;
 
        if (h) {
-               h = tolower(h);
+               h = g_ascii_tolower(h);
                for (p += 1; *p != '\0'; p++)
-                       h = (h << 5) - h + tolower(*p);
+                       h = (h << 5) - h + g_ascii_tolower(*p);
        }
 
        return h;
@@ -1683,34 +1781,20 @@ gint scan_mailto_url(const gchar *mailto, gchar **to, gchar **cc, gchar **bcc,
        return 0;
 }
 
-/*
- * We need this wrapper around g_get_home_dir(), so that
- * we can fix some Windoze things here.  Should be done in glibc of course
- * but as long as we are not able to do our own extensions to glibc, we do
- * it here.
- */
 const gchar *get_home_dir(void)
 {
-#if HAVE_DOSISH_SYSTEM
-    static gchar *home_dir;
-
-    if (!home_dir) {
-        home_dir = read_w32_registry_string(NULL,
-                                            "Software\\Sylpheed", "HomeDir" );
-        if (!home_dir || !*home_dir) {
-            if (getenv ("HOMEDRIVE") && getenv("HOMEPATH")) {
-                const char *s = g_get_home_dir();
-                if (s && *s)
-                    home_dir = g_strdup (s);
-            }
-            if (!home_dir || !*home_dir) 
-                home_dir = g_strdup ("c:\\sylpheed");
-        }
-        debug_print("initialized home_dir to '%s'\n", home_dir);
-    }
-    return home_dir;
-#else /* standard glib */
-    return g_get_home_dir();
+#ifdef G_OS_WIN32
+       static const gchar *home_dir = NULL;
+
+       if (!home_dir) {
+               home_dir = g_get_home_dir();
+               if (!home_dir)
+                       home_dir = "C:\\Sylpheed";
+       }
+
+       return home_dir;
+#else
+       return g_get_home_dir();
 #endif
 }
 
@@ -1719,12 +1803,33 @@ const gchar *get_rc_dir(void)
        static gchar *rc_dir = NULL;
 
        if (!rc_dir)
+#ifdef G_OS_WIN32
+               rc_dir = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
+                                    "Application Data", G_DIR_SEPARATOR_S,
+                                    RC_DIR, NULL);
+#else
                rc_dir = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
                                     RC_DIR, NULL);
+#endif
 
        return rc_dir;
 }
 
+const gchar *get_mail_base_dir(void)
+{
+#ifdef G_OS_WIN32
+       static gchar *mail_base_dir = NULL;
+
+       if (!mail_base_dir)
+               mail_base_dir = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+                                           "Mailboxes", NULL);
+
+       return mail_base_dir;
+#else
+       return get_home_dir();
+#endif
+}
+
 const gchar *get_news_cache_dir(void)
 {
        static gchar *news_cache_dir = NULL;
@@ -1815,6 +1920,7 @@ gchar *get_tmp_file(void)
 
 const gchar *get_domain_name(void)
 {
+#ifdef G_OS_UNIX
        static gchar *domain_name = NULL;
 
        if (!domain_name) {
@@ -1837,13 +1943,16 @@ const gchar *get_domain_name(void)
        }
 
        return domain_name;
+#else
+       return "unknown";
+#endif
 }
 
 off_t get_file_size(const gchar *file)
 {
        struct stat s;
 
-       if (stat(file, &s) < 0) {
+       if (g_stat(file, &s) < 0) {
                FILE_OP_ERROR(file, "stat");
                return -1;
        }
@@ -1857,7 +1966,7 @@ off_t get_file_size_as_crlf(const gchar *file)
        off_t size = 0;
        gchar buf[BUFFSIZE];
 
-       if ((fp = fopen(file, "rb")) == NULL) {
+       if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return -1;
        }
@@ -1911,7 +2020,7 @@ gboolean file_exist(const gchar *file, gboolean allow_fifo)
        if (file == NULL)
                return FALSE;
 
-       if (stat(file, &s) < 0) {
+       if (g_stat(file, &s) < 0) {
                if (ENOENT != errno) FILE_OP_ERROR(file, "stat");
                return FALSE;
        }
@@ -1969,7 +2078,7 @@ gint change_dir(const gchar *dir)
        if (debug_mode)
                prevdir = g_get_current_dir();
 
-       if (chdir(dir) < 0) {
+       if (g_chdir(dir) < 0) {
                FILE_OP_ERROR(dir, "chdir");
                if (debug_mode) g_free(prevdir);
                return -1;
@@ -1988,11 +2097,11 @@ gint change_dir(const gchar *dir)
 
 gint make_dir(const gchar *dir)
 {
-       if (mkdir(dir, S_IRWXU) < 0) {
+       if (g_mkdir(dir, S_IRWXU) < 0) {
                FILE_OP_ERROR(dir, "mkdir");
                return -1;
        }
-       if (chmod(dir, S_IRWXU) < 0)
+       if (g_chmod(dir, S_IRWXU) < 0)
                FILE_OP_ERROR(dir, "chmod");
 
        return 0;
@@ -2026,36 +2135,32 @@ gint make_dir_hier(const gchar *dir)
 
 gint remove_all_files(const gchar *dir)
 {
-       DIR *dp;
-       struct dirent *d;
+       GDir *dp;
+       const gchar *dir_name;
        gchar *prev_dir;
 
        prev_dir = g_get_current_dir();
 
-       if (chdir(dir) < 0) {
+       if (g_chdir(dir) < 0) {
                FILE_OP_ERROR(dir, "chdir");
                g_free(prev_dir);
                return -1;
        }
 
-       if ((dp = opendir(".")) == NULL) {
-               FILE_OP_ERROR(dir, "opendir");
+       if ((dp = g_dir_open(".", 0, NULL)) == NULL) {
+               g_warning("failed to open directory: %s\n", dir);
                g_free(prev_dir);
                return -1;
        }
 
-       while ((d = readdir(dp)) != NULL) {
-               if (!strcmp(d->d_name, ".") ||
-                   !strcmp(d->d_name, ".."))
-                       continue;
-
-               if (unlink(d->d_name) < 0)
-                       FILE_OP_ERROR(d->d_name, "unlink");
+       while ((dir_name = g_dir_read_name(dp)) != NULL) {
+               if (g_unlink(dir_name) < 0)
+                       FILE_OP_ERROR(dir_name, "unlink");
        }
 
-       closedir(dp);
+       g_dir_close(dp);
 
-       if (chdir(prev_dir) < 0) {
+       if (g_chdir(prev_dir) < 0) {
                FILE_OP_ERROR(prev_dir, "chdir");
                g_free(prev_dir);
                return -1;
@@ -2068,38 +2173,38 @@ gint remove_all_files(const gchar *dir)
 
 gint remove_numbered_files(const gchar *dir, guint first, guint last)
 {
-       DIR *dp;
-       struct dirent *d;
+       GDir *dp;
+       const gchar *dir_name;
        gchar *prev_dir;
        gint file_no;
 
        prev_dir = g_get_current_dir();
 
-       if (chdir(dir) < 0) {
+       if (g_chdir(dir) < 0) {
                FILE_OP_ERROR(dir, "chdir");
                g_free(prev_dir);
                return -1;
        }
 
-       if ((dp = opendir(".")) == NULL) {
-               FILE_OP_ERROR(dir, "opendir");
+       if ((dp = g_dir_open(".", 0, NULL)) == NULL) {
+               g_warning("failed to open directory: %s\n", dir);
                g_free(prev_dir);
                return -1;
        }
 
-       while ((d = readdir(dp)) != NULL) {
-               file_no = to_number(d->d_name);
+       while ((dir_name = g_dir_read_name(dp)) != NULL) {
+               file_no = to_number(dir_name);
                if (file_no > 0 && first <= file_no && file_no <= last) {
-                       if (is_dir_exist(d->d_name))
+                       if (is_dir_exist(dir_name))
                                continue;
-                       if (unlink(d->d_name) < 0)
-                               FILE_OP_ERROR(d->d_name, "unlink");
+                       if (g_unlink(dir_name) < 0)
+                               FILE_OP_ERROR(dir_name, "unlink");
                }
        }
 
-       closedir(dp);
+       g_dir_close(dp);
 
-       if (chdir(prev_dir) < 0) {
+       if (g_chdir(prev_dir) < 0) {
                FILE_OP_ERROR(prev_dir, "chdir");
                g_free(prev_dir);
                return -1;
@@ -2112,39 +2217,39 @@ gint remove_numbered_files(const gchar *dir, guint first, guint last)
 
 gint remove_numbered_files_not_in_list(const gchar *dir, GSList *numberlist)
 {
-       DIR *dp;
-       struct dirent *d;
+       GDir *dp;
+       const gchar *dir_name;
        gchar *prev_dir;
        gint file_no;
 
        prev_dir = g_get_current_dir();
 
-       if (chdir(dir) < 0) {
+       if (g_chdir(dir) < 0) {
                FILE_OP_ERROR(dir, "chdir");
                g_free(prev_dir);
                return -1;
        }
 
-       if ((dp = opendir(".")) == NULL) {
+       if ((dp = g_dir_open(".", 0, NULL)) == NULL) {
                FILE_OP_ERROR(dir, "opendir");
                g_free(prev_dir);
                return -1;
        }
 
-       while ((d = readdir(dp)) != NULL) {
-               file_no = to_number(d->d_name);
+       while ((dir_name = g_dir_read_name(dp)) != NULL) {
+               file_no = to_number(dir_name);
                if (file_no > 0 && (g_slist_find(numberlist, GINT_TO_POINTER(file_no)) == NULL)) {
                        debug_print("removing unwanted file %d from %s\n", file_no, dir);
-                       if (is_dir_exist(d->d_name))
+                       if (is_dir_exist(dir_name))
                                continue;
-                       if (unlink(d->d_name) < 0)
-                               FILE_OP_ERROR(d->d_name, "unlink");
+                       if (g_unlink(dir_name) < 0)
+                               FILE_OP_ERROR(dir_name, "unlink");
                }
        }
 
-       closedir(dp);
+       g_dir_close(dp);
 
-       if (chdir(prev_dir) < 0) {
+       if (g_chdir(prev_dir) < 0) {
                FILE_OP_ERROR(prev_dir, "chdir");
                g_free(prev_dir);
                return -1;
@@ -2162,8 +2267,8 @@ gint remove_all_numbered_files(const gchar *dir)
 
 gint remove_expired_files(const gchar *dir, guint hours)
 {
-       DIR *dp;
-       struct dirent *d;
+       GDir *dp;
+       const gchar *dir_name;
        struct stat s;
        gchar *prev_dir;
        gint file_no;
@@ -2171,14 +2276,14 @@ gint remove_expired_files(const gchar *dir, guint hours)
 
        prev_dir = g_get_current_dir();
 
-       if (chdir(dir) < 0) {
+       if (g_chdir(dir) < 0) {
                FILE_OP_ERROR(dir, "chdir");
                g_free(prev_dir);
                return -1;
        }
 
-       if ((dp = opendir(".")) == NULL) {
-               FILE_OP_ERROR(dir, "opendir");
+       if ((dp = g_dir_open(".", 0, NULL)) == NULL) {
+               g_warning("failed to open directory: %s\n", dir);
                g_free(prev_dir);
                return -1;
        }
@@ -2186,26 +2291,26 @@ gint remove_expired_files(const gchar *dir, guint hours)
        now = time(NULL);
        expire_time = hours * 60 * 60;
 
-       while ((d = readdir(dp)) != NULL) {
-               file_no = to_number(d->d_name);
+       while ((dir_name = g_dir_read_name(dp)) != NULL) {
+               file_no = to_number(dir_name);
                if (file_no > 0) {
-                       if (stat(d->d_name, &s) < 0) {
-                               FILE_OP_ERROR(d->d_name, "stat");
+                       if (g_stat(dir_name, &s) < 0) {
+                               FILE_OP_ERROR(dir_name, "stat");
                                continue;
                        }
                        if (S_ISDIR(s.st_mode))
                                continue;
                        mtime = MAX(s.st_mtime, s.st_atime);
                        if (now - mtime > expire_time) {
-                               if (unlink(d->d_name) < 0)
-                                       FILE_OP_ERROR(d->d_name, "unlink");
+                               if (g_unlink(dir_name) < 0)
+                                       FILE_OP_ERROR(dir_name, "unlink");
                        }
                }
        }
 
-       closedir(dp);
+       g_dir_close(dp);
 
-       if (chdir(prev_dir) < 0) {
+       if (g_chdir(prev_dir) < 0) {
                FILE_OP_ERROR(prev_dir, "chdir");
                g_free(prev_dir);
                return -1;
@@ -2219,20 +2324,18 @@ gint remove_expired_files(const gchar *dir, guint hours)
 gint remove_dir_recursive(const gchar *dir)
 {
        struct stat s;
-       DIR *dp;
-       struct dirent *d;
+       GDir *dp;
+       const gchar *dir_name;
        gchar *prev_dir;
 
-       /* g_print("dir = %s\n", dir); */
-
-       if (stat(dir, &s) < 0) {
+       if (g_stat(dir, &s) < 0) {
                FILE_OP_ERROR(dir, "stat");
                if (ENOENT == errno) return 0;
                return -1;
        }
 
        if (!S_ISDIR(s.st_mode)) {
-               if (unlink(dir) < 0) {
+               if (g_unlink(dir) < 0) {
                        FILE_OP_ERROR(dir, "unlink");
                        return -1;
                }
@@ -2245,48 +2348,44 @@ gint remove_dir_recursive(const gchar *dir)
 
        if (!path_cmp(prev_dir, dir)) {
                g_free(prev_dir);
-               if (chdir("..") < 0) {
+               if (g_chdir("..") < 0) {
                        FILE_OP_ERROR(dir, "chdir");
                        return -1;
                }
                prev_dir = g_get_current_dir();
        }
 
-       if (chdir(dir) < 0) {
+       if (g_chdir(dir) < 0) {
                FILE_OP_ERROR(dir, "chdir");
                g_free(prev_dir);
                return -1;
        }
 
-       if ((dp = opendir(".")) == NULL) {
-               FILE_OP_ERROR(dir, "opendir");
-               chdir(prev_dir);
+       if ((dp = g_dir_open(".", 0, NULL)) == NULL) {
+               g_warning("failed to open directory: %s\n", dir);
+               g_chdir(prev_dir);
                g_free(prev_dir);
                return -1;
        }
 
        /* remove all files in the directory */
-       while ((d = readdir(dp)) != NULL) {
-               if (!strcmp(d->d_name, ".") ||
-                   !strcmp(d->d_name, ".."))
-                       continue;
+       while ((dir_name = g_dir_read_name(dp)) != NULL) {
+               /* g_print("removing %s\n", dir_name); */
 
-               /* g_print("removing %s\n", d->d_name); */
-
-               if (dirent_is_directory(d)) {
-                       if (remove_dir_recursive(d->d_name) < 0) {
+               if (is_dir_exist(dir_name)) {
+                       if (remove_dir_recursive(dir_name) < 0) {
                                g_warning("can't remove directory\n");
                                return -1;
                        }
                } else {
-                       if (unlink(d->d_name) < 0)
-                               FILE_OP_ERROR(d->d_name, "unlink");
+                       if (g_unlink(dir_name) < 0)
+                               FILE_OP_ERROR(dir_name, "unlink");
                }
        }
 
-       closedir(dp);
+       g_dir_close(dp);
 
-       if (chdir(prev_dir) < 0) {
+       if (g_chdir(prev_dir) < 0) {
                FILE_OP_ERROR(prev_dir, "chdir");
                g_free(prev_dir);
                return -1;
@@ -2294,7 +2393,7 @@ gint remove_dir_recursive(const gchar *dir)
 
        g_free(prev_dir);
 
-       if (rmdir(dir) < 0) {
+       if (g_rmdir(dir) < 0) {
                FILE_OP_ERROR(dir, "rmdir");
                return -1;
        }
@@ -2302,6 +2401,21 @@ gint remove_dir_recursive(const gchar *dir)
        return 0;
 }
 
+gint rename_force(const gchar *oldpath, const gchar *newpath)
+{
+#ifndef G_OS_UNIX
+       if (!is_file_entry_exist(oldpath)) {
+               errno = ENOENT;
+               return -1;
+       }
+       if (is_file_exist(newpath)) {
+               if (g_unlink(newpath) < 0)
+                       FILE_OP_ERROR(newpath, "unlink");
+       }
+#endif
+       return g_rename(oldpath, newpath);
+}
+
 #if 0
 /* this seems to be slower than the stdio version... */
 gint copy_file(const gchar *src, const gchar *dest)
@@ -2319,7 +2433,7 @@ gint copy_file(const gchar *src, const gchar *dest)
 
        if (is_file_exist(dest)) {
                dest_bak = g_strconcat(dest, ".bak", NULL);
-               if (rename(dest, dest_bak) < 0) {
+               if (rename_force(dest, dest_bak) < 0) {
                        FILE_OP_ERROR(dest, "rename");
                        close(src_fd);
                        g_free(dest_bak);
@@ -2348,7 +2462,7 @@ gint copy_file(const gchar *src, const gchar *dest)
                                g_warning("writing to %s failed.\n", dest);
                                close(dest_fd);
                                close(src_fd);
-                               unlink(dest);
+                               g_unlink(dest);
                                if (dest_bak) {
                                        if (rename(dest_bak, dest) < 0)
                                                FILE_OP_ERROR(dest_bak, "rename");
@@ -2366,7 +2480,7 @@ gint copy_file(const gchar *src, const gchar *dest)
 
        if (n_read < 0 || get_file_size(src) != get_file_size(dest)) {
                g_warning("File copy from %s to %s failed.\n", src, dest);
-               unlink(dest);
+               g_unlink(dest);
                if (dest_bak) {
                        if (rename(dest_bak, dest) < 0)
                                FILE_OP_ERROR(dest_bak, "rename");
@@ -2393,12 +2507,12 @@ gint append_file(const gchar *src, const gchar *dest, gboolean keep_backup)
 
        gboolean err = FALSE;
 
-       if ((src_fp = fopen(src, "rb")) == NULL) {
+       if ((src_fp = g_fopen(src, "rb")) == NULL) {
                FILE_OP_ERROR(src, "fopen");
                return -1;
        }
        
-       if ((dest_fp = fopen(dest, "ab")) == NULL) {
+       if ((dest_fp = g_fopen(dest, "ab")) == NULL) {
                FILE_OP_ERROR(dest, "fopen");
                fclose(src_fp);
                return -1;
@@ -2416,7 +2530,7 @@ gint append_file(const gchar *src, const gchar *dest, gboolean keep_backup)
                        g_warning("writing to %s failed.\n", dest);
                        fclose(dest_fp);
                        fclose(src_fp);
-                       unlink(dest);
+                       g_unlink(dest);
                        return -1;
                }
        }
@@ -2432,7 +2546,7 @@ gint append_file(const gchar *src, const gchar *dest, gboolean keep_backup)
        }
 
        if (err) {
-               unlink(dest);
+               g_unlink(dest);
                return -1;
        }
 
@@ -2447,13 +2561,13 @@ gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup)
        gchar *dest_bak = NULL;
        gboolean err = FALSE;
 
-       if ((src_fp = fopen(src, "rb")) == NULL) {
+       if ((src_fp = g_fopen(src, "rb")) == NULL) {
                FILE_OP_ERROR(src, "fopen");
                return -1;
        }
        if (is_file_exist(dest)) {
                dest_bak = g_strconcat(dest, ".bak", NULL);
-               if (rename(dest, dest_bak) < 0) {
+               if (rename_force(dest, dest_bak) < 0) {
                        FILE_OP_ERROR(dest, "rename");
                        fclose(src_fp);
                        g_free(dest_bak);
@@ -2461,11 +2575,11 @@ gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup)
                }
        }
 
-       if ((dest_fp = fopen(dest, "wb")) == NULL) {
+       if ((dest_fp = g_fopen(dest, "wb")) == NULL) {
                FILE_OP_ERROR(dest, "fopen");
                fclose(src_fp);
                if (dest_bak) {
-                       if (rename(dest_bak, dest) < 0)
+                       if (rename_force(dest_bak, dest) < 0)
                                FILE_OP_ERROR(dest_bak, "rename");
                        g_free(dest_bak);
                }
@@ -2484,9 +2598,9 @@ gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup)
                        g_warning("writing to %s failed.\n", dest);
                        fclose(dest_fp);
                        fclose(src_fp);
-                       unlink(dest);
+                       g_unlink(dest);
                        if (dest_bak) {
-                               if (rename(dest_bak, dest) < 0)
+                               if (rename_force(dest_bak, dest) < 0)
                                        FILE_OP_ERROR(dest_bak, "rename");
                                g_free(dest_bak);
                        }
@@ -2505,9 +2619,9 @@ gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup)
        }
 
        if (err) {
-               unlink(dest);
+               g_unlink(dest);
                if (dest_bak) {
-                       if (rename(dest_bak, dest) < 0)
+                       if (rename_force(dest_bak, dest) < 0)
                                FILE_OP_ERROR(dest_bak, "rename");
                        g_free(dest_bak);
                }
@@ -2515,7 +2629,7 @@ gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup)
        }
 
        if (keep_backup == FALSE && dest_bak)
-               unlink(dest_bak);
+               g_unlink(dest_bak);
 
        g_free(dest_bak);
 
@@ -2529,7 +2643,7 @@ gint move_file(const gchar *src, const gchar *dest, gboolean overwrite)
                return -1;
        }
 
-       if (rename(src, dest) == 0) return 0;
+       if (rename_force(src, dest) == 0) return 0;
 
        if (EXDEV != errno) {
                FILE_OP_ERROR(src, "rename");
@@ -2538,7 +2652,7 @@ gint move_file(const gchar *src, const gchar *dest, gboolean overwrite)
 
        if (copy_file(src, dest, FALSE) < 0) return -1;
 
-       unlink(src);
+       g_unlink(src);
 
        return 0;
 }
@@ -2582,7 +2696,7 @@ gint copy_file_part(FILE *fp, off_t offset, size_t length, const gchar *dest)
        FILE *dest_fp;
        gboolean err = FALSE;
 
-       if ((dest_fp = fopen(dest, "wb")) == NULL) {
+       if ((dest_fp = g_fopen(dest, "wb")) == NULL) {
                FILE_OP_ERROR(dest, "fopen");
                return -1;
        }
@@ -2602,7 +2716,7 @@ gint copy_file_part(FILE *fp, off_t offset, size_t length, const gchar *dest)
 
        if (err) {
                g_warning("writing to %s failed.\n", dest);
-               unlink(dest);
+               g_unlink(dest);
                return -1;
        }
 
@@ -2653,12 +2767,12 @@ gint canonicalize_file(const gchar *src, const gchar *dest)
        gboolean err = FALSE;
        gboolean last_linebreak = FALSE;
 
-       if ((src_fp = fopen(src, "rb")) == NULL) {
+       if ((src_fp = g_fopen(src, "rb")) == NULL) {
                FILE_OP_ERROR(src, "fopen");
                return -1;
        }
 
-       if ((dest_fp = fopen(dest, "wb")) == NULL) {
+       if ((dest_fp = g_fopen(dest, "wb")) == NULL) {
                FILE_OP_ERROR(dest, "fopen");
                fclose(src_fp);
                return -1;
@@ -2695,7 +2809,7 @@ gint canonicalize_file(const gchar *src, const gchar *dest)
                        g_warning("writing to %s failed.\n", dest);
                        fclose(dest_fp);
                        fclose(src_fp);
-                       unlink(dest);
+                       g_unlink(dest);
                        return -1;
                }
        }
@@ -2716,7 +2830,7 @@ gint canonicalize_file(const gchar *src, const gchar *dest)
        }
 
        if (err) {
-               unlink(dest);
+               g_unlink(dest);
                return -1;
        }
 
@@ -2736,7 +2850,7 @@ gint canonicalize_file_replace(const gchar *file)
 
        if (move_file(tmp_file, file, TRUE) < 0) {
                g_warning("can't replace %s .\n", file);
-               unlink(tmp_file);
+               g_unlink(tmp_file);
                g_free(tmp_file);
                return -1;
        }
@@ -2751,12 +2865,12 @@ gint uncanonicalize_file(const gchar *src, const gchar *dest)
        gchar buf[BUFFSIZE];
        gboolean err = FALSE;
 
-       if ((src_fp = fopen(src, "rb")) == NULL) {
+       if ((src_fp = g_fopen(src, "rb")) == NULL) {
                FILE_OP_ERROR(src, "fopen");
                return -1;
        }
 
-       if ((dest_fp = fopen(dest, "wb")) == NULL) {
+       if ((dest_fp = g_fopen(dest, "wb")) == NULL) {
                FILE_OP_ERROR(dest, "fopen");
                fclose(src_fp);
                return -1;
@@ -2773,7 +2887,7 @@ gint uncanonicalize_file(const gchar *src, const gchar *dest)
                        g_warning("writing to %s failed.\n", dest);
                        fclose(dest_fp);
                        fclose(src_fp);
-                       unlink(dest);
+                       g_unlink(dest);
                        return -1;
                }
        }
@@ -2789,7 +2903,7 @@ gint uncanonicalize_file(const gchar *src, const gchar *dest)
        }
 
        if (err) {
-               unlink(dest);
+               g_unlink(dest);
                return -1;
        }
 
@@ -2809,7 +2923,7 @@ gint uncanonicalize_file_replace(const gchar *file)
 
        if (move_file(tmp_file, file, TRUE) < 0) {
                g_warning("can't replace %s .\n", file);
-               unlink(tmp_file);
+               g_unlink(tmp_file);
                g_free(tmp_file);
                return -1;
        }
@@ -2911,18 +3025,9 @@ gchar *generate_mime_boundary(const gchar *prefix)
        gchar buf_uniq[17];
        gchar buf_date[64];
        gint i;
-       gint pid;
-
-       pid = getpid();
 
-       /* We make the boundary depend on the pid, so that all running
-        * processes generate different values even when they have been
-        * started within the same second and srandom(time(NULL)) has been
-        * used.  I can't see whether this is really an advantage but it
-        * doesn't do any harm.
-        */
        for (i = 0; i < sizeof(buf_uniq) - 1; i++)
-               buf_uniq[i] = tbl[(rand() ^ pid) % (sizeof(tbl) - 1)];
+               buf_uniq[i] = tbl[g_random_int_range(0, sizeof(tbl) - 1)];
        buf_uniq[i] = '\0';
 
        get_rfc822_date(buf_date, sizeof(buf_date));
@@ -2939,7 +3044,7 @@ gint change_file_mode_rw(FILE *fp, const gchar *file)
 #if HAVE_FCHMOD
        return fchmod(fileno(fp), S_IRUSR|S_IWUSR);
 #else
-       return chmod(file, S_IRUSR|S_IWUSR);
+       return g_chmod(file, S_IRUSR|S_IWUSR);
 #endif
 }
 
@@ -2973,7 +3078,7 @@ FILE *my_tmpfile(void)
        if (fd < 0)
                return tmpfile();
 
-       unlink(fname);
+       g_unlink(fname);
 
        fp = fdopen(fd, "w+b");
        if (!fp)
@@ -3029,7 +3134,7 @@ gint str_write_to_file(const gchar *str, const gchar *file)
        g_return_val_if_fail(str != NULL, -1);
        g_return_val_if_fail(file != NULL, -1);
 
-       if ((fp = fopen(file, "wb")) == NULL) {
+       if ((fp = g_fopen(file, "wb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return -1;
        }
@@ -3043,13 +3148,13 @@ gint str_write_to_file(const gchar *str, const gchar *file)
        if (fwrite(str, 1, len, fp) != len) {
                FILE_OP_ERROR(file, "fwrite");
                fclose(fp);
-               unlink(file);
+               g_unlink(file);
                return -1;
        }
 
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(file, "fclose");
-               unlink(file);
+               g_unlink(file);
                return -1;
        }
 
@@ -3063,7 +3168,7 @@ gchar *file_read_to_str(const gchar *file)
 
        g_return_val_if_fail(file != NULL, NULL);
 
-       if ((fp = fopen(file, "rb")) == NULL) {
+       if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return NULL;
        }
@@ -3118,63 +3223,37 @@ gchar *file_read_stream_to_str(FILE *fp)
 
 gint execute_async(gchar *const argv[])
 {
-       pid_t pid;
-       gint status;
+       g_return_val_if_fail(argv != NULL && argv[0] != NULL, -1);
 
-       if ((pid = fork()) < 0) {
-               perror("fork");
+       if (g_spawn_async(NULL, (gchar **)argv, NULL, G_SPAWN_SEARCH_PATH,
+                         NULL, NULL, NULL, FALSE) == FALSE) {
+               g_warning("Can't execute command: %s\n", argv[0]);
                return -1;
        }
 
-       if (pid == 0) {                 /* child process */
-               pid_t gch_pid;
-
-               if ((gch_pid = fork()) < 0) {
-                       perror("fork");
-                       _exit(1);
-               }
-
-               if (gch_pid == 0) {     /* grandchild process */
-                       execvp(argv[0], argv);
-
-                       perror("execvp");
-                       _exit(1);
-               }
-
-               _exit(0);
-       }
-
-       waitpid(pid, &status, 0);
-
-       if (WIFEXITED(status))
-               return WEXITSTATUS(status);
-       else
-               return -1;
+       return 0;
 }
 
 gint execute_sync(gchar *const argv[])
 {
-       pid_t pid;
        gint status;
 
-       if ((pid = fork()) < 0) {
-               perror("fork");
-               return -1;
-       }
-
-       if (pid == 0) {         /* child process */
-               execvp(argv[0], argv);
+       g_return_val_if_fail(argv != NULL && argv[0] != NULL, -1);
 
-               perror("execvp");
-               _exit(1);
+       if (g_spawn_sync(NULL, (gchar **)argv, NULL, G_SPAWN_SEARCH_PATH,
+                        NULL, NULL, NULL, NULL, &status, NULL) == FALSE) {
+               g_warning("Can't execute command: %s\n", argv[0]);
+               return -1;
        }
 
-       waitpid(pid, &status, 0);
-
+#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)
@@ -3182,7 +3261,7 @@ gint execute_command_line(const gchar *cmdline, gboolean async)
        gchar **argv;
        gint ret;
 
-       debug_print("executing: %s\n", cmdline);
+       debug_print("execute_command_line(): executing: %s\n", cmdline);
 
        argv = strsplit_with_quote(cmdline, " ", 0);
 
@@ -3203,6 +3282,8 @@ gchar *get_command_output(const gchar *cmdline)
 
        g_return_val_if_fail(cmdline != NULL, NULL);
 
+       debug_print("get_command_output(): executing: %s\n", cmdline);
+
        if (g_spawn_command_line_sync(cmdline, &child_stdout, NULL, &status,
                                      NULL) == FALSE) {
                g_warning("Can't execute command: %s\n", cmdline);
index 0dae156..80b4f54 100644 (file)
 #  include <wchar.h>
 #endif
 
+/* Wrappers for C library function that take pathname arguments. */
+#if GLIB_CHECK_VERSION(2, 6, 0)
+#  include <glib/gstdio.h>
+#else
+
+#define g_open         open
+#define g_rename       rename
+#define g_mkdir                mkdir
+#define g_stat         stat
+#define g_lstat                lstat
+#define g_unlink       unlink
+#define g_remove       remove
+#define g_rmdir                rmdir
+#define g_fopen                fopen
+#define g_freopen      freopen
+
+#endif /* GLIB_CHECK_VERSION */
+
+#if !GLIB_CHECK_VERSION(2, 7, 0)
+
+#ifdef G_OS_UNIX
+#define g_chdir                chdir
+#define g_chmod                chmod
+#else
+gint g_chdir   (const gchar    *path);
+gint g_chmod   (const gchar    *path,
+                gint            mode);
+#endif /* G_OS_UNIX */
+
+#endif /* !GLIB_CHECK_VERSION */
+
 /* The AC_CHECK_SIZEOF() in configure fails for some machines.
  * we provide some fallback values here */
 #if !SIZEOF_UNSIGNED_SHORT
 #define FILE_OP_ERROR(file, func) \
 { \
        fprintf(stderr, "%s: ", file); \
+       fflush(stderr); \
        perror(func); \
 }
 
@@ -359,6 +391,7 @@ gint scan_mailto_url                        (const gchar    *mailto,
 /* return static strings */
 const gchar *get_home_dir              (void);
 const gchar *get_rc_dir                        (void);
+const gchar *get_mail_base_dir         (void);
 const gchar *get_news_cache_dir                (void);
 const gchar *get_imap_cache_dir                (void);
 const gchar *get_mbox_cache_dir                (void);
@@ -400,6 +433,8 @@ gint remove_dir_recursive   (const gchar    *dir);
 gint append_file               (const gchar    *src,
                                 const gchar    *dest,
                                 gboolean        keep_backup);
+gint rename_force              (const gchar    *oldpath,
+                                const gchar    *newpath);
 gint copy_file                 (const gchar    *src,
                                 const gchar    *dest,
                                 gboolean        keep_backup);
index b561bd5..63ba7b4 100644 (file)
@@ -73,7 +73,7 @@ XMLFile *xml_open_file(const gchar *path)
 
        newfile = g_new(XMLFile, 1);
 
-       newfile->fp = fopen(path, "rb");
+       newfile->fp = g_fopen(path, "rb");
        if (!newfile->fp) {
                g_free(newfile);
                return NULL;
index 29872dc..4e3f9c4 100644 (file)
 #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>
 #include <libgen.h>
@@ -298,6 +299,7 @@ static gboolean attach_property_key_pressed (GtkWidget      *widget,
                                                 gboolean       *cancelled);
 
 static void compose_exec_ext_editor            (Compose        *compose);
+#ifdef G_OS_UNIX
 static gint compose_exec_ext_editor_real       (const gchar    *file);
 static gboolean compose_ext_editor_kill                (Compose        *compose);
 static gboolean compose_input_cb               (GIOChannel     *source,
@@ -305,6 +307,7 @@ static gboolean compose_input_cb            (GIOChannel     *source,
                                                 gpointer        data);
 static void compose_set_ext_editor_sensitive   (Compose        *compose,
                                                 gboolean        sensitive);
+#endif /* G_OS_UNIX */
 
 static void compose_undo_state_changed         (UndoMain       *undostruct,
                                                 gint            undo_state,
@@ -2337,7 +2340,7 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
 
        g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
 
-       if ((fp = fopen(file, "rb")) == NULL) {
+       if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return COMPOSE_INSERT_READ_ERROR;
        }
@@ -2419,7 +2422,7 @@ static void compose_attach_append(Compose *compose, const gchar *file,
                alertpanel_notice(_("File %s is empty."), filename);
                return;
        }
-       if ((fp = fopen(file, "rb")) == NULL) {
+       if ((fp = g_fopen(file, "rb")) == NULL) {
                alertpanel_error(_("Can't read %s."), filename);
                return;
        }
@@ -3566,7 +3569,7 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
        size_t len;
        gchar buf[BUFFSIZE];
 
-       if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
+       if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
                FILE_OP_ERROR(compose->redirect_filename, "fopen");
                return -1;
        }
@@ -3804,7 +3807,7 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file)
        size_t len;
        gchar *chars, *tmp;
 
-       if ((fp = fopen(file, "wb")) == NULL) {
+       if ((fp = g_fopen(file, "wb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return -1;
        }
@@ -3832,7 +3835,7 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file)
                FILE_OP_ERROR(file, "fwrite");
                g_free(chars);
                fclose(fp);
-               unlink(file);
+               g_unlink(file);
                return -1;
        }
 
@@ -3840,7 +3843,7 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file)
 
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(file, "fclose");
-               unlink(file);
+               g_unlink(file);
                return -1;
        }
        return 0;
@@ -3940,7 +3943,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        /* write queue header */
        tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
                              G_DIR_SEPARATOR, compose);
-       if ((fp = fopen(tmp, "wb")) == NULL) {
+       if ((fp = g_fopen(tmp, "wb")) == NULL) {
                FILE_OP_ERROR(tmp, "fopen");
                g_free(tmp);
                return -2;
@@ -4042,7 +4045,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                if (compose_redirect_write_to_file(compose, fp) < 0) {
                        lock = FALSE;
                        fclose(fp);
-                       unlink(tmp);
+                       g_unlink(tmp);
                        g_free(tmp);
                        return -2;
                }
@@ -4050,7 +4053,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND) < 0) {
                        lock = FALSE;
                        fclose(fp);
-                       unlink(tmp);
+                       g_unlink(tmp);
                        g_free(tmp);
                        return -2;
                }
@@ -4058,7 +4061,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
 
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(tmp, "fclose");
-               unlink(tmp);
+               g_unlink(tmp);
                g_free(tmp);
                return -2;
        }
@@ -4066,18 +4069,18 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        queue = account_get_special_folder(compose->account, F_QUEUE);
        if (!queue) {
                g_warning("can't find queue folder\n");
-               unlink(tmp);
+               g_unlink(tmp);
                g_free(tmp);
                return -1;
        }
        folder_item_scan(queue);
        if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
                g_warning("can't queue the message\n");
-               unlink(tmp);
+               g_unlink(tmp);
                g_free(tmp);
                return -1;
        }
-       unlink(tmp);
+       g_unlink(tmp);
        g_free(tmp);
 
        if (compose->mode == COMPOSE_REEDIT) {
@@ -4253,8 +4256,6 @@ static gchar *compose_get_header(Compose *compose)
        gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
        GString *header;
 
-       /* struct utsname utsbuf; */
-
        g_return_val_if_fail(compose->account != NULL, NULL);
        g_return_val_if_fail(compose->account->address != NULL, NULL);
 
@@ -4335,21 +4336,18 @@ static gchar *compose_get_header(Compose *compose)
        }
 
        /* Program version and system info */
-       /* uname(&utsbuf); */
        if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
            !compose->newsgroup_list) {
                g_string_append_printf(header, "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 (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
                g_string_append_printf(header, "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 */
@@ -5967,6 +5965,7 @@ static gboolean attach_property_key_pressed(GtkWidget *widget,
 
 static void compose_exec_ext_editor(Compose *compose)
 {
+#ifdef G_OS_UNIX
        gchar *tmp;
        pid_t pid;
        gint pipe_fds[2];
@@ -6030,8 +6029,10 @@ static void compose_exec_ext_editor(Compose *compose)
        }
 
        g_free(tmp);
+#endif /* G_OS_UNIX */
 }
 
+#ifdef G_OS_UNIX
 static gint compose_exec_ext_editor_real(const gchar *file)
 {
        static gchar *def_cmd = "emacs %s";
@@ -6145,11 +6146,11 @@ static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
                compose_insert_file(compose, compose->exteditor_file);
                compose_changed_cb(NULL, compose);
 
-               if (unlink(compose->exteditor_file) < 0)
+               if (g_unlink(compose->exteditor_file) < 0)
                        FILE_OP_ERROR(compose->exteditor_file, "unlink");
        } else if (buf[0] == '1') {     /* failed */
                g_warning("Couldn't exec external editor\n");
-               if (unlink(compose->exteditor_file) < 0)
+               if (g_unlink(compose->exteditor_file) < 0)
                        FILE_OP_ERROR(compose->exteditor_file, "unlink");
        } else if (buf[0] == '2') {
                g_warning("Couldn't write to file\n");
@@ -6194,6 +6195,7 @@ static void compose_set_ext_editor_sensitive(Compose *compose,
        gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn,  sensitive);
        gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn,  sensitive);
 }
+#endif /* G_OS_UNIX */
 
 /**
  * compose_undo_state_changed:
@@ -6428,7 +6430,7 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
 
        tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
                              G_DIR_SEPARATOR, compose);
-       if ((fp = fopen(tmp, "wb")) == NULL) {
+       if ((fp = g_fopen(tmp, "wb")) == NULL) {
                FILE_OP_ERROR(tmp, "fopen");
                return;
        }
@@ -6458,7 +6460,7 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
 
        if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
                fclose(fp);
-               unlink(tmp);
+               g_unlink(tmp);
                g_free(tmp);
                lock = FALSE;
                return;
@@ -6467,7 +6469,7 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
 
        folder_item_scan(draft);
        if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
-               unlink(tmp);
+               g_unlink(tmp);
                g_free(tmp);
                lock = FALSE;
                return;
@@ -6502,7 +6504,7 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
 
                path = folder_item_fetch_msg(draft, msgnum);
                g_return_if_fail(path != NULL);
-               if (stat(path, &s) < 0) {
+               if (g_stat(path, &s) < 0) {
                        FILE_OP_ERROR(path, "stat");
                        g_free(path);
                        lock = FALSE;
@@ -6610,10 +6612,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(_("Discard message"),
@@ -7228,7 +7232,7 @@ static void compose_insert_drag_received_cb (GtkWidget            *widget,
                gchar *tmpfile = get_tmp_file();
                str_write_to_file((const gchar *)data->data, tmpfile);
                compose_insert_file(compose, tmpfile);
-               unlink(tmpfile);
+               g_unlink(tmpfile);
                g_free(tmpfile);
                gtk_drag_finish(drag_context, TRUE, FALSE, time);
                return;
index ff91cd9..1922331 100644 (file)
@@ -544,7 +544,7 @@ static void crash_cleanup_exit(void)
 {
        extern gchar *get_socket_name(void);
        const char *filename = get_socket_name();
-       unlink(filename);
+       g_unlink(filename);
 }
 
 #endif
index 07346b9..35e8791 100644 (file)
@@ -284,12 +284,12 @@ void exporthtml_set_attributes( ExportHtmlCtl *ctl, const gboolean value ) {
 static gint exporthtml_create_css_dfl( const gchar *fileSpec ) {
        FILE *cssFile;
 
-       cssFile = fopen( fileSpec, "rb" );
+       cssFile = g_fopen( fileSpec, "rb" );
        if( cssFile ) {
                fclose( cssFile );
                return MGU_SUCCESS;
        }
-       cssFile = fopen( fileSpec, "wb" );
+       cssFile = g_fopen( fileSpec, "wb" );
        if( ! cssFile ) {
                return MGU_OPEN_FILE;
        }
@@ -342,12 +342,12 @@ static gint exporthtml_create_css_dfl( const gchar *fileSpec ) {
 static gint exporthtml_create_css_full( const gchar *fileSpec ) {
        FILE *cssFile;
 
-       cssFile = fopen( fileSpec, "rb" );
+       cssFile = g_fopen( fileSpec, "rb" );
        if( cssFile ) {
                fclose( cssFile );
                return MGU_SUCCESS;
        }
-       cssFile = fopen( fileSpec, "wb" );
+       cssFile = g_fopen( fileSpec, "wb" );
        if( ! cssFile ) {
                return MGU_OPEN_FILE;
        }
@@ -990,7 +990,7 @@ void exporthtml_process(
        gchar *dsName;
        static gchar *title;
 
-       htmlFile = fopen( ctl->path, "wb" );
+       htmlFile = g_fopen( ctl->path, "wb" );
        if( ! htmlFile ) {
                /* Cannot open file */
                printf( "Cannot open file for write\n" );
index 805be08..3abfa2a 100644 (file)
@@ -501,7 +501,7 @@ void exportldif_process( ExportLdifCtl *ctl, AddressCache *cache )
        ItemFolder *rootFolder;
        FILE *ldifFile;
 
-       ldifFile = fopen( ctl->path, "wb" );
+       ldifFile = g_fopen( ctl->path, "wb" );
        if( ! ldifFile ) {
                /* Cannot open file */
                ctl->retVal = MGU_OPEN_FILE;
index 359ecaf..1ff7460 100644 (file)
@@ -2316,7 +2316,7 @@ static gint folder_item_get_msg_num_by_file(FolderItem *dest, const gchar *file)
        gint msgnum = 0;
        gchar buf[BUFFSIZE];
 
-       if ((fp = fopen(file, "rb")) == NULL)
+       if ((fp = g_fopen(file, "rb")) == NULL)
                return 0;
 
        if ((folder_has_parent_of_type(dest, F_QUEUE)) || 
@@ -2507,7 +2507,7 @@ gint folder_item_add_msgs(FolderItem *dest, GSList *file_list,
                                lastnum = num;
 
                        if (num >= 0 && remove_source) {
-                               if (unlink(fileinfo->file) < 0)
+                               if (g_unlink(fileinfo->file) < 0)
                                        FILE_OP_ERROR(fileinfo->file, "unlink");
                        }
 
index 9c34a39..a261abf 100644 (file)
@@ -148,15 +148,24 @@ static void about_create(void)
 #if HAVE_SYS_UTSNAME_H
        uname(&utsbuf);
        g_snprintf(buf, sizeof(buf),
-                  _("GTK+ version %d.%d.%d\n"
+                  _("GTK+ %d.%d.%d / GLib %d.%d.%d\n"
                   "Operating System: %s %s (%s)"),
                   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 defined(G_OS_WIN32)
+       g_snprintf(buf, sizeof(buf),
+                  _("GTK+ %d.%d.%d / GLib %d.%d.%d\n"
+                  "Operating System: %s"),
+                  gtk_major_version, gtk_minor_version, gtk_micro_version,
+                  glib_major_version, glib_minor_version, glib_micro_version,
+                  "Win32");
 #else
        g_snprintf(buf, sizeof(buf),
-                  "GTK+ version %d.%d.%d\n"
-                  "Operating System: Windoze",
-                  gtk_major_version, gtk_minor_version, gtk_micro_version);
+                  _("GTK+ %d.%d.%d / GLib %d.%d.%d\n"
+                  "Operating System: unknown"),
+                  gtk_major_version, gtk_minor_version, gtk_micro_version,
+                  glib_major_version, glib_minor_version, glib_micro_version);
 #endif
 
        label = gtk_label_new(buf);
index 2c89c45..a4af31f 100644 (file)
@@ -145,7 +145,7 @@ static void image_viewer_load_image(ImageViewer *imageviewer)
                return;
        }
        image_viewer_load_file(imageviewer, imgfile);
-       unlink(imgfile);
+       g_unlink(imgfile);
        g_free(imgfile);
 }
 
index 4b16497..ebbb159 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
 #include <stdio.h>
 #include <unistd.h>
 #include <string.h>
-#include <time.h>
-#include <sys/time.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"
@@ -400,8 +393,8 @@ static IncProgressDialog *inc_progress_dialog_create(gboolean autocheck)
        }
 
        dialog->dialog = progress;
-       gettimeofday(&dialog->progress_tv, NULL);
-       gettimeofday(&dialog->folder_tv, NULL);
+       g_get_current_time(&dialog->progress_tv);
+       g_get_current_time(&dialog->folder_tv);
        dialog->queue_list = NULL;
        dialog->cur_row = 0;
 
@@ -964,17 +957,17 @@ static void inc_progress_dialog_set_progress(IncProgressDialog *inc_dialog,
 static void inc_progress_dialog_update_periodic(IncProgressDialog *inc_dialog,
                                                IncSession *inc_session)
 {
-       struct timeval tv_cur;
-       struct timeval tv_result;
+       GTimeVal tv_cur;
+       GTimeVal tv_result;
        gint msec;
 
-       gettimeofday(&tv_cur, NULL);
+       g_get_current_time(&tv_cur);
 
        tv_result.tv_sec = tv_cur.tv_sec - inc_dialog->progress_tv.tv_sec;
        tv_result.tv_usec = tv_cur.tv_usec - inc_dialog->progress_tv.tv_usec;
        if (tv_result.tv_usec < 0) {
                tv_result.tv_sec--;
-               tv_result.tv_usec += 1000000;
+               tv_result.tv_usec += G_USEC_PER_SEC;
        }
 
        msec = tv_result.tv_sec * 1000 + tv_result.tv_usec / 1000;
@@ -1080,7 +1073,7 @@ static gint inc_drop_message(Pop3Session *session, const gchar *file)
        } else
                inbox = folder_get_default_inbox();
        if (!inbox) {
-               unlink(file);
+               g_unlink(file);
                return -1;
        }
 
@@ -1090,7 +1083,7 @@ static gint inc_drop_message(Pop3Session *session, const gchar *file)
        /* add msg file to drop folder */
        if ((msgnum = folder_item_add_msg(
                        dropfolder, file, NULL, TRUE)) < 0) {
-               unlink(file);
+               g_unlink(file);
                return -1;
        }
 
@@ -1326,7 +1319,7 @@ static gint get_spool(FolderItem *dest, const gchar *mbox)
 
        msgs = proc_mbox(dest, tmp_mbox, TRUE);
 
-       unlink(tmp_mbox);
+       g_unlink(tmp_mbox);
        if (msgs >= 0) empty_mbox(mbox);
        unlock_mbox(mbox, lockfd, LOCK_FLOCK);
 
index 507b815..c908926 100644 (file)
--- a/src/inc.h
+++ b/src/inc.h
@@ -25,8 +25,6 @@
 #endif
 
 #include <glib.h>
-#include <time.h>
-#include <sys/time.h>
 
 #include "mainwindow.h"
 #include "progressdialog.h"
@@ -60,8 +58,8 @@ struct _IncProgressDialog
 
        gboolean show_dialog;
 
-       struct timeval progress_tv;
-       struct timeval folder_tv;
+       GTimeVal progress_tv;
+       GTimeVal folder_tv;
 
        GList *queue_list;      /* list of IncSession */
        gint cur_row;
index b40a9ae..a8e9af9 100644 (file)
@@ -638,7 +638,7 @@ static gint jpilot_get_file_info( JPilotFile *pilotFile, unsigned char **buf, in
        *buf_size=0;
 
        if( pilotFile->path ) {
-               in = fopen( pilotFile->path, "rb" );
+               in = g_fopen( pilotFile->path, "rb" );
                if( !in ) {
                        return MGU_OPEN_FILE;
                }
@@ -833,8 +833,8 @@ static gint jpilot_read_db_files( JPilotFile *pilotFile, GList **records ) {
                return MGU_BAD_ARGS;
        }
 
-       in = fopen( pilotFile->path, "rb" );
-       if( ! in ) {
+       in = g_fopen( pilotFile->path, "rb" );
+       if (!in) {
                return MGU_OPEN_FILE;
        }
 
@@ -963,7 +963,7 @@ static gint jpilot_read_db_files( JPilotFile *pilotFile, GList **records ) {
        /* Read the PC3 file, if present */
        pcFile = jpilot_get_pc3_file( pilotFile );
        if( pcFile == NULL ) return MGU_SUCCESS;
-       pc_in = fopen( pcFile, "rb" );
+       pc_in = g_fopen( pcFile, "rb");
        g_free( pcFile );
 
        if( pc_in == NULL ) {
@@ -1781,7 +1781,7 @@ gchar *jpilot_find_pilotdb( void ) {
        strcat( str, JPILOT_DBHOME_FILE );
 
        /* Attempt to open */
-       if( ( fp = fopen( str, "rb" ) ) != NULL ) {
+       if( ( fp = g_fopen( str, "rb" ) ) != NULL ) {
                fclose( fp );
        }
        else {
index 193e577..61a95fc 100644 (file)
@@ -33,6 +33,7 @@
 #include "addrcache.h"
 
 #include "base64.h"
+#include "utils.h"
 
 #define        LDIF_SEP_TAG    ':'
 #define        LDIF_LANG_TAG   ';'
@@ -267,7 +268,7 @@ void ldif_print_file( LdifFile *ldifFile, FILE *stream ) {
 static gint ldif_open_file( LdifFile* ldifFile ) {
        /* printf( "Opening file\n" ); */
        if( ldifFile->path ) {
-               ldifFile->file = fopen( ldifFile->path, "rb" );
+               ldifFile->file = g_fopen( ldifFile->path, "rb" );
                if( ! ldifFile->file ) {
                        /* printf( "can't open %s\n", ldifFile->path ); */
                        ldifFile->retVal = MGU_OPEN_FILE;
index 904de9e..f7794e8 100644 (file)
@@ -36,7 +36,9 @@
 #include <time.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <signal.h>
+#ifdef G_OS_UNIX
+#  include <signal.h>
+#endif
 #include "wizard.h"
 #ifdef HAVE_STARTUP_NOTIFICATION
 # define SN_API_NOT_YET_FROZEN
@@ -254,8 +256,10 @@ int main(int argc, char *argv[])
        crash_install_handlers();
 #endif
        install_basic_sighandlers();
+       sock_init();
 
-       /* check and create unix domain socket */
+       /* check and create unix domain socket for remote operation */
+#ifdef G_OS_UNIX
        lock_socket = prohibit_duplicate_launch();
        if (lock_socket < 0) {
 #ifdef HAVE_STARTUP_NOTIFICATION
@@ -270,7 +274,7 @@ int main(int argc, char *argv[])
                lock_socket_remove();
                return 0;
        }
-
+#endif
        g_thread_init(NULL);
        /* gdk_threads_init(); */
 
@@ -318,12 +322,13 @@ int main(int argc, char *argv[])
        remove_all_files(get_tmp_dir());
        remove_all_files(get_mime_tmp_dir());
 
-       if (is_file_exist(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log")) {
-               if (rename(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log",
-                          RC_DIR G_DIR_SEPARATOR_S "sylpheed.log.bak") < 0)
+       if (is_file_exist("sylpheed.log")) {
+               if (rename_force("sylpheed.log", "sylpheed.log.bak") < 0)
                        FILE_OP_ERROR("sylpheed.log", "rename");
        }
-       set_log_file(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log");
+       set_log_file("sylpheed.log");
+
+       CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
 
        folder_system_init();
        prefs_common_read_config();
@@ -371,10 +376,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
 
        prefs_account_init();
        account_read_config_all();
@@ -421,8 +428,9 @@ int main(int argc, char *argv[])
        inc_autocheck_timer_init(mainwin);
 
        /* ignore SIGPIPE signal for preventing sudden death of program */
+#ifdef G_OS_UNIX
        signal(SIGPIPE, SIG_IGN);
-
+#endif
        if (cmd.online_mode == ONLINE_MODE_OFFLINE)
                main_window_toggle_work_offline(mainwin, TRUE);
        if (cmd.online_mode == ONLINE_MODE_ONLINE)
@@ -528,7 +536,7 @@ static void exit_sylpheed(MainWindow *mainwin)
 #endif
        /* delete crashfile */
        if (!cmd.crash)
-               unlink(get_crashfile_name());
+               g_unlink(get_crashfile_name());
 
        lock_socket_remove();
 
@@ -775,6 +783,9 @@ void app_will_exit(GtkWidget *widget, gpointer data)
                        return;
                manage_window_focus_in(mainwin->window, NULL, NULL);
        }
+
+       sock_cleanup();
+
        gtk_main_quit();
 }
 
@@ -792,7 +803,11 @@ 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;
@@ -818,7 +833,7 @@ static gint prohibit_duplicate_launch(void)
        path = get_socket_name();
        uxsock = fd_connect_unix(path);
        if (uxsock < 0) {
-               unlink(path);
+               g_unlink(path);
                return fd_open_unix(path);
        }
 
@@ -899,6 +914,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;
@@ -907,7 +923,8 @@ static gint lock_socket_remove(void)
                gdk_input_remove(lock_socket_tag);
        fd_close(lock_socket);
        filename = get_socket_name();
-       unlink(filename);
+       g_unlink(filename);
+#endif
 
        return 0;
 }
index 08e5f1c..5cb0620 100644 (file)
@@ -849,7 +849,7 @@ gboolean matcherlist_match_file(MatcherList *matchers, MsgInfo *info,
        if (file == NULL)
                return FALSE;
 
-       if ((fp = fopen(file, "rb")) == NULL) {
+       if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                g_free(file);
                return result;
@@ -1514,7 +1514,7 @@ void prefs_matcher_read_config(void)
        prefs_filtering_clear();
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MATCHER_RC, NULL);
-       f = fopen(rcpath, "rb");
+       f = g_fopen(rcpath, "rb");
        g_free(rcpath);
 
        if (f != NULL) {
@@ -1527,7 +1527,7 @@ void prefs_matcher_read_config(void)
                /* printf("reading filtering\n"); */
                rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                     FILTERING_RC, NULL);
-               f = fopen(rcpath, "rb");
+               f = g_fopen(rcpath, "rb");
                g_free(rcpath);
                
                if (f != NULL) {
@@ -1538,7 +1538,7 @@ void prefs_matcher_read_config(void)
                /* printf("reading scoring\n"); */
                rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                     SCORING_RC, NULL);
-               f = fopen(rcpath, "rb");
+               f = g_fopen(rcpath, "rb");
                g_free(rcpath);
                
                if (f != NULL) {
index 1c9ef54..df41c0a 100644 (file)
@@ -50,7 +50,7 @@
                g_warning("can't write to temporary file\n"); \
                fclose(tmp_fp); \
                fclose(mbox_fp); \
-               unlink(tmp_file); \
+               g_unlink(tmp_file); \
                g_free(tmp_file); \
                return -1; \
        } \
@@ -69,7 +69,7 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, gboolean apply_filter)
 
        debug_print("Getting messages from %s into %s...\n", mbox, dest->path);
 
-       if ((mbox_fp = fopen(mbox, "rb")) == NULL) {
+       if ((mbox_fp = g_fopen(mbox, "rb")) == NULL) {
                FILE_OP_ERROR(mbox, "fopen");
                return -1;
        }
@@ -107,7 +107,7 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, gboolean apply_filter)
                gboolean is_next_msg = FALSE;
                gint msgnum;
 
-               if ((tmp_fp = fopen(tmp_file, "wb")) == NULL) {
+               if ((tmp_fp = g_fopen(tmp_file, "wb")) == NULL) {
                        FILE_OP_ERROR(tmp_file, "fopen");
                        g_warning("can't open temporary file\n");
                        fclose(mbox_fp);
@@ -199,7 +199,7 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, gboolean apply_filter)
                        FILE_OP_ERROR(tmp_file, "fclose");
                        g_warning("can't write to temporary file\n");
                        fclose(mbox_fp);
-                       unlink(tmp_file);
+                       g_unlink(tmp_file);
                        g_free(tmp_file);
                        return -1;
                }
@@ -208,7 +208,7 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, gboolean apply_filter)
                        
                if ((msgnum = folder_item_add_msg(dropfolder, tmp_file, NULL, TRUE)) < 0) {
                        fclose(mbox_fp);
-                       unlink(tmp_file);
+                       g_unlink(tmp_file);
                        g_free(tmp_file);
                        return -1;
                }
@@ -232,6 +232,7 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, gboolean apply_filter)
 
 gint lock_mbox(const gchar *base, LockType type)
 {
+#ifdef G_OS_UNIX
        gint retval = 0;
 
        if (type == LOCK_FILE) {
@@ -240,7 +241,7 @@ gint lock_mbox(const gchar *base, LockType type)
                FILE *lockfp;
 
                lockfile = g_strdup_printf("%s.%d", base, getpid());
-               if ((lockfp = fopen(lockfile, "wb")) == NULL) {
+               if ((lockfp = g_fopen(lockfile, "wb")) == NULL) {
                        FILE_OP_ERROR(lockfile, "fopen");
                        g_warning("can't create lock file %s\n", lockfile);
                        g_warning("use 'flock' instead of 'file' if possible.\n");
@@ -256,7 +257,7 @@ gint lock_mbox(const gchar *base, LockType type)
                        FILE_OP_ERROR(lockfile, "link");
                        if (retry >= 5) {
                                g_warning("can't create %s\n", lockfile);
-                               unlink(lockfile);
+                               g_unlink(lockfile);
                                g_free(lockfile);
                                return -1;
                        }
@@ -266,7 +267,7 @@ gint lock_mbox(const gchar *base, LockType type)
                        retry++;
                        sleep(5);
                }
-               unlink(lockfile);
+               g_unlink(lockfile);
                g_free(lockfile);
        } else if (type == LOCK_FLOCK) {
                gint lockfd;
@@ -302,6 +303,9 @@ gint lock_mbox(const gchar *base, LockType type)
        }
 
        return retval;
+#else
+       return -1;
+#endif /* G_OS_UNIX */
 }
 
 gint unlock_mbox(const gchar *base, gint fd, LockType type)
@@ -310,7 +314,7 @@ gint unlock_mbox(const gchar *base, gint fd, LockType type)
                gchar *lockfile;
 
                lockfile = g_strconcat(base, ".lock", NULL);
-               if (unlink(lockfile) < 0) {
+               if (g_unlink(lockfile) < 0) {
                        FILE_OP_ERROR(lockfile, "unlink");
                        g_free(lockfile);
                        return -1;
@@ -357,7 +361,7 @@ void empty_mbox(const gchar *mbox)
 {
        FILE *fp;
 
-       if ((fp = fopen(mbox, "wb")) == NULL) {
+       if ((fp = g_fopen(mbox, "wb")) == NULL) {
                FILE_OP_ERROR(mbox, "fopen");
                g_warning("can't truncate mailbox to zero.\n");
                return;
@@ -373,7 +377,7 @@ gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
        FILE *mbox_fp;
        gchar buf[BUFFSIZE];
 
-       if ((mbox_fp = fopen(mbox, "wb")) == NULL) {
+       if ((mbox_fp = g_fopen(mbox, "wb")) == NULL) {
                FILE_OP_ERROR(mbox, "fopen");
                return -1;
        }
index 882a830..7511d7c 100644 (file)
@@ -599,7 +599,7 @@ static gint disposition_notification_send(MsgInfo *msginfo)
        g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
                   get_rc_dir(), G_DIR_SEPARATOR, (gint)msginfo);
 
-       if ((fp = fopen(tmp, "wb")) == NULL) {
+       if ((fp = g_fopen(tmp, "wb")) == NULL) {
                FILE_OP_ERROR(tmp, "fopen");
                return -1;
        }
@@ -674,7 +674,7 @@ static gint disposition_notification_send(MsgInfo *msginfo)
 
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(tmp, "fclose");
-               unlink(tmp);
+               g_unlink(tmp);
                return -1;
        }
 
@@ -683,13 +683,13 @@ static gint disposition_notification_send(MsgInfo *msginfo)
        if (!queue) queue = folder_get_default_queue();
        if (!queue) {
                g_warning("can't find queue folder\n");
-               unlink(tmp);
+               g_unlink(tmp);
                return -1;
        }
        folder_item_scan(queue);
        if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
                g_warning("can't queue the message\n");
-               unlink(tmp);
+               g_unlink(tmp);
                return -1;
        }
                
index d74b242..0010a41 100644 (file)
--- a/src/mh.c
+++ b/src/mh.c
@@ -385,14 +385,19 @@ static gint mh_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
                destfile = mh_get_new_msg_filename(dest);
                if (destfile == NULL) return -1;
 
+#ifdef G_OS_UNIX
                if (link(fileinfo->file, destfile) < 0) {
+#endif
                        if (copy_file(fileinfo->file, destfile, TRUE) < 0) {
                                g_warning(_("can't copy message %s to %s\n"),
                                          fileinfo->file, destfile);
                                g_free(destfile);
                                return -1;
                        }
+#ifdef G_OS_UNIX
                }
+#endif
+
                if (relation != NULL)
                        g_relation_insert(relation, fileinfo, GINT_TO_POINTER(dest->last_num + 1));
                g_free(destfile);
@@ -492,7 +497,7 @@ static gint mh_remove_msg(Folder *folder, FolderItem *item, gint num)
 
        need_scan = mh_scan_required(folder, item);
 
-       if (unlink(file) < 0) {
+       if (g_unlink(file) < 0) {
                FILE_OP_ERROR(file, "unlink");
                g_free(file);
                return -1;
@@ -525,7 +530,7 @@ static gboolean mh_is_msg_changed(Folder *folder, FolderItem *item,
 {
        struct stat s;
 
-       if (stat(itos(msginfo->msgnum), &s) < 0 ||
+       if (g_stat(itos(msginfo->msgnum), &s) < 0 ||
            msginfo->size  != s.st_size || (
                (msginfo->mtime - s.st_mtime != 0) &&
                (msginfo->mtime - s.st_mtime != 3600) &&
@@ -582,7 +587,7 @@ static gint mh_create_tree(Folder *folder)
 
        g_return_val_if_fail(folder != NULL, -1);
 
-       CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), -1);
+       CHDIR_RETURN_VAL_IF_FAIL(get_mail_base_dir(), -1);
        rootpath = LOCAL_FOLDER(folder)->rootpath;
        MAKE_DIR_IF_NOT_EXIST(rootpath);
        CHDIR_RETURN_VAL_IF_FAIL(rootpath, -1);
@@ -678,7 +683,7 @@ static FolderItem *mh_create_folder(Folder *folder, FolderItem *parent,
        path = folder_item_get_path(new_item);
        mh_sequences_filename = g_strconcat(path, G_DIR_SEPARATOR_S,
                                            ".mh_sequences", NULL);
-       if ((mh_sequences_file = fopen(mh_sequences_filename, "a+b")) != NULL) {
+       if ((mh_sequences_file = g_fopen(mh_sequences_filename, "a+b")) != NULL) {
                fclose(mh_sequences_file);
        }
        g_free(mh_sequences_filename);
@@ -710,7 +715,7 @@ static gint mh_rename_folder(Folder *folder, FolderItem *item,
        newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S, real_name, NULL);
        g_free(real_name);
 
-       if (rename(oldpath, newpath) < 0) {
+       if (g_rename(oldpath, newpath) < 0) {
                FILE_OP_ERROR(oldpath, "rename");
                g_free(oldpath);
                g_free(newpath);
@@ -848,8 +853,13 @@ static void mh_remove_missing_folder_items(Folder *folder)
 static void mh_scan_tree_recursive(FolderItem *item)
 {
        Folder *folder;
+#ifdef G_OS_WIN32
+       GDir *dir;
+#else
        DIR *dp;
        struct dirent *d;
+#endif
+       const gchar *dir_name;
        struct stat s;
        gchar *real_path, *entry, *utf8entry, *utf8name;
        gint n_msg = 0;
@@ -860,11 +870,20 @@ static void mh_scan_tree_recursive(FolderItem *item)
        folder = item->folder;
 
        real_path = item->path ? mh_filename_from_utf8(item->path) : g_strdup(".");
+#ifdef G_OS_WIN32
+       dir = g_dir_open(real_path, 0, NULL);
+       if (!dir) {
+               g_warning("failed to open directory: %s\n", real_path);
+               g_free(real_path);
+               return;
+       }
+#else
        dp = opendir(real_path);
        if (!dp) {
                FILE_OP_ERROR(real_path, "opendir");
                return;
        }
+#endif
        g_free(real_path);
 
        debug_print("scanning %s ...\n",
@@ -873,10 +892,15 @@ static void mh_scan_tree_recursive(FolderItem *item)
        if (folder->ui_func)
                folder->ui_func(folder, item, folder->ui_func_data);
 
+#ifdef G_OS_WIN32
+       while ((dir_name = g_dir_read_name(dir)) != NULL) {
+#else
        while ((d = readdir(dp)) != NULL) {
-               if (d->d_name[0] == '.') continue;
+               dir_name = d->d_name;
+#endif
+               if (dir_name[0] == '.') continue;
 
-               utf8name = mh_filename_to_utf8(d->d_name);
+               utf8name = mh_filename_to_utf8(dir_name);
                if (item->path)
                        utf8entry = g_strconcat(item->path, G_DIR_SEPARATOR_S,
                                                utf8name, NULL);
@@ -885,12 +909,12 @@ static void mh_scan_tree_recursive(FolderItem *item)
                entry = mh_filename_from_utf8(utf8entry);
 
                if (
-#ifdef HAVE_DIRENT_D_TYPE
+#if !defined(G_OS_WIN32) && defined(HAVE_DIRENT_D_TYPE)
                        d->d_type == DT_DIR ||
                        (d->d_type == DT_UNKNOWN &&
 #endif
-                       stat(entry, &s) == 0 && S_ISDIR(s.st_mode)
-#ifdef HAVE_DIRENT_D_TYPE
+                       g_stat(entry, &s) == 0 && S_ISDIR(s.st_mode)
+#if !defined(G_OS_WIN32) && defined(HAVE_DIRENT_D_TYPE)
                        )
 #endif
                   ) {
@@ -922,37 +946,41 @@ static void mh_scan_tree_recursive(FolderItem *item)
 
                        if (!item->path) {
                                if (!folder->inbox &&
-                                   !strcmp(d->d_name, INBOX_DIR)) {
+                                   !strcmp(dir_name, INBOX_DIR)) {
                                        new_item->stype = F_INBOX;
                                        folder->inbox = new_item;
                                } else if (!folder->outbox &&
-                                          !strcmp(d->d_name, OUTBOX_DIR)) {
+                                          !strcmp(dir_name, OUTBOX_DIR)) {
                                        new_item->stype = F_OUTBOX;
                                        folder->outbox = new_item;
                                } else if (!folder->draft &&
-                                          !strcmp(d->d_name, DRAFT_DIR)) {
+                                          !strcmp(dir_name, DRAFT_DIR)) {
                                        new_item->stype = F_DRAFT;
                                        folder->draft = new_item;
                                } else if (!folder->queue &&
-                                          !strcmp(d->d_name, QUEUE_DIR)) {
+                                          !strcmp(dir_name, QUEUE_DIR)) {
                                        new_item->stype = F_QUEUE;
                                        folder->queue = new_item;
                                } else if (!folder->trash &&
-                                          !strcmp(d->d_name, TRASH_DIR)) {
+                                          !strcmp(dir_name, TRASH_DIR)) {
                                        new_item->stype = F_TRASH;
                                        folder->trash = new_item;
                                }
                        }
 
                        mh_scan_tree_recursive(new_item);
-               } else if (to_number(d->d_name) != -1) n_msg++;
+               } else if (to_number(dir_name) > 0) n_msg++;
 
                g_free(entry);
                g_free(utf8entry);
                g_free(utf8name);
        }
 
+#ifdef G_OS_WIN32
+       g_dir_close(dir);
+#else
        closedir(dp);
+#endif
 
        item->mtime = time(NULL);
 
index b2b10d2..dd0d8f4 100644 (file)
@@ -459,7 +459,7 @@ static void mimeview_show_message_part(MimeView *mimeview, MimeInfo *partinfo)
        fname = mimeview->file;
        if (!fname) return;
 
-       if ((fp = fopen(fname, "rb")) == NULL) {
+       if ((fp = g_fopen(fname, "rb")) == NULL) {
                FILE_OP_ERROR(fname, "fopen");
                return;
        }
index f0d8a79..dbb589f 100644 (file)
@@ -291,7 +291,7 @@ static FILE *msgcache_open_data_file(const gchar *file, guint version,
        g_return_val_if_fail(file != NULL, NULL);
 
        if (mode == DATA_WRITE) {
-               if ((fp = fopen(file, "wb")) == NULL) {
+               if ((fp = g_fopen(file, "wb")) == NULL) {
                        FILE_OP_ERROR(file, "fopen");
                        return NULL;
                }
@@ -303,7 +303,7 @@ static FILE *msgcache_open_data_file(const gchar *file, guint version,
        }
 
        /* check version */
-       if ((fp = fopen(file, "rb")) == NULL)
+       if ((fp = g_fopen(file, "rb")) == NULL)
                debug_print("Mark/Cache file '%s' not found\n", file);
        else {
                if (buf && buf_size > 0)
@@ -324,7 +324,7 @@ static FILE *msgcache_open_data_file(const gchar *file, guint version,
        if (fp) {
                /* reopen with append mode */
                fclose(fp);
-               if ((fp = fopen(file, "ab")) == NULL)
+               if ((fp = g_fopen(file, "ab")) == NULL)
                        FILE_OP_ERROR(file, "fopen");
        } else {
                /* open with overwrite mode if mark file doesn't exist or
index cac872d..acc9963 100644 (file)
@@ -123,7 +123,7 @@ void mutt_print_file( MuttFile *muttFile, FILE *stream ) {
 */
 static gint mutt_open_file( MuttFile* muttFile ) {
        if( muttFile->path ) {
-               muttFile->file = fopen( muttFile->path, "rb" );
+               muttFile->file = g_fopen( muttFile->path, "rb" );
                if( ! muttFile->file ) {
                        muttFile->retVal = MGU_OPEN_FILE;
                        return muttFile->retVal;
@@ -578,7 +578,7 @@ gchar *mutt_find_file( void ) {
        strcat( str, MUTT_HOME_FILE );
 
        /* Attempt to open */
-       if( ( fp = fopen( str, "rb" ) ) != NULL ) {
+       if( ( fp = g_fopen( str, "rb" ) ) != NULL ) {
                fclose( fp );
        }
        else {
index 28e08fb..21e53d4 100644 (file)
@@ -386,7 +386,7 @@ GSList *news_get_group_list(Folder *folder)
        filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
        g_free(path);
 
-       if ((fp = fopen(filename, "rb")) == NULL) {
+       if ((fp = g_fopen(filename, "rb")) == NULL) {
                NNTPSession *session;
                gint ok;
 
@@ -413,7 +413,7 @@ GSList *news_get_group_list(Folder *folder)
                        return NULL;
                }
 
-               if ((fp = fopen(filename, "rb")) == NULL) {
+               if ((fp = g_fopen(filename, "rb")) == NULL) {
                        FILE_OP_ERROR(filename, "fopen");
                        g_free(filename);
                        return NULL;
@@ -493,7 +493,7 @@ gint news_post(Folder *folder, const gchar *file)
        g_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, -1);
        g_return_val_if_fail(file != NULL, -1);
 
-       if ((fp = fopen(file, "rb")) == NULL) {
+       if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return -1;
        }
@@ -733,7 +733,7 @@ gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
        if (tmp == NULL)
                return -1;
 
-       if ((tmpfp = fopen(tmp, "wb")) == NULL) {
+       if ((tmpfp = g_fopen(tmp, "wb")) == NULL) {
                FILE_OP_ERROR(tmp, "fopen");
                return -1;
        }
index 94e55b4..be206d6 100644 (file)
@@ -84,13 +84,13 @@ int partial_msg_in_uidl_list(MsgInfo *msginfo)
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                           "uidl", G_DIR_SEPARATOR_S, msginfo->account_server,
                           "-", msginfo->account_login, NULL);
-       if ((fp = fopen(path, "rb")) == NULL) {
+       if ((fp = g_fopen(path, "rb")) == NULL) {
                if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                g_free(path);
                path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                   "uidl-", msginfo->account_server,
                                   "-", sanitized_uid, NULL);
-               if ((fp = fopen(path, "rb")) == NULL) {
+               if ((fp = g_fopen(path, "rb")) == NULL) {
                        if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                        g_free(sanitized_uid);
                        g_free(path);
@@ -162,14 +162,14 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
                           "uidl", G_DIR_SEPARATOR_S, tinfo->account_server,
                           "-", sanitized_uid, NULL);
 
-       if ((fp = fopen(path, "rb")) == NULL) {
+       if ((fp = g_fopen(path, "rb")) == NULL) {
                perror("fopen1");
                if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                g_free(path);
                path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                   "uidl-", tinfo->account_server,
                                   "-", tinfo->account_login, NULL);
-               if ((fp = fopen(path, "rb")) == NULL) {
+               if ((fp = g_fopen(path, "rb")) == NULL) {
                        if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                        g_free(path);
                }
@@ -182,7 +182,7 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
        
        g_free(sanitized_uid);
 
-       if ((fpnew = fopen(pathnew, "wb")) == NULL) {
+       if ((fpnew = g_fopen(pathnew, "wb")) == NULL) {
                perror("fopen2");
                fclose(fp);
                g_free(pathnew);
@@ -234,12 +234,12 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
        g_free(path);
        g_free(pathnew);
        
-       if ((fp = fopen(filename,"rb")) == NULL) {
+       if ((fp = g_fopen(filename,"rb")) == NULL) {
                perror("fopen3");
                goto bail;
        }
        pathnew = g_strdup_printf("%s.new", filename);
-       if ((fpnew = fopen(pathnew, "wb")) == NULL) {
+       if ((fpnew = g_fopen(pathnew, "wb")) == NULL) {
                perror("fopen4");
                fclose(fp);
                g_free(pathnew);
@@ -265,7 +265,7 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
        }
        fclose(fpnew);
        fclose(fp);
-       unlink(filename);
+       g_unlink(filename);
        rename(pathnew, filename);
        g_free(pathnew);
        msginfo->planned_download = download;
@@ -341,13 +341,13 @@ gchar *partial_get_filename(const gchar *server, const gchar *login,
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                           "uidl", G_DIR_SEPARATOR_S, 
                           server, "-", sanitized_uid, NULL);
-       if ((fp = fopen(path, "rb")) == NULL) {
+       if ((fp = g_fopen(path, "rb")) == NULL) {
                if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                g_free(path);
                path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                   "uidl-", server,
                                   "-", sanitized_uid, NULL);
-               if ((fp = fopen(path, "rb")) == NULL) {
+               if ((fp = g_fopen(path, "rb")) == NULL) {
                        if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                        g_free(sanitized_uid);
                        g_free(path);
index 67003b8..01ab960 100644 (file)
@@ -129,7 +129,7 @@ void pine_print_file( PineFile *pineFile, FILE *stream ) {
  */
 static gint pine_open_file( PineFile* pineFile ) {
        if( pineFile->path ) {
-               pineFile->file = fopen( pineFile->path, "rb" );
+               pineFile->file = g_fopen( pineFile->path, "rb" );
                if( ! pineFile->file ) {
                        pineFile->retVal = MGU_OPEN_FILE;
                        return pineFile->retVal;
@@ -677,7 +677,7 @@ gchar *pine_find_file( void ) {
        strcat( str, PINE_HOME_FILE );
 
        /* Attempt to open */
-       if( ( fp = fopen( str, "rb" ) ) != NULL ) {
+       if( ( fp = g_fopen( str, "rb" ) ) != NULL ) {
                fclose( fp );
        }
        else {
index d0b9629..0b71afd 100644 (file)
--- a/src/pop.c
+++ b/src/pop.c
@@ -575,13 +575,13 @@ void pop3_get_uidl_table(PrefsAccount *ac_prefs, Pop3Session *session)
                           "-", sanitized_uid, NULL);
                           
        g_free(sanitized_uid);
-       if ((fp = fopen(path, "rb")) == NULL) {
+       if ((fp = g_fopen(path, "rb")) == NULL) {
                if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                g_free(path);
                path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                   "uidl-", ac_prefs->recv_server,
                                   "-", ac_prefs->userid, NULL);
-               if ((fp = fopen(path, "rb")) == NULL) {
+               if ((fp = g_fopen(path, "rb")) == NULL) {
                        if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                        g_free(path);
                        session->uidl_table = table;
@@ -652,7 +652,7 @@ gint pop3_write_uidl_list(Pop3Session *session)
        
        g_free(sanitized_uid);
 
-       if ((fp = fopen(path, "wb")) == NULL) {
+       if ((fp = g_fopen(path, "wb")) == NULL) {
                FILE_OP_ERROR(path, "fopen");
                g_free(path);
                return -1;
@@ -680,7 +680,7 @@ static gint pop3_write_msg_to_file(const gchar *file, const gchar *data,
 
        g_return_val_if_fail(file != NULL, -1);
 
-       if ((fp = fopen(file, "wb")) == NULL) {
+       if ((fp = g_fopen(file, "wb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return -1;
        }
@@ -704,7 +704,7 @@ static gint pop3_write_msg_to_file(const gchar *file, const gchar *data,
                        FILE_OP_ERROR(file, "fwrite");
                        g_warning("can't write to file: %s\n", file);
                        fclose(fp);
-                       unlink(file);
+                       g_unlink(file);
                        return -1;
                }
 
@@ -730,7 +730,7 @@ static gint pop3_write_msg_to_file(const gchar *file, const gchar *data,
                FILE_OP_ERROR(file, "fwrite");
                g_warning("can't write to file: %s\n", file);
                fclose(fp);
-               unlink(file);
+               g_unlink(file);
                return -1;
        }
        if (data[len - 1] != '\r' && data[len - 1] != '\n') {
@@ -738,14 +738,14 @@ static gint pop3_write_msg_to_file(const gchar *file, const gchar *data,
                        FILE_OP_ERROR(file, "fputc");
                        g_warning("can't write to file: %s\n", file);
                        fclose(fp);
-                       unlink(file);
+                       g_unlink(file);
                        return -1;
                }
        }
 
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(file, "fclose");
-               unlink(file);
+               g_unlink(file);
                return -1;
        }
 
index 441927f..a246a13 100644 (file)
@@ -318,7 +318,7 @@ void prefs_actions_read_config(void)
        debug_print("Reading actions configurations...\n");
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACTIONS_RC, NULL);
-       if ((fp = fopen(rcpath, "rb")) == NULL) {
+       if ((fp = g_fopen(rcpath, "rb")) == NULL) {
                if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
                g_free(rcpath);
                return;
index aa76122..44c2d86 100644 (file)
@@ -589,7 +589,7 @@ GList *prefs_common_read_history(const gchar *history)
 
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, history,
                           NULL);
-       if ((fp = fopen(path, "rb")) == NULL) {
+       if ((fp = g_fopen(path, "rb")) == NULL) {
                if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                g_free(path);
                return NULL;
@@ -632,7 +632,7 @@ void prefs_common_save_history(const gchar *history, GList *list)
 
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, history,
                           NULL);
-       if ((fp = fopen(path, "wb")) == NULL) {
+       if ((fp = g_fopen(path, "wb")) == NULL) {
                FILE_OP_ERROR(path, "fopen");
                g_free(path);
                return;
index 3067dae..dc4d713 100644 (file)
@@ -315,7 +315,7 @@ void prefs_custom_header_read_config(PrefsAccount *ac)
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                             CUSTOM_HEADER_RC, NULL);
-       if ((fp = fopen(rcpath, "rb")) == NULL) {
+       if ((fp = g_fopen(rcpath, "rb")) == NULL) {
                if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
                g_free(rcpath);
                ac->customhdr_list = NULL;
@@ -360,7 +360,7 @@ void prefs_custom_header_write_config(PrefsAccount *ac)
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                             CUSTOM_HEADER_RC, NULL);
 
-       if ((fp = fopen(rcpath, "rb")) == NULL) {
+       if ((fp = g_fopen(rcpath, "rb")) == NULL) {
                if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
        } else {
                all_hdrs = NULL;
index a1305c0..e2a94a8 100644 (file)
@@ -398,7 +398,7 @@ void prefs_display_header_read_config(void)
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                             DISPLAY_HEADER_RC, NULL);
-       if ((fp = fopen(rcpath, "rb")) == NULL) {
+       if ((fp = g_fopen(rcpath, "rb")) == NULL) {
                if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
                g_free(rcpath);
                prefs_common.disphdr_list = NULL;
index 78ba0ce..05d1dde 100644 (file)
@@ -65,7 +65,7 @@ void prefs_read_config(PrefParam *param, const gchar *label,
 
        prefs_set_default(param);
 
-       if ((fp = fopen(rcfile, "rb")) == NULL) {
+       if ((fp = g_fopen(rcfile, "rb")) == NULL) {
                if (ENOENT != errno) FILE_OP_ERROR(rcfile, "fopen");
                return;
        }
@@ -223,7 +223,7 @@ void prefs_write_config(PrefParam *param, const gchar *label,
        g_return_if_fail(rcfile != NULL);
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, rcfile, NULL);
-       if ((orig_fp = fopen(rcpath, "rb")) == NULL) {
+       if ((orig_fp = g_fopen(rcpath, "rb")) == NULL) {
                if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
        }
 
index cd25bd5..0bd4d8b 100644 (file)
@@ -188,7 +188,7 @@ static void prefs_themes_file_remove(const gchar *filename, gpointer data)
                if (!((base[0] == '.') || (base[0] == '.' && base[1] == '.')))
                        g_warning("prefs_themes_file_remove(): subdir in theme dir skipped.\n");
        }
-       else if (0 != unlink(filename)) {
+       else if (0 != g_unlink(filename)) {
                (*status) = g_strdup(filename);
        }
        g_free(base);
@@ -686,7 +686,7 @@ static void prefs_themes_get_theme_info(ThemesData *tdata)
        }
        else {
                sinfo = g_strconcat(path, G_DIR_SEPARATOR_S, THEMEINFO_FILE, NULL);
-               finfo = fopen(sinfo, "r");
+               finfo = g_fopen(sinfo, "r");
                if (finfo == NULL) {
                        info->name = g_strdup(_("No info file available for this theme"));
                        info->author = g_strdup(_("Unknown"));
index ca4f6ac..8ede75b 100644 (file)
@@ -233,7 +233,7 @@ GSList *procheader_get_header_list_from_file(const gchar *file)
        FILE *fp;
        GSList *hlist;
 
-       if ((fp = fopen(file, "rb")) == NULL) {
+       if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return NULL;
        }
@@ -472,7 +472,7 @@ MsgInfo *procheader_parse_file(const gchar *file, MsgFlags flags,
        if (!S_ISREG(s.st_mode))
                return NULL;
 
-       if ((fp = fopen(file, "rb")) == NULL) {
+       if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return NULL;
        }
@@ -995,7 +995,7 @@ gint procheader_get_header_from_msginfo(MsgInfo *msginfo, gchar *buf, gint len,
        
        g_return_val_if_fail(msginfo != NULL, -1);
        file = procmsg_get_message_file_path(msginfo);
-       if ((fp = fopen(file, "rb")) == NULL) {
+       if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                g_free(file);
                return -1;
@@ -1003,7 +1003,7 @@ gint procheader_get_header_from_msginfo(MsgInfo *msginfo, gchar *buf, gint len,
        val = procheader_get_one_field(buf,len, fp, hentry);
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(file, "fclose");
-               unlink(file);
+               g_unlink(file);
                g_free(file);
                return -1;
        }
index 4d10344..9a98522 100644 (file)
@@ -102,7 +102,7 @@ static gboolean free_func(GNode *node, gpointer data)
        switch (mimeinfo->content) {
        case MIMECONTENT_FILE:
                if (mimeinfo->tmp)
-                       unlink(mimeinfo->data.filename);
+                       g_unlink(mimeinfo->data.filename);
                g_free(mimeinfo->data.filename);
                break;
 
@@ -289,7 +289,7 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
            encoding == ENC_BINARY)
                return TRUE;
 
-       infp = fopen(mimeinfo->data.filename, "rb");
+       infp = g_fopen(mimeinfo->data.filename, "rb");
        if (!infp) {
                perror("fopen");
                return FALSE;
@@ -387,7 +387,7 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
 
        stat(tmpfilename, &statbuf);
        if (mimeinfo->tmp && (mimeinfo->data.filename != NULL))
-               unlink(mimeinfo->data.filename);
+               g_unlink(mimeinfo->data.filename);
        if (mimeinfo->data.filename != NULL)
                g_free(mimeinfo->data.filename);
        mimeinfo->data.filename = tmpfilename;
@@ -423,7 +423,7 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
        }
 
        if (mimeinfo->content == MIMECONTENT_FILE) {
-               if ((infp = fopen(mimeinfo->data.filename, "rb")) == NULL) {
+               if ((infp = g_fopen(mimeinfo->data.filename, "rb")) == NULL) {
                        g_warning("Can't open file %s\n", mimeinfo->data.filename);
                        return FALSE;
                }
@@ -447,9 +447,9 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
                                        fclose(infp);
                                        return FALSE;
                                }
-                               if ((tmp_fp = fopen(tmp_file, "rb")) == NULL) {
+                               if ((tmp_fp = g_fopen(tmp_file, "rb")) == NULL) {
                                        FILE_OP_ERROR(tmp_file, "fopen");
-                                       unlink(tmp_file);
+                                       g_unlink(tmp_file);
                                        g_free(tmp_file);
                                        fclose(infp);
                                        return FALSE;
@@ -480,7 +480,7 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
 
                if (tmp_file) {
                        fclose(tmp_fp);
-                       unlink(tmp_file);
+                       g_unlink(tmp_file);
                        g_free(tmp_file);
                }
        } else if (encoding == ENC_QUOTED_PRINTABLE) {
@@ -513,7 +513,7 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
 
        if (mimeinfo->content == MIMECONTENT_FILE) {
                if (mimeinfo->tmp && (mimeinfo->data.filename != NULL))
-                       unlink(mimeinfo->data.filename);
+                       g_unlink(mimeinfo->data.filename);
                g_free(mimeinfo->data.filename);
        } else if (mimeinfo->content == MIMECONTENT_MEM) {
                if (mimeinfo->tmp && (mimeinfo->data.mem != NULL))
@@ -543,7 +543,7 @@ gint procmime_get_part(const gchar *outfile, MimeInfo *mimeinfo)
        if (mimeinfo->encoding_type != ENC_BINARY && !procmime_decode_content(mimeinfo))
                return -1;
 
-       if ((infp = fopen(mimeinfo->data.filename, "rb")) == NULL) {
+       if ((infp = g_fopen(mimeinfo->data.filename, "rb")) == NULL) {
                FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
                return -1;
        }
@@ -552,7 +552,7 @@ gint procmime_get_part(const gchar *outfile, MimeInfo *mimeinfo)
                fclose(infp);
                return -1;
        }
-       if ((outfp = fopen(outfile, "wb")) == NULL) {
+       if ((outfp = g_fopen(outfile, "wb")) == NULL) {
                FILE_OP_ERROR(outfile, "fopen");
                fclose(infp);
                return -1;
@@ -568,7 +568,7 @@ gint procmime_get_part(const gchar *outfile, MimeInfo *mimeinfo)
        fclose(infp);
        if (fclose(outfp) == EOF) {
                FILE_OP_ERROR(outfile, "fclose");
-               unlink(outfile);
+               g_unlink(outfile);
                return -1;
        }
 
@@ -614,7 +614,7 @@ void renderer_read_config(void)
        renderer_list = NULL;
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, RENDERER_RC, NULL);
-       f = fopen(rcpath, "rb");
+       f = g_fopen(rcpath, "rb");
        g_free(rcpath);
        
        if (f == NULL)
@@ -694,7 +694,7 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo)
                return NULL;
        }
 
-       tmpfp = fopen(tmpfile, "rb");
+       tmpfp = g_fopen(tmpfile, "rb");
        if (tmpfp == NULL) {
                g_free(tmpfile);
                return NULL;
@@ -787,7 +787,7 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo)
 
        fclose(tmpfp);
        rewind(outfp);
-       unlink(tmpfile);
+       g_unlink(tmpfile);
        g_free(tmpfile);
 
        return outfp;
@@ -1097,10 +1097,10 @@ GList *procmime_get_mime_type_list(void)
        if (mime_type_list) 
                return mime_type_list;
        
-       if ((fp = fopen("/usr/share/mime/globs", "rb")) == NULL) {
+       if ((fp = g_fopen("/usr/share/mime/globs", "rb")) == NULL) {
                fp_is_glob_file = FALSE;
-               if ((fp = fopen("/etc/mime.types", "rb")) == NULL) {
-                       if ((fp = fopen(SYSCONFDIR "/mime.types", "rb")) 
+               if ((fp = g_fopen("/etc/mime.types", "rb")) == NULL) {
+                       if ((fp = g_fopen(SYSCONFDIR "/mime.types", "rb")) 
                                == NULL) {
                                FILE_OP_ERROR(SYSCONFDIR "/mime.types", 
                                        "fopen");
@@ -1182,7 +1182,7 @@ EncodingType procmime_get_encoding_for_text_file(const gchar *file)
        size_t total_len = 0;
        gfloat octet_percentage;
 
-       if ((fp = fopen(file, "rb")) == NULL) {
+       if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return ENC_UNKNOWN;
        }
@@ -1333,7 +1333,7 @@ void procmime_parse_message_rfc822(MimeInfo *mimeinfo)
 
        procmime_decode_content(mimeinfo);
 
-       fp = fopen(mimeinfo->data.filename, "rb");
+       fp = g_fopen(mimeinfo->data.filename, "rb");
        if (fp == NULL) {
                FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
                return;
@@ -1397,7 +1397,7 @@ void procmime_parse_multipart(MimeInfo *mimeinfo)
 
        procmime_decode_content(mimeinfo);
 
-       fp = fopen(mimeinfo->data.filename, "rb");
+       fp = g_fopen(mimeinfo->data.filename, "rb");
        if (fp == NULL) {
                FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
                return;
@@ -1829,7 +1829,7 @@ MimeInfo *procmime_scan_queue_file(const gchar *filename)
        g_return_val_if_fail(filename != NULL, NULL);
 
        /* Open file */
-       if ((fp = fopen(filename, "rb")) == NULL)
+       if ((fp = g_fopen(filename, "rb")) == NULL)
                return NULL;
        /* Skip queue header */
        while (fgets(buf, sizeof(buf), fp) != NULL)
@@ -2004,7 +2004,7 @@ gint procmime_write_message_rfc822(MimeInfo *mimeinfo, FILE *fp)
        /* write header */
        switch (mimeinfo->content) {
        case MIMECONTENT_FILE:
-               if ((infp = fopen(mimeinfo->data.filename, "rb")) == NULL) {
+               if ((infp = g_fopen(mimeinfo->data.filename, "rb")) == NULL) {
                        FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
                        return -1;
                }
@@ -2064,7 +2064,7 @@ gint procmime_write_multipart(MimeInfo *mimeinfo, FILE *fp)
 
        switch (mimeinfo->content) {
        case MIMECONTENT_FILE:
-               if ((infp = fopen(mimeinfo->data.filename, "rb")) == NULL) {
+               if ((infp = g_fopen(mimeinfo->data.filename, "rb")) == NULL) {
                        FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
                        return -1;
                }
@@ -2121,7 +2121,7 @@ gint procmime_write_mimeinfo(MimeInfo *mimeinfo, FILE *fp)
        if (G_NODE_IS_LEAF(mimeinfo->node)) {
                switch (mimeinfo->content) {
                case MIMECONTENT_FILE:
-                       if ((infp = fopen(mimeinfo->data.filename, "rb")) == NULL) {
+                       if ((infp = g_fopen(mimeinfo->data.filename, "rb")) == NULL) {
                                FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
                                return -1;
                        }
index c217904..db63e6a 100644 (file)
@@ -505,7 +505,7 @@ FILE *procmsg_open_message(MsgInfo *msginfo)
                        return NULL;
        }
 
-       if ((fp = fopen(file, "rb")) == NULL) {
+       if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                g_free(file);
                return NULL;
@@ -702,7 +702,7 @@ static PrefsAccount *procmsg_get_account_from_file(const gchar *file)
        
        g_return_val_if_fail(file != NULL, NULL);
 
-       if ((fp = fopen(file, "rb")) == NULL) {
+       if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return NULL;
        }
@@ -900,11 +900,11 @@ gint procmsg_remove_special_headers(const gchar *in, const gchar *out)
        FILE *fp, *outfp;
        gchar buf[BUFFSIZE];
        
-       if ((fp = fopen(in, "rb")) == NULL) {
+       if ((fp = g_fopen(in, "rb")) == NULL) {
                FILE_OP_ERROR(in, "fopen");
                return -1;
        }
-       if ((outfp = fopen(out, "wb")) == NULL) {
+       if ((outfp = g_fopen(out, "wb")) == NULL) {
                FILE_OP_ERROR(out, "fopen");
                fclose(fp);
                return -1;
@@ -944,7 +944,7 @@ gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file,
                folder_item_scan(outbox);
                if ((num = folder_item_add_msg(outbox, tmp, &flag, TRUE)) < 0) {
                        g_warning("can't save message\n");
-                       unlink(tmp);
+                       g_unlink(tmp);
                        return -1;
                }
        } else {
@@ -995,7 +995,7 @@ void procmsg_print_message(MsgInfo *msginfo, const gchar *cmdline)
        prtmp = g_strdup_printf("%s%cprinttmp.%08x",
                                get_mime_tmp_dir(), G_DIR_SEPARATOR, id++);
 
-       if ((prfp = fopen(prtmp, "wb")) == NULL) {
+       if ((prfp = g_fopen(prtmp, "wb")) == NULL) {
                FILE_OP_ERROR(prtmp, "fopen");
                g_free(prtmp);
                fclose(tmpfp);
@@ -1286,7 +1286,7 @@ static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_ses
 
        g_return_val_if_fail(file != NULL, -1);
 
-       if ((fp = fopen(file, "rb")) == NULL) {
+       if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return -1;
        }
@@ -1439,7 +1439,7 @@ static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_ses
                /* write to temporary file */
                tmp = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
                            G_DIR_SEPARATOR, (gint)file);
-               if ((tmpfp = fopen(tmp, "wb")) == NULL) {
+               if ((tmpfp = g_fopen(tmp, "wb")) == NULL) {
                        FILE_OP_ERROR(tmp, "fopen");
                        newsval = -1;
                        alertpanel_error(_("Could not create temporary file for news sending."));
@@ -1469,7 +1469,7 @@ static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_ses
                                                 newsac->nntp_server);
                                }
                        }
-                       unlink(tmp);
+                       g_unlink(tmp);
                }
                g_free(tmp);
        }
@@ -1494,7 +1494,7 @@ static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_ses
        }
 
        if (tmp_enc_file != NULL) {
-               unlink(tmp_enc_file);
+               g_unlink(tmp_enc_file);
                free(tmp_enc_file);
                tmp_enc_file = NULL;
        }
@@ -1940,7 +1940,7 @@ MsgInfo *procmsg_msginfo_new_from_mimeinfo(MsgInfo *src_msginfo, MimeInfo *mimei
                }
        } else {
                gchar *tmpfile = get_tmp_file();
-               FILE *fp = fopen(tmpfile, "wb");
+               FILE *fp = g_fopen(tmpfile, "wb");
                if (fp && procmime_write_mimeinfo(mimeinfo, fp) >= 0) {
                        if (fp)
                                fclose(fp);
index 67987f6..1125e2a 100644 (file)
@@ -44,7 +44,7 @@ gint recv_write_to_file(SockInfo *sock, const gchar *filename)
 
        g_return_val_if_fail(filename != NULL, -1);
 
-       if ((fp = fopen(filename, "wb")) == NULL) {
+       if ((fp = g_fopen(filename, "wb")) == NULL) {
                FILE_OP_ERROR(filename, "fopen");
                recv_write(sock, NULL);
                return -1;
@@ -55,13 +55,13 @@ gint recv_write_to_file(SockInfo *sock, const gchar *filename)
 
        if ((ret = recv_write(sock, fp)) < 0) {
                fclose(fp);
-               unlink(filename);
+               g_unlink(filename);
                return ret;
        }
 
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(filename, "fclose");
-               unlink(filename);
+               g_unlink(filename);
                return -1;
        }
 
@@ -75,7 +75,7 @@ gint recv_bytes_write_to_file(SockInfo *sock, glong size, const gchar *filename)
 
        g_return_val_if_fail(filename != NULL, -1);
 
-       if ((fp = fopen(filename, "wb")) == NULL) {
+       if ((fp = g_fopen(filename, "wb")) == NULL) {
                FILE_OP_ERROR(filename, "fopen");
                recv_write(sock, NULL);
                return -1;
@@ -86,13 +86,13 @@ gint recv_bytes_write_to_file(SockInfo *sock, glong size, const gchar *filename)
 
        if ((ret = recv_bytes_write(sock, size, fp)) < 0) {
                fclose(fp);
-               unlink(filename);
+               g_unlink(filename);
                return ret;
        }
 
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(filename, "fclose");
-               unlink(filename);
+               g_unlink(filename);
                return -1;
        }
 
index 466ddad..1af7329 100644 (file)
@@ -91,7 +91,7 @@ gint send_message(const gchar *file, PrefsAccount *ac_prefs, GSList *to_list)
        g_return_val_if_fail(ac_prefs != NULL, -1);
        g_return_val_if_fail(to_list != NULL, -1);
 
-       if ((fp = fopen(file, "rb")) == NULL) {
+       if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return -1;
        }
index be6292b..ffa900e 100644 (file)
@@ -146,7 +146,7 @@ load_domain( const char *filename )
     size_t to_read;
     char *read_ptr;
 
-    fp = fopen( filename, "rb" );
+    fp = g_fopen( filename, "rb" );
     if( !fp )
        return NULL; /* can't open the file */
     /* we must know about the size of the file */
index 71793db..6bf9048 100644 (file)
@@ -136,7 +136,7 @@ void source_window_show_msg(SourceWindow *sourcewin, MsgInfo *msginfo)
        file = procmsg_get_message_file(msginfo);
        g_return_if_fail(file != NULL);
 
-       if ((fp = fopen(file, "rb")) == NULL) {
+       if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                g_free(file);
                return;
index 517e9a1..0244577 100644 (file)
@@ -500,7 +500,7 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
        if ((mimeinfo->type == MIMETYPE_MESSAGE) && !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
                FILE *fp;
 
-               fp = fopen(mimeinfo->data.filename, "rb");
+               fp = g_fopen(mimeinfo->data.filename, "rb");
                fseek(fp, mimeinfo->offset, SEEK_SET);
                headers = textview_scan_header(textview, fp);
                if (headers) {
@@ -538,7 +538,7 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                        gchar *uri_str;
                        FILE *fp;
 
-                       fp = fopen(mimeinfo->data.filename, "rb");
+                       fp = g_fopen(mimeinfo->data.filename, "rb");
                        fseek(fp, mimeinfo->offset, SEEK_SET);
 
                        filename = procmime_get_tmp_file_name(mimeinfo);
@@ -751,10 +751,10 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                
                filename = procmime_get_tmp_file_name(mimeinfo);
                if (procmime_get_part(filename, mimeinfo) == 0) {
-                       tmpfp = fopen(filename, "rb");
+                       tmpfp = g_fopen(filename, "rb");
                        textview_show_html(textview, tmpfp, conv);
                        fclose(tmpfp);
-                       unlink(filename);
+                       g_unlink(filename);
                }
                g_free(filename);
        } else if (!g_ascii_strcasecmp(mimeinfo->subtype, "enriched")) {
@@ -762,14 +762,14 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                
                filename = procmime_get_tmp_file_name(mimeinfo);
                if (procmime_get_part(filename, mimeinfo) == 0) {
-                       tmpfp = fopen(filename, "rb");
+                       tmpfp = g_fopen(filename, "rb");
                        textview_show_ertf(textview, tmpfp, conv);
                        fclose(tmpfp);
-                       unlink(filename);
+                       g_unlink(filename);
                }
                g_free(filename);
        } else {
-               tmpfp = fopen(mimeinfo->data.filename, "rb");
+               tmpfp = g_fopen(mimeinfo->data.filename, "rb");
                fseek(tmpfp, mimeinfo->offset, SEEK_SET);
                debug_print("Viewing text content of type: %s (length: %d)\n", mimeinfo->subtype, mimeinfo->length);
                while ((fgets(buf, sizeof(buf), tmpfp) != NULL) && 
index ea2da2f..967b4de 100644 (file)
@@ -190,7 +190,7 @@ static gint vcard_open_file( VCardFile* cardFile ) {
        /* fprintf( stdout, "Opening file\n" ); */
        cardFile->addressCache->dataRead = FALSE;
        if( cardFile->path ) {
-               cardFile->file = fopen( cardFile->path, "rb" );
+               cardFile->file = g_fopen( cardFile->path, "rb" );
                if( ! cardFile->file ) {
                        /* fprintf( stderr, "can't open %s\n", cardFile->path ); */
                        cardFile->retVal = MGU_OPEN_FILE;
@@ -650,7 +650,7 @@ gchar *vcard_find_gnomecard( void ) {
        strcat( str, GNOMECARD_FILE );
 
        fileSpec = NULL;
-       if( ( fp = fopen( str, "rb" ) ) != NULL ) {
+       if( ( fp = g_fopen( str, "rb" ) ) != NULL ) {
                /* Read configuration file */
                lenlbl = strlen( GNOMECARD_SECTION );
                while( fgets( buf, sizeof( buf ), fp ) != NULL ) {