Wrap file I/O to claws_* to benefit from custom locking when
authorColin Leroy <colin@colino.net>
Sun, 7 Oct 2018 12:12:29 +0000 (14:12 +0200)
committerColin Leroy <colin@colino.net>
Sun, 7 Oct 2018 12:13:54 +0000 (14:13 +0200)
available. Gains about 33% on I/O bound tasks.

95 files changed:
configure.ac
src/account.c
src/addrbook.c
src/addrharvest.c
src/addrindex.c
src/advsearch.c
src/autofaces.c
src/common/claws_io.c
src/common/claws_io.h
src/common/log.c
src/common/plugin.c
src/common/prefs.c
src/common/ssl_certificate.c
src/common/tags.c
src/common/template.c
src/common/utils.c
src/common/xml.c
src/common/xml.h
src/common/xmlprops.c
src/compose.c
src/enriched.c
src/etpan/imap-thread.c
src/exporthtml.c
src/exportldif.c
src/folder.c
src/gtk/about.c
src/html.c
src/imap.c
src/jpilot.c
src/ldapquery.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/passwordstore.c
src/pine.c
src/plugins/acpi_notifier/acpi_notifier.c
src/plugins/bogofilter/bogofilter.c
src/plugins/clamd/libclamd/clamd-plugin.c
src/plugins/fancy/claws.def
src/plugins/fancy/fancy_viewer.c
src/plugins/libravatar/claws.def
src/plugins/libravatar/libravatar_image.c
src/plugins/libravatar/libravatar_missing.c
src/plugins/mailmbox/claws.def
src/plugins/mailmbox/mailimf.c
src/plugins/mailmbox/mailimf_write.c
src/plugins/mailmbox/mailmbox.c
src/plugins/mailmbox/mailmbox_folder.c
src/plugins/newmail/newmail.c
src/plugins/perl/perl_plugin.c
src/plugins/pgpcore/claws.def
src/plugins/pgpcore/pgp_utils.c
src/plugins/pgpcore/sgpgme.c
src/plugins/pgpinline/claws.def
src/plugins/pgpinline/pgpinline.c
src/plugins/pgpmime/claws.def
src/plugins/pgpmime/pgpmime.c
src/plugins/python/python_plugin.c
src/plugins/rssyl/claws.def
src/plugins/rssyl/opml_export.c
src/plugins/rssyl/rssyl_add_item.c
src/plugins/rssyl/rssyl_deleted.c
src/plugins/smime/claws.def
src/plugins/smime/smime.c
src/plugins/spamassassin/spamassassin.c
src/plugins/tnef_parse/claws.def
src/plugins/tnef_parse/tnef_parse.c
src/plugins/vcalendar/claws.def
src/plugins/vcalendar/vcal_meeting_gtk.c
src/plugins/vcalendar/vcalendar.c
src/pop.c
src/prefs_account.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/quote_fmt_parse.y
src/send_message.c
src/sourcewindow.c
src/summaryview.c
src/textview.c
src/vcard.c

index c6ef76f..a5f1bc9 100644 (file)
@@ -180,7 +180,7 @@ if test x"$_gcc_psign" = xyes ; then
        CFLAGS="$CFLAGS -Wno-pointer-sign"
 fi
 
-CFLAGS="$CFLAGS -Wall"
+CFLAGS="$CFLAGS -Wall -D_GNU_SOURCE"
 
 if test $USE_MAINTAINER_MODE = yes; then
        CFLAGS="$CFLAGS -g -Wno-pointer-sign -DUSE_MAINTAINER_MODE"
@@ -427,7 +427,7 @@ AC_CHECK_FUNCS(gethostname mkdir mktime socket strstr strchr \
               uname flock lockf inet_aton inet_addr \
               fchmod mkstemp truncate getuid regcomp)
 
-AC_CHECK_FUNCS(fgets_unlocked fwrite_unlocked fmemopen)
+AC_CHECK_FUNCS(fgets_unlocked fgetc_unlocked fputs_unlocked fputc_unlocked fread_unlocked fwrite_unlocked feof_unlocked ferror_unlocked fmemopen)
 
 dnl *****************
 dnl ** common code **
index e73a012..285257b 100644 (file)
@@ -55,6 +55,7 @@
 #include "prefs_actions.h"
 #include "hooks.h"
 #include "passwordstore.h"
+#include "claws_io.h"
 
 enum {
        ACCOUNT_IS_DEFAULT,
@@ -194,14 +195,14 @@ 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 = g_fopen(rcpath, "rb")) == NULL) {
-               if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
+       if ((fp = claws_fopen(rcpath, "rb")) == NULL) {
+               if (ENOENT != errno) FILE_OP_ERROR(rcpath, "claws_fopen");
                g_free(rcpath);
                return;
        }
        g_free(rcpath);
 
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                if (!strncmp(buf, "[Account: ", 10)) {
                        strretchomp(buf);
                        memmove(buf, buf + 1, sizeof(buf) - 1);
@@ -211,7 +212,7 @@ void account_read_config_all(void)
                                                       g_strdup(buf));
                }
        }
-       fclose(fp);
+       claws_fclose(fp);
 
        /* read config data from file */
        cur_account = NULL;
index 0720c6b..64a3645 100644 (file)
 
 /* General functions for accessing address book files */
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
+
 #include <glib.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -951,11 +956,11 @@ static int addrbook_write_elem_s(FILE *fp, gint lvl, gchar *name)
 {
        gint i;
        for (i = 0; i < lvl; i++) 
-               if (fputs("  ", fp) == EOF)
+               if (claws_fputs("  ", fp) == EOF)
                        return -1;
-       if (fputs("<", fp) == EOF)
+       if (claws_fputs("<", fp) == EOF)
                return -1;
-       if (fputs(name, fp) == EOF)
+       if (claws_fputs(name, fp) == EOF)
                return -1;
                
        return 0;
@@ -971,13 +976,13 @@ static int addrbook_write_elem_e(FILE *fp, gint lvl, gchar *name)
 {
        gint i;
        for(i = 0; i < lvl; i++)
-               if (fputs("  ", fp) == EOF)
+               if (claws_fputs("  ", fp) == EOF)
                        return -1;
-       if (fputs("</", fp) == EOF)
+       if (claws_fputs("</", fp) == EOF)
                return -1;
-       if (fputs(name, fp) == EOF)
+       if (claws_fputs(name, fp) == EOF)
                return -1;
-       if (fputs(">\n", fp) == EOF)
+       if (claws_fputs(">\n", fp) == EOF)
                return -1;
                
        return 0;
@@ -991,15 +996,15 @@ static int addrbook_write_elem_e(FILE *fp, gint lvl, gchar *name)
  */
 static int addrbook_write_attr(FILE *fp, gchar *name, gchar *value)
 {
-       if (fputs(" ", fp) == EOF)
+       if (claws_fputs(" ", fp) == EOF)
                return -1;
-       if (fputs(name, fp) == EOF)
+       if (claws_fputs(name, fp) == EOF)
                return -1;
-       if (fputs("=\"", fp) == EOF)
+       if (claws_fputs("=\"", fp) == EOF)
                return -1;
        if (xml_file_put_escape_str(fp, value) < 0)
                return -1;
-       if (fputs("\"", fp) == EOF)
+       if (claws_fputs("\"", fp) == EOF)
                return -1;
        
        return 0;
@@ -1042,13 +1047,13 @@ static void addrbook_write_item_person_vis(gpointer key, gpointer value,
                                data->error = TRUE;
                        if (addrbook_write_attr(fp, AB_ATTAG_COMMON_NAME, ADDRITEM_NAME(person)) < 0)
                                data->error = TRUE;
-                       if (fputs(" >\n", fp) == EOF)
+                       if (claws_fputs(" >\n", fp) == EOF)
                                data->error = TRUE;
 
                        /* Output email addresses */
                        if (addrbook_write_elem_s(fp, 2, AB_ELTAG_ADDRESS_LIST) < 0)
                                data->error = TRUE;
-                       if (fputs(">\n", fp) == EOF)
+                       if (claws_fputs(">\n", fp) == EOF)
                                data->error = TRUE;
                        node = person->listEMail;
                        while (node) {
@@ -1063,7 +1068,7 @@ static void addrbook_write_item_person_vis(gpointer key, gpointer value,
                                        data->error = TRUE;
                                if (addrbook_write_attr(fp, AB_ATTAG_REMARKS, email->remarks) < 0)
                                        data->error = TRUE;
-                               if (fputs(" />\n", fp) == EOF)
+                               if (claws_fputs(" />\n", fp) == EOF)
                                        data->error = TRUE;
                                node = g_list_next(node);
                        }
@@ -1073,7 +1078,7 @@ static void addrbook_write_item_person_vis(gpointer key, gpointer value,
                        /* Output user attributes */
                        if (addrbook_write_elem_s(fp, 2, AB_ELTAG_ATTRIBUTE_LIST) < 0)
                                data->error = TRUE;
-                       if (fputs(">\n", fp) == EOF)
+                       if (claws_fputs(">\n", fp) == EOF)
                                data->error = TRUE;
                        node = person->listAttrib;
                        while (node) {
@@ -1084,7 +1089,7 @@ static void addrbook_write_item_person_vis(gpointer key, gpointer value,
                                        data->error = TRUE;
                                if (addrbook_write_attr(fp, AB_ATTAG_NAME, attrib->name) < 0)
                                        data->error = TRUE;
-                               if (fputs(" >", fp) == EOF)
+                               if (claws_fputs(" >", fp) == EOF)
                                        data->error = TRUE;
                                if (xml_file_put_escape_str(fp, attrib->value) < 0)
                                        data->error = TRUE;
@@ -1129,13 +1134,13 @@ static void addrbook_write_item_group_vis(gpointer key, gpointer value,
                                data->error = TRUE;
                        if (addrbook_write_attr(fp, AB_ATTAG_REMARKS, group->remarks) < 0)
                                data->error = TRUE;
-                       if (fputs(" >\n", fp) == EOF)
+                       if (claws_fputs(" >\n", fp) == EOF)
                                data->error = TRUE;
 
                        /* Output email address links */
                        if (addrbook_write_elem_s(fp, 2, AB_ELTAG_MEMBER_LIST) < 0)
                                data->error = TRUE;
-                       if (fputs(">\n", fp) == EOF)
+                       if (claws_fputs(">\n", fp) == EOF)
                                data->error = TRUE;
                        node = group->listEMail;
                        while (node) {
@@ -1147,7 +1152,7 @@ static void addrbook_write_item_group_vis(gpointer key, gpointer value,
                                        data->error = TRUE;
                                if (addrbook_write_attr(fp, AB_ATTAG_EID, ADDRITEM_ID(email)) < 0)
                                        data->error = TRUE;
-                               if (fputs(" />\n", fp) == EOF)
+                               if (claws_fputs(" />\n", fp) == EOF)
                                        data->error = TRUE;
                                node = g_list_next(node);
                        }
@@ -1187,11 +1192,11 @@ static void addrbook_write_item_folder_vis(gpointer key, gpointer value,
                                data->error = TRUE;
                        if (addrbook_write_attr(fp, AB_ATTAG_REMARKS, folder->remarks) < 0)
                                data->error = TRUE;
-                       if (fputs(" >\n", fp) == EOF)
+                       if (claws_fputs(" >\n", fp) == EOF)
                                data->error = TRUE;
                        if (addrbook_write_elem_s(fp, 2, AB_ELTAG_ITEM_LIST) < 0)
                                data->error = TRUE;
-                       if (fputs(">\n", fp) == EOF)
+                       if (claws_fputs(">\n", fp) == EOF)
                                data->error = TRUE;
 
                        /* Output persons */
@@ -1204,7 +1209,7 @@ static void addrbook_write_item_folder_vis(gpointer key, gpointer value,
                                        data->error = TRUE;
                                if (addrbook_write_attr(fp, AB_ATTAG_UID, ADDRITEM_ID(item)) < 0)
                                        data->error = TRUE;
-                               if (fputs(" />\n", fp) == EOF)
+                               if (claws_fputs(" />\n", fp) == EOF)
                                        data->error = TRUE;
                                node = g_list_next(node);
                        }
@@ -1219,7 +1224,7 @@ static void addrbook_write_item_folder_vis(gpointer key, gpointer value,
                                        data->error = TRUE;
                                if (addrbook_write_attr(fp, AB_ATTAG_UID, ADDRITEM_ID(item)) < 0)
                                        data->error = TRUE;
-                               if (fputs(" />\n", fp) == EOF)
+                               if (claws_fputs(" />\n", fp) == EOF)
                                        data->error = TRUE;
                                node = g_list_next(node);
                        }
@@ -1234,7 +1239,7 @@ static void addrbook_write_item_folder_vis(gpointer key, gpointer value,
                                        data->error = TRUE;
                                if (addrbook_write_attr(fp, AB_ATTAG_UID, ADDRITEM_ID(item)) < 0)
                                        data->error = TRUE;
-                               if (fputs(" />\n", fp) == EOF)
+                               if (claws_fputs(" />\n", fp) == EOF)
                                        data->error = TRUE;
                                node = g_list_next(node);
                        }
@@ -1268,10 +1273,10 @@ static gint addrbook_write_to(AddressBookFile *book, gchar *newFile)
 
        book->retVal = MGU_OPEN_FILE;
 #ifdef DEV_STANDALONE
-       fp = g_fopen(fileSpec, "wb");
+       fp = claws_fopen(fileSpec, "wb");
        g_free(fileSpec);
        if (fp) {
-               if (fputs("<?xml version=\"1.0\" ?>\n", fp) == EOF) {
+               if (claws_fputs("<?xml version=\"1.0\" ?>\n", fp) == EOF) {
                        book->retVal = MGU_ERROR_WRITE;
                        return book->retVal;
                }
@@ -1288,7 +1293,7 @@ static gint addrbook_write_to(AddressBookFile *book, gchar *newFile)
                if (addrbook_write_attr(fp, AB_ATTAG_NAME,
                                    addrcache_get_name(book->addressCache)) < 0)
                        goto fail;
-               if (fputs(" >\n", fp) == EOF)
+               if (claws_fputs(" >\n", fp) == EOF)
                        goto fail;
 
                /* Output all persons */
@@ -1319,7 +1324,7 @@ static gint addrbook_write_to(AddressBookFile *book, gchar *newFile)
 
                book->retVal = MGU_SUCCESS;
 #ifdef DEV_STANDALONE
-               safe_fclose(fp);
+               claws_safe_fclose(fp);
 #else
                if (prefs_file_close( pfile ) < 0)
                        book->retVal = MGU_ERROR_WRITE;
index 6d4bf3b..1d94633 100644 (file)
  * Functions for an E-Mail address harvester.
  */
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
+
 #include <sys/stat.h>
 #include <dirent.h>
 #include <glib.h>
@@ -35,6 +40,7 @@
 #ifdef USE_ALT_ADDRBOOK
        #include "addressbook-dbus.h"
 #endif
+#include "claws_io.h"
 
 /* Mail header names of interest */
 static gchar *_headerFrom_     = HEADER_FROM;
@@ -644,7 +650,7 @@ static GSList *addrharvest_get_header( FILE *fp, GList *listHdr, gboolean *done
        list = NULL;
 
        /* Read line */
-       if( fgets( buf, MSG_BUFFSIZE, fp ) == NULL ) {
+       if( claws_fgets( buf, MSG_BUFFSIZE, fp ) == NULL ) {
                *done = TRUE;
                return list;
        }
@@ -671,7 +677,7 @@ static GSList *addrharvest_get_header( FILE *fp, GList *listHdr, gboolean *done
                ch = fgetc( fp );
                if( ch == ' ' || ch == '\t' ) {
                        /* Continuation character - read into buffer */
-                       if( fgets( buf, MSG_BUFFSIZE, fp ) == NULL ) {
+                       if( claws_fgets( buf, MSG_BUFFSIZE, fp ) == NULL ) {
                                break;
                        }
                }
@@ -708,7 +714,7 @@ static gint addrharvest_readfile(
        GSList *list;
        gboolean done;
 
-       msgFile = g_fopen( fileName, "rb" );
+       msgFile = claws_fopen( fileName, "rb" );
        if( ! msgFile ) {
                /* Cannot open file */
                retVal = MGU_OPEN_FILE;
@@ -747,7 +753,7 @@ static gint addrharvest_readfile(
                g_free( buf );
        }
 
-       fclose( msgFile );
+       claws_fclose( msgFile );
        return MGU_SUCCESS;
 }
 
index f1adf01..bad1fa5 100644 (file)
@@ -937,11 +937,11 @@ static AddressInterface *addrindex_tag_get_datasource(
 static int addrindex_write_elem_s( FILE *fp, const gint lvl, const gchar *name ) {
        gint i;
        for( i = 0; i < lvl; i++ ) 
-               if (fputs( "  ", fp ) == EOF)
+               if (claws_fputs( "  ", fp ) == EOF)
                        return -1;
-       if (fputs( "<", fp ) == EOF)
+       if (claws_fputs( "<", fp ) == EOF)
                return -1;
-       if (fputs( name, fp ) == EOF)
+       if (claws_fputs( name, fp ) == EOF)
                return -1;
        return 0;
 }
@@ -955,13 +955,13 @@ static int addrindex_write_elem_s( FILE *fp, const gint lvl, const gchar *name )
 static int addrindex_write_elem_e( FILE *fp, const gint lvl, const gchar *name ) {
        gint i;
        for( i = 0; i < lvl; i++ ) 
-               if (fputs( "  ", fp ) == EOF)
+               if (claws_fputs( "  ", fp ) == EOF)
                        return -1;
-       if (fputs( "</", fp ) == EOF)
+       if (claws_fputs( "</", fp ) == EOF)
                return -1;
-       if (fputs( name, fp ) == EOF)
+       if (claws_fputs( name, fp ) == EOF)
                return -1;
-       if (fputs( ">\n", fp ) == EOF)
+       if (claws_fputs( ">\n", fp ) == EOF)
                return -1;
        return 0;
 }
@@ -973,15 +973,15 @@ static int addrindex_write_elem_e( FILE *fp, const gint lvl, const gchar *name )
  * \param value Attribute value.
  */
 static int addrindex_write_attr( FILE *fp, const gchar *name, const gchar *value ) {
-       if (fputs( " ", fp ) == EOF)
+       if (claws_fputs( " ", fp ) == EOF)
                return -1;
-       if (fputs( name, fp ) == EOF)
+       if (claws_fputs( name, fp ) == EOF)
                return -1;
-       if (fputs( "=\"", fp ) == EOF)
+       if (claws_fputs( "=\"", fp ) == EOF)
                return -1;
        if (xml_file_put_escape_str( fp, value ) < 0)
                return -1;
-       if (fputs( "\"", fp ) == EOF)
+       if (claws_fputs( "\"", fp ) == EOF)
                return -1;
        return 0;
 }
@@ -1071,7 +1071,7 @@ static int addrindex_write_fragment(
                        node = g_list_next( node );
                }
                if( fragment->children ) {
-                       if (fputs(" >\n", fp) == EOF)
+                       if (claws_fputs(" >\n", fp) == EOF)
                                return -1;
 
                        /* Output children */
@@ -1088,7 +1088,7 @@ static int addrindex_write_fragment(
                                return -1;
                }
                else {
-                       if (fputs(" />\n", fp) == EOF)
+                       if (claws_fputs(" />\n", fp) == EOF)
                                return -1;
                }
        }
@@ -1134,7 +1134,7 @@ static int addrindex_write_book( FILE *fp, AddressDataSource *ds, gint lvl ) {
                        return -1;
                if (addrindex_write_attr( fp, ATTAG_BOOK_FILE, abf->fileName ) < 0)
                        return -1;
-               if (fputs( " />\n", fp ) == EOF)
+               if (claws_fputs( " />\n", fp ) == EOF)
                        return -1;
        }
        return 0;
@@ -1172,7 +1172,7 @@ static int addrindex_write_vcard( FILE *fp, AddressDataSource *ds, gint lvl ) {
                        return -1;
                if (addrindex_write_attr( fp, ATTAG_VCARD_FILE, vcf->path ) < 0)
                        return -1;
-               if (fputs( " />\n", fp ) == EOF)
+               if (claws_fputs( " />\n", fp ) == EOF)
                        return -1;
        }
        return 0;
@@ -1237,7 +1237,7 @@ static int addrindex_write_jpilot( FILE *fp,AddressDataSource *ds, gint lvl ) {
                        ind++;
                        node = g_list_next( node );
                }
-               if (fputs( " />\n", fp ) == EOF)
+               if (claws_fputs( " />\n", fp ) == EOF)
                        return -1;
        }
        return 0;
@@ -1519,7 +1519,7 @@ static int addrindex_write_ldap( FILE *fp, AddressDataSource *ds, gint lvl ) {
                        ATVAL_BOOLEAN_YES : ATVAL_BOOLEAN_NO ) < 0)
                return -1;
 
-       if (fputs(" >\n", fp) == EOF)
+       if (claws_fputs(" >\n", fp) == EOF)
                return -1;
 
        /* Output attributes */
@@ -1529,7 +1529,7 @@ static int addrindex_write_ldap( FILE *fp, AddressDataSource *ds, gint lvl ) {
                        return -1;
                if (addrindex_write_attr( fp, ATTAG_LDAP_ATTR_NAME, node->data ) < 0)
                        return -1;
-               if (fputs(" />\n", fp) == EOF)
+               if (claws_fputs(" />\n", fp) == EOF)
                        return -1;
                node = g_list_next( node );
        }
@@ -1708,7 +1708,7 @@ static int addrindex_write_index( AddressIndex *addrIndex, FILE *fp ) {
                        nodeDS = iface->listSource;
                        if (addrindex_write_elem_s( fp, lvlList, iface->listTag ) < 0)
                                return -1;
-                       if (fputs( ">\n", fp ) == EOF)
+                       if (claws_fputs( ">\n", fp ) == EOF)
                                return -1;
                        while( nodeDS ) {
                                AddressDataSource *ds = nodeDS->data;
@@ -1759,10 +1759,10 @@ static 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 = g_fopen( fileSpec, "wb" );
+       fp = claws_fopen( fileSpec, "wb" );
        g_free( fileSpec );
        if( fp ) {
-               fputs( "<?xml version=\"1.0\" ?>\n", fp );
+               claws_fputs( "<?xml version=\"1.0\" ?>\n", fp );
 #else
        pfile = prefs_write_open( fileSpec );
        g_free( fileSpec );
@@ -1773,7 +1773,7 @@ static gint addrindex_write_to( AddressIndex *addrIndex, const gchar *newFile )
 #endif
                if (addrindex_write_elem_s( fp, 0, TAG_ADDRESS_INDEX ) < 0)
                        goto fail;
-               if (fputs( ">\n", fp ) == EOF)
+               if (claws_fputs( ">\n", fp ) == EOF)
                        goto fail;
 
                if (addrindex_write_index( addrIndex, fp ) < 0)
@@ -1783,7 +1783,7 @@ static gint addrindex_write_to( AddressIndex *addrIndex, const gchar *newFile )
 
                addrIndex->retVal = MGU_SUCCESS;
 #ifdef DEV_STANDALONE
-               safe_fclose( fp );
+               claws_safe_fclose( fp );
 #else
                if( prefs_file_close( pfile ) < 0 ) {
                        addrIndex->retVal = MGU_ERROR_WRITE;
index ccfad6c..85dc3cc 100644 (file)
@@ -31,6 +31,7 @@
 #include "matcher_parser.h"
 #include "utils.h"
 #include "prefs_common.h"
+#include "timing.h"
 
 struct _AdvancedSearch {
        struct {
@@ -502,27 +503,33 @@ static gboolean search_impl(MsgInfoList **messages, AdvancedSearch* search,
                            FolderItem* folderItem, gboolean recursive)
 {
        if (recursive) {
-               if (!search_impl(messages, search, folderItem, FALSE))
+               START_TIMING("recursive");
+               if (!search_impl(messages, search, folderItem, FALSE)) {
+                       END_TIMING();
                        return FALSE;
-
+               }
                if (folderItem->node->children != NULL && !search->search_aborted) {
                        GNode *node;
                        for (node = folderItem->node->children; node != NULL; node = node->next) {
                                FolderItem *cur = FOLDER_ITEM(node->data);
                                debug_print("in: %s\n", cur->path);
-                               if (!search_impl(messages, search, cur, TRUE))
+                               if (!search_impl(messages, search, cur, TRUE)) {
+                                       END_TIMING();
                                        return FALSE;
+                               }
                        }
                }
+               END_TIMING();
        } else if (!folderItem->no_select) {
                MsgNumberList *msgnums = NULL;
                MsgNumberList *cur;
                MsgInfoList *msgs = NULL;
                gboolean can_search_on_server = folderItem->folder->klass->supports_server_search;
-
+               START_TIMING("folder");
                if (!search_filter_folder(&msgnums, search, folderItem,
                                          can_search_on_server)) {
                        g_slist_free(msgnums);
+                       END_TIMING();
                        return FALSE;
                }
 
@@ -542,6 +549,7 @@ static gboolean search_impl(MsgInfoList **messages, AdvancedSearch* search,
                }
 
                g_slist_free(msgnums);
+               END_TIMING();
        }
 
        return TRUE;
index 6146f65..d12c975 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "utils.h"
 #include "autofaces.h"
+#include "claws_io.h"
 
 static gint get_content_for_any_face(gchar *buf, gint len, gchar *anyname, gint maxlen)
 {
@@ -37,20 +38,20 @@ static gint get_content_for_any_face(gchar *buf, gint len, gchar *anyname, gint
        xfile = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, AUTOFACES_DIR,
                            G_DIR_SEPARATOR_S, anyname, NULL);
        buf[0] = '\0';
-       if ((xfp = g_fopen(xfile, "rb")) == NULL) {
+       if ((xfp = claws_fopen(xfile, "rb")) == NULL) {
                g_free(xfile);
                debug_print("header content file '%s' not found\n", anyname);
                return -1;
        }
-       if (fgets(buf, (len < maxlen)? len: maxlen, xfp) == NULL) {
-               fclose(xfp);
+       if (claws_fgets(buf, (len < maxlen)? len: maxlen, xfp) == NULL) {
+               claws_fclose(xfp);
                g_free(xfile);
                g_warning("header content file '%s' read failure", anyname);
                return -2;
        }
        lastc = strlen(buf) - 1;        /* remove trailing \n */
        buf[lastc] = (buf[lastc] == '\n')? '\0': buf[lastc];
-       fclose(xfp);
+       claws_fclose(xfp);
        g_free(xfile);
 
        return 0;
index 1de8bea..6268978 100644 (file)
 #include <unistd.h>
 
 #include "timing.h"
+#include "claws_io.h"
 
 gboolean prefs_common_get_flush_metadata(void);
 
+/* FIXME make static once every file I/O is done using claws_* wrappers */
 int safe_fclose(FILE *fp)
 {
        int r;
@@ -45,3 +47,47 @@ int safe_fclose(FILE *fp)
 
        return r;
 }
+
+#if HAVE_FGETS_UNLOCKED
+
+/* Open a file and locks it once
+ * so subsequent I/O is faster
+ */
+FILE *claws_fopen(const char *file, const char *mode)
+{
+       FILE *fp = fopen(file, mode);
+       if (!fp)
+               return NULL;
+       flockfile(fp);
+       return fp;
+}
+
+FILE *claws_fdopen(int fd, const char *mode)
+{
+       FILE *fp = fdopen(fd, mode);
+       if (!fp)
+               return NULL;
+       flockfile(fp);
+       return fp;
+}
+
+/* Unlocks and close a file pointer
+ */
+
+int claws_fclose(FILE *fp)
+{
+       funlockfile(fp);
+       return fclose(fp);
+}
+
+/* Unlock, then safe-close a file pointer
+ * Safe close is done using fflush + fsync
+ * if the according preference says so.
+ */
+int claws_safe_fclose(FILE *fp)
+{
+       funlockfile(fp);
+       return safe_fclose(fp);
+}
+
+#endif
index e3e0e0c..35edae3 100644 (file)
 #ifndef __CLAWS_IO_H__
 #define __CLAWS_IO_H__
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
+
+#include <stdio.h>
+
+#if HAVE_FGETS_UNLOCKED
+#define claws_fgets fgets_unlocked
+#define claws_fgetc fgetc_unlocked
+#define claws_fputs fputs_unlocked
+#define claws_fputc fputc_unlocked
+#define claws_fread fread_unlocked
+#define claws_fwrite fwrite_unlocked
+#define claws_feof feof_unlocked
+#define claws_ferror ferror_unlocked
+
+FILE *claws_fopen(const char *file, const char *mode);
+FILE *claws_fdopen(int fd, const char *mode);
+int claws_fclose(FILE *fp);
+int claws_safe_fclose(FILE *fp);
+
+#else
+
+#define claws_fgets fgets
+#define claws_fgetc fgetc
+#define claws_fputs fputs
+#define claws_fputc fputc
+#define claws_fread fread
+#define claws_fwrite fwrite
+#define claws_feof feof
+#define claws_ferror ferror
+#define claws_fopen g_fopen
+#define claws_fdopen fdopen
+#define claws_fclose fclose
+#define claws_safe_fclose safe_fclose
+#endif
+
 int safe_fclose(FILE *fp);
 
 #endif
index 65f284e..15a852b 100644 (file)
@@ -28,7 +28,6 @@
 #  include <w32lib.h>
 #endif
 
-#include <stdio.h>
 #include <glib.h>
 #include <glib/gi18n.h>
 
 #include "hooks.h"
 #include "claws_io.h"
 
-#define FWRITE(_b,_s,_n,_f)    if (fwrite(_b,_s,_n,_f) != _n) { \
-                                       g_message("log fwrite failed!\n"); \
+#define FWRITE(_b,_s,_n,_f)    if (claws_fwrite(_b,_s,_n,_f) != _n) { \
+                                       g_message("log claws_fwrite failed!\n"); \
                                        return; \
                                }
-#define FPUTS(_b,_f)           if (fputs(_b,_f) == EOF) { \
-                                       g_message("log fputs failed!\n"); \
+#define FPUTS(_b,_f)           if (claws_fputs(_b,_f) == EOF) { \
+                                       g_message("log claws_fputs failed!\n"); \
                                        return; \
                                }
 #define FFLUSH(_f)             if (fflush(_f) != 0) { \
@@ -122,9 +121,9 @@ void set_log_file(LogInstance instance, const gchar *filename)
                g_free(backupname);
        }
 
-       log_fp[instance] = g_fopen(fullname, "wb");
+       log_fp[instance] = claws_fopen(fullname, "wb");
        if (!log_fp[instance]) {
-               FILE_OP_ERROR(fullname, "fopen");
+               FILE_OP_ERROR(fullname, "claws_fopen");
                log_filename[instance] = NULL;
                g_free(fullname);
                return;
@@ -137,7 +136,7 @@ void set_log_file(LogInstance instance, const gchar *filename)
 void close_log_file(LogInstance instance)
 {
        if (log_fp[instance]) {
-               safe_fclose(log_fp[instance]);
+               claws_safe_fclose(log_fp[instance]);
                log_fp[instance] = NULL;
                log_size[instance] = 0;
                g_free(log_filename[instance]);
index 64a6f01..963b16d 100644 (file)
@@ -41,6 +41,7 @@
 #include "prefs.h"
 #include "claws.h"
 #include "timing.h"
+#include "claws_io.h"
 
 #ifdef G_OS_WIN32
 #define PLUGINS_BLOCK_PREFIX "PluginsWin32_"
@@ -245,13 +246,13 @@ static gint plugin_load_deps(const gchar *filename, gchar **error)
        deps_file = g_strconcat(tmp, ".deps", NULL);
        g_free(tmp);
        
-       fp = g_fopen(deps_file, "rb");
+       fp = claws_fopen(deps_file, "rb");
        g_free(deps_file);
        
        if (!fp)
                return 0;
        
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                Plugin *dep_plugin = NULL;
                gchar *path = NULL;
                buf[strlen(buf)-1]='\0'; /* chop off \n */
@@ -262,7 +263,7 @@ static gint plugin_load_deps(const gchar *filename, gchar **error)
                        dep_plugin = plugin_load(path, error);
                        if (dep_plugin == NULL) {
                                g_free(path);
-                               fclose(fp);
+                               claws_fclose(fp);
                                return -1;
                        }
                        dep_plugin->in_prefix_dir = TRUE;
@@ -278,7 +279,7 @@ static gint plugin_load_deps(const gchar *filename, gchar **error)
                                        g_strdup(filename));
                }
        }
-       fclose(fp);
+       claws_fclose(fp);
        return 0;
 }
 
@@ -605,7 +606,7 @@ void plugin_load_all(const gchar *type)
        }
        g_free(block);
 
-       while (fgets(buf, sizeof(buf), pfile->fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), pfile->fp) != NULL) {
                if (buf[0] == '[')
                        break;
 
index 77b4213..971193e 100644 (file)
@@ -22,6 +22,8 @@
 #include "claws-features.h"
 #endif
 
+#include <stdio.h>
+
 #include "defs.h"
 
 #include <glib.h>
@@ -46,8 +48,8 @@ PrefFile *prefs_read_open(const gchar *path)
 
        cm_return_val_if_fail(path != NULL, NULL);
 
-       if ((fp = g_fopen(path, "rb")) == NULL) {
-               FILE_OP_ERROR(path, "fopen");
+       if ((fp = claws_fopen(path, "rb")) == NULL) {
+               FILE_OP_ERROR(path, "claws_fopen");
                return NULL;
        }
 
@@ -83,8 +85,8 @@ PrefFile *prefs_write_open(const gchar *path)
        }
 
        tmppath = g_strconcat(path, ".tmp", NULL);
-       if ((fp = g_fopen(tmppath, "wb")) == NULL) {
-               FILE_OP_ERROR(tmppath, "fopen");
+       if ((fp = claws_fopen(tmppath, "wb")) == NULL) {
+               FILE_OP_ERROR(tmppath, "claws_fopen");
                g_free(tmppath);
                return NULL;
        }
@@ -128,17 +130,17 @@ gint prefs_file_close(PrefFile *pfile)
        path = pfile->path;
 
        if (!pfile->writing) {
-               fclose(fp);
+               claws_fclose(fp);
                g_free(pfile);
                g_free(path);
                return 0;
        }
 
        if (orig_fp) {
-               while (fgets(buf, sizeof(buf), orig_fp) != NULL) {
+               while (claws_fgets(buf, sizeof(buf), orig_fp) != NULL) {
                        /* next block */
                        if (buf[0] == '[') {
-                               if (fputs(buf, fp)  == EOF) {
+                               if (claws_fputs(buf, fp)  == EOF) {
                                        g_warning("failed to write configuration to file");
                                        prefs_file_close_revert(pfile);
                                
@@ -148,20 +150,20 @@ gint prefs_file_close(PrefFile *pfile)
                        }
                }
                
-               while (fgets(buf, sizeof(buf), orig_fp) != NULL)
-                       if (fputs(buf, fp) == EOF) {
+               while (claws_fgets(buf, sizeof(buf), orig_fp) != NULL)
+                       if (claws_fputs(buf, fp) == EOF) {
                                g_warning("failed to write configuration to file");
                                prefs_file_close_revert(pfile);                 
                                
                                return -1;
                        }
-               fclose(orig_fp);
+               claws_fclose(orig_fp);
        }
 
        tmppath = g_strconcat(path, ".tmp", NULL);
 
-       if (safe_fclose(fp) == EOF) {
-               FILE_OP_ERROR(tmppath, "fclose");
+       if (claws_safe_fclose(fp) == EOF) {
+               FILE_OP_ERROR(tmppath, "claws_fclose");
                claws_unlink(tmppath);
                g_free(path);
                g_free(tmppath);
@@ -214,10 +216,10 @@ gint prefs_file_close_revert(PrefFile *pfile)
        cm_return_val_if_fail(pfile != NULL, -1);
 
        if (pfile->orig_fp)
-               fclose(pfile->orig_fp);
+               claws_fclose(pfile->orig_fp);
        if (pfile->writing)
                tmppath = g_strconcat(pfile->path, ".tmp", NULL);
-       fclose(pfile->fp);
+       claws_fclose(pfile->fp);
        if (pfile->writing) {
                if (claws_unlink(tmppath) < 0) FILE_OP_ERROR(tmppath, "unlink");
                g_free(tmppath);
@@ -272,7 +274,7 @@ gint prefs_set_block_label(PrefFile *pfile, const gchar *label)
 
        block_label = g_strdup_printf("[%s]", label);
        if (!pfile->writing) {
-               while (fgets(buf, sizeof(buf), pfile->fp) != NULL) {
+               while (claws_fgets(buf, sizeof(buf), pfile->fp) != NULL) {
                        gint val;
                        
                        val = strncmp(buf, block_label, strlen(block_label));
@@ -282,10 +284,10 @@ gint prefs_set_block_label(PrefFile *pfile, const gchar *label)
                        }
                }
        } else {
-               if ((pfile->orig_fp = g_fopen(pfile->path, "rb")) != NULL) {
+               if ((pfile->orig_fp = claws_fopen(pfile->path, "rb")) != NULL) {
                        gboolean block_matched = FALSE;
 
-                       while (fgets(buf, sizeof(buf), pfile->orig_fp) != NULL) {
+                       while (claws_fgets(buf, sizeof(buf), pfile->orig_fp) != NULL) {
                                gint val;
 
                                val = strncmp(buf, block_label, strlen(block_label));
@@ -294,7 +296,7 @@ gint prefs_set_block_label(PrefFile *pfile, const gchar *label)
                                        block_matched = TRUE;
                                        break;
                                } else {
-                                       if (fputs(buf, pfile->fp) == EOF) {
+                                       if (claws_fputs(buf, pfile->fp) == EOF) {
                                                g_warning("failed to write configuration to file");
                                                prefs_file_close_revert(pfile);
                                                g_free(block_label);
@@ -305,13 +307,13 @@ gint prefs_set_block_label(PrefFile *pfile, const gchar *label)
                        }
 
                        if (!block_matched) {
-                               fclose(pfile->orig_fp);
+                               claws_fclose(pfile->orig_fp);
                                pfile->orig_fp = NULL;
                        }
                }
 
-               if (fputs(block_label, pfile->fp) == EOF ||
-                       fputc('\n', pfile->fp) == EOF) {
+               if (claws_fputs(block_label, pfile->fp) == EOF ||
+                       claws_fputc('\n', pfile->fp) == EOF) {
                        g_warning("failed to write configuration to file");
                        prefs_file_close_revert(pfile);
                        g_free(block_label);
index d098ac2..8afe4da 100644 (file)
@@ -173,7 +173,7 @@ static void gnutls_export_X509_fp(FILE *fp, gnutls_x509_crt_t x509_cert, gnutls_
        }
 
        debug_print("writing %zd bytes\n",cert_size);
-       if (fwrite(&output, 1, cert_size, fp) < cert_size) {
+       if (claws_fwrite(&output, 1, cert_size, fp) < cert_size) {
                g_warning("failed to write cert: %d %s", errno, g_strerror(errno));
        }
 }
@@ -241,8 +241,8 @@ static int gnutls_import_X509_list_fp(FILE *fp, gnutls_x509_crt_fmt_t format,
        tmp.data = malloc(s.st_size);
        memset(tmp.data, 0, s.st_size);
        tmp.size = s.st_size;
-       if (fread (tmp.data, 1, s.st_size, fp) < s.st_size) {
-               perror("fread");
+       if (claws_fread (tmp.data, 1, s.st_size, fp) < s.st_size) {
+               perror("claws_fread");
                free(tmp.data);
                free(crt_list);
                return -EIO;
@@ -300,8 +300,8 @@ static gnutls_x509_privkey_t gnutls_import_key_fp(FILE *fp, gnutls_x509_crt_fmt_
        tmp.data = malloc(s.st_size);
        memset(tmp.data, 0, s.st_size);
        tmp.size = s.st_size;
-       if (fread (tmp.data, 1, s.st_size, fp) < s.st_size) {
-               perror("fread");
+       if (claws_fread (tmp.data, 1, s.st_size, fp) < s.st_size) {
+               perror("claws_fread");
                free(tmp.data);
                return NULL;
        }
@@ -331,7 +331,7 @@ static gnutls_pkcs12_t gnutls_import_PKCS12_fp(FILE *fp, gnutls_x509_crt_fmt_t f
        tmp.data = malloc(s.st_size);
        memset(tmp.data, 0, s.st_size);
        tmp.size = s.st_size;
-       if (fread (tmp.data, 1, s.st_size, fp) < s.st_size) {
+       if (claws_fread (tmp.data, 1, s.st_size, fp) < s.st_size) {
                log_error(LOG_PROTOCOL, _("Cannot read P12 certificate file (%s)\n"),
                                  g_strerror(errno));
                free(tmp.data);
@@ -367,7 +367,7 @@ static void ssl_certificate_save (SSLCertificate *cert)
        file = get_certificate_path(cert->host, port, cert->fingerprint);
 
        g_free(port);
-       fp = g_fopen(file, "wb");
+       fp = claws_fopen(file, "wb");
        if (fp == NULL) {
                g_free(file);
                debug_print("Can't save certificate !\n");
@@ -377,7 +377,7 @@ static void ssl_certificate_save (SSLCertificate *cert)
        gnutls_export_X509_fp(fp, cert->x509_cert, GNUTLS_X509_FMT_DER);
 
        g_free(file);
-       safe_fclose(fp);
+       claws_safe_fclose(fp);
 
 }
 
@@ -421,14 +421,14 @@ SSLCertificate *ssl_certificate_find (const gchar *host, gushort port, const gch
        
        if (fingerprint != NULL) {
                file = get_certificate_path(host, buf, fingerprint);
-               fp = g_fopen(file, "rb");
+               fp = claws_fopen(file, "rb");
        }
        if (fp == NULL) {
                /* see if we have the old one */
                debug_print("didn't get %s\n", file);
                g_free(file);
                file = get_certificate_path(host, buf, NULL);
-               fp = g_fopen(file, "rb");
+               fp = claws_fopen(file, "rb");
 
                if (fp) {
                        debug_print("got %s\n", file);
@@ -449,7 +449,7 @@ SSLCertificate *ssl_certificate_find (const gchar *host, gushort port, const gch
                gnutls_x509_crt_deinit(tmp_x509);
        }
 
-       fclose(fp);
+       claws_fclose(fp);
        g_free(file);
        
        if (must_rename) {
@@ -531,7 +531,7 @@ static guint check_cert(SSLCertificate *cert)
        FILE *fp;
 
        if (claws_ssl_get_cert_file())
-               fp = g_fopen(claws_ssl_get_cert_file(), "r");
+               fp = claws_fopen(claws_ssl_get_cert_file(), "r");
        else
                return (guint)-1;
 
@@ -540,10 +540,10 @@ static guint check_cert(SSLCertificate *cert)
 
        if ((r = gnutls_import_X509_list_fp(fp, GNUTLS_X509_FMT_PEM, &ca_list, &max_ca)) < 0) {
                debug_print("CA import failed: %s\n", gnutls_strerror(r));
-               fclose(fp);
+               claws_fclose(fp);
                return (guint)-1;
        }
-       fclose(fp);
+       claws_fclose(fp);
        fp = NULL;
        
        buf = g_strdup_printf("%d", cert->port);
@@ -554,20 +554,20 @@ static guint check_cert(SSLCertificate *cert)
                size_t n = 128;
                char *fingerprint;
 
-               fp = g_fopen(chain_file, "r");
+               fp = claws_fopen(chain_file, "r");
                if (fp == NULL) {
-                       debug_print("fopen %s failed: %s\n", chain_file, g_strerror(errno));
+                       debug_print("claws_fopen %s failed: %s\n", chain_file, g_strerror(errno));
                        g_free(chain_file);
                        return (guint)-1;
                }
                if ((r = gnutls_import_X509_list_fp(fp, GNUTLS_X509_FMT_PEM, &chain, &max_certs)) < 0) {
                        debug_print("chain import failed: %s\n", gnutls_strerror(r));
-                       fclose(fp);
+                       claws_fclose(fp);
                        g_free(chain_file);
                        return (guint)-1;
                }
                g_free(chain_file);
-               fclose(fp);
+               claws_fclose(fp);
                fp = NULL;
 
                gnutls_x509_crt_get_fingerprint(chain[0], GNUTLS_DIG_MD5, md, &n);
@@ -670,7 +670,7 @@ static void ssl_certificate_save_chain(gnutls_x509_crt_t *certs, gint len, const
 
                        g_free(buf);
 
-                       fp = g_fopen(file, "wb");
+                       fp = claws_fopen(file, "wb");
                        if (fp == NULL) {
                                g_free(file);
                                debug_print("Can't save certificate !\n");
@@ -683,7 +683,7 @@ static void ssl_certificate_save_chain(gnutls_x509_crt_t *certs, gint len, const
 
        }
        if (fp)
-               safe_fclose(fp);
+               claws_safe_fclose(fp);
 }
 
 gboolean ssl_certificate_check (gnutls_x509_crt_t x509_cert, guint status, 
@@ -816,12 +816,12 @@ gboolean ssl_certificate_check_chain(gnutls_x509_crt_t *certs, gint chain_len,
        gint status;
 
        if (claws_ssl_get_cert_file()) {
-               FILE *fp = g_fopen(claws_ssl_get_cert_file(), "rb");
+               FILE *fp = claws_fopen(claws_ssl_get_cert_file(), "rb");
                int r = -errno;
 
                if (fp) {
                        r = gnutls_import_X509_list_fp(fp, GNUTLS_X509_FMT_PEM, &cas, &ncas);
-                       fclose(fp);
+                       claws_fclose(fp);
                }
 
                if (r < 0)
@@ -861,10 +861,10 @@ gnutls_x509_crt_t ssl_certificate_get_x509_from_pem_file(const gchar *file)
                return NULL;
        
        if (is_file_exist(file)) {
-               FILE *fp = g_fopen(file, "r");
+               FILE *fp = claws_fopen(file, "r");
                if (fp) {
                        x509 = gnutls_import_X509_fp(fp, GNUTLS_X509_FMT_PEM);
-                       fclose(fp);
+                       claws_fclose(fp);
                        return x509;
                } else {
                        log_error(LOG_PROTOCOL, _("Cannot open certificate file %s: %s\n"),
@@ -884,10 +884,10 @@ gnutls_x509_privkey_t ssl_certificate_get_pkey_from_pem_file(const gchar *file)
                return NULL;
        
        if (is_file_exist(file)) {
-               FILE *fp = g_fopen(file, "r");
+               FILE *fp = claws_fopen(file, "r");
                if (fp) {
                        key = gnutls_import_key_fp(fp, GNUTLS_X509_FMT_PEM);
-                       fclose(fp);
+                       claws_fclose(fp);
                        return key;
                } else {
                        log_error(LOG_PROTOCOL, _("Cannot open key file %s (%s)\n"),
@@ -1037,10 +1037,10 @@ void ssl_certificate_get_x509_and_pkey_from_p12_file(const gchar *file, const gc
                return;
 
        if (is_file_exist(file)) {
-               FILE *fp = g_fopen(file, "r");
+               FILE *fp = claws_fopen(file, "r");
                if (fp) {
                        p12 = gnutls_import_PKCS12_fp(fp, GNUTLS_X509_FMT_DER);
-                       fclose(fp);
+                       claws_fclose(fp);
                        if (!p12) {
                                log_error(LOG_PROTOCOL, _("Failed to read P12 certificate file %s\n"), file);
                        }
index 264f139..4086323 100644 (file)
@@ -53,7 +53,7 @@ void tags_read_tags(void)
                        TAGS_RC, NULL);
        gchar tmp[255];
        gint id;
-       FILE *fp = g_fopen(file, "rb");
+       FILE *fp = claws_fopen(file, "rb");
        
        g_free(file);
 
@@ -69,10 +69,10 @@ void tags_read_tags(void)
        if (!fp) 
                return;
        if (fscanf(fp, "max_id %d\n", &tag_max_id) != 1) {
-               fclose(fp);
+               claws_fclose(fp);
                return;
        }
-       while (fgets(tmp, sizeof(tmp), fp) != NULL) {
+       while (claws_fgets(tmp, sizeof(tmp), fp) != NULL) {
                gchar *sep = strchr(tmp, '\t');
                gchar *tag_name = sep?(sep+1):NULL;
                
@@ -89,7 +89,7 @@ void tags_read_tags(void)
                }
        }
        
-       fclose(fp);
+       claws_fclose(fp);
 }
 
 typedef struct _TagWriteData
@@ -121,10 +121,10 @@ void tags_write_tags(void)
                        TAGS_RC, NULL);
        TagWriteData data;
 
-       FILE *fp = g_fopen(file, "wb");
+       FILE *fp = claws_fopen(file, "wb");
                        
        if (!fp) {
-               FILE_OP_ERROR(file, "g_fopen");
+               FILE_OP_ERROR(file, "claws_fopen");
                g_free(file);
                g_free(file_new);
                return;
@@ -141,14 +141,14 @@ void tags_write_tags(void)
        }
 
        if (data.error) {
-               fclose(fp);
+               claws_fclose(fp);
                g_free(file);
                g_free(file_new);
                return;
        }
        
-       if (safe_fclose(fp) == EOF) {
-               FILE_OP_ERROR(file, "fclose");
+       if (claws_safe_fclose(fp) == EOF) {
+               FILE_OP_ERROR(file, "claws_fclose");
                g_free(file);
                g_free(file_new);
                return;
index e8db301..8ae5fde 100644 (file)
@@ -40,8 +40,8 @@ static Template *template_load(gchar *filename)
        gchar buf[BUFFSIZE];
        gint bytes_read;
 
-       if ((fp = g_fopen(filename, "rb")) == NULL) {
-               FILE_OP_ERROR(filename, "fopen");
+       if ((fp = claws_fopen(filename, "rb")) == NULL) {
+               FILE_OP_ERROR(filename, "claws_fopen");
                return NULL;
        }
 
@@ -56,7 +56,7 @@ static Template *template_load(gchar *filename)
        tmpl->replyto = NULL;
        tmpl->value = NULL;
 
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                if (buf[0] == '\n')
                        break;
                else if (!g_ascii_strncasecmp(buf, "Name:", 5))
@@ -78,19 +78,19 @@ static Template *template_load(gchar *filename)
        if (!tmpl->name) {
                g_warning("wrong template format");
                template_free(tmpl);
-               fclose(fp);
+               claws_fclose(fp);
                return NULL;
        }
 
-       if ((bytes_read = fread(buf, 1, sizeof(buf), fp)) == 0) {
-               if (ferror(fp)) {
-                       FILE_OP_ERROR(filename, "fread");
+       if ((bytes_read = claws_fread(buf, 1, sizeof(buf), fp)) == 0) {
+               if (claws_ferror(fp)) {
+                       FILE_OP_ERROR(filename, "claws_fread");
                        template_free(tmpl);
-                       fclose(fp);
+                       claws_fclose(fp);
                        return NULL;
                }
        }
-       fclose(fp);
+       claws_fclose(fp);
        tmpl->value = g_strndup(buf, bytes_read);
 
        return tmpl;
@@ -203,7 +203,7 @@ GSList *template_read_config(void)
 if (!(func)) \
 { \
        g_warning("Failed to write template to file"); \
-       if (fp) fclose(fp); \
+       if (fp) claws_fclose(fp); \
        if (new) claws_unlink(new); \
        g_free(new); \
        g_free(filename); \
@@ -256,8 +256,8 @@ static void template_write_config(GSList *tmpl_list)
                        new = g_strconcat(filename, ".new", NULL);
                }
 
-               if ((fp = g_fopen(new?new:filename, "wb")) == NULL) {
-                       FILE_OP_ERROR(new?new:filename, "fopen");
+               if ((fp = claws_fopen(new?new:filename, "wb")) == NULL) {
+                       FILE_OP_ERROR(new?new:filename, "claws_fopen");
                        g_free(new);
                        g_free(filename);
                        return;
@@ -277,14 +277,14 @@ static void template_write_config(GSList *tmpl_list)
                if (tmpl->replyto && *tmpl->replyto != '\0')
                        TRY(fprintf(fp, "Reply-To: %s\n", tmpl->replyto) > 0);
 
-               TRY(fputs("\n", fp) != EOF);
+               TRY(claws_fputs("\n", fp) != EOF);
 
                if (tmpl->value && *tmpl->value != '\0') {
-                       TRY(fwrite(tmpl->value, sizeof(gchar), strlen(tmpl->value), fp) == strlen(tmpl->value));
+                       TRY(claws_fwrite(tmpl->value, sizeof(gchar), strlen(tmpl->value), fp) == strlen(tmpl->value));
                } else {
-                       TRY(fwrite("", sizeof(gchar), 1, fp) == 1);
+                       TRY(claws_fwrite("", sizeof(gchar), 1, fp) == 1);
                }
-               TRY_NO_CLOSE(safe_fclose(fp) != EOF);
+               TRY_NO_CLOSE(claws_safe_fclose(fp) != EOF);
 
                if (new) {
                        if (rename_force(new, filename) < 0) {
index 977eda4..aaae7b2 100644 (file)
@@ -322,27 +322,27 @@ gint file_strip_crs(const gchar *file)
        if (file == NULL)
                goto freeout;
 
-       fp = g_fopen(file, "rb");
+       fp = claws_fopen(file, "rb");
        if (!fp)
                goto freeout;
 
-       outfp = g_fopen(out, "wb");
+       outfp = claws_fopen(out, "wb");
        if (!outfp) {
-               fclose(fp);
+               claws_fclose(fp);
                goto freeout;
        }
 
-       while (fgets(buf, sizeof (buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof (buf), fp) != NULL) {
                strcrchomp(buf);
-               if (fputs(buf, outfp) == EOF) {
-                       fclose(fp);
-                       fclose(outfp);
+               if (claws_fputs(buf, outfp) == EOF) {
+                       claws_fclose(fp);
+                       claws_fclose(outfp);
                        goto unlinkout;
                }
        }
 
-       fclose(fp);
-       if (safe_fclose(outfp) == EOF) {
+       claws_fclose(fp);
+       if (claws_safe_fclose(outfp) == EOF) {
                goto unlinkout;
        }
        
@@ -2419,14 +2419,14 @@ gint append_file(const gchar *src, const gchar *dest, gboolean keep_backup)
 
        gboolean err = FALSE;
 
-       if ((src_fp = g_fopen(src, "rb")) == NULL) {
-               FILE_OP_ERROR(src, "g_fopen");
+       if ((src_fp = claws_fopen(src, "rb")) == NULL) {
+               FILE_OP_ERROR(src, "claws_fopen");
                return -1;
        }
 
-       if ((dest_fp = g_fopen(dest, "ab")) == NULL) {
-               FILE_OP_ERROR(dest, "g_fopen");
-               fclose(src_fp);
+       if ((dest_fp = claws_fopen(dest, "ab")) == NULL) {
+               FILE_OP_ERROR(dest, "claws_fopen");
+               claws_fclose(src_fp);
                return -1;
        }
 
@@ -2435,25 +2435,25 @@ gint append_file(const gchar *src, const gchar *dest, gboolean keep_backup)
                g_warning("can't change file mode: %s", dest);
        }
 
-       while ((n_read = fread(buf, sizeof(gchar), sizeof(buf), src_fp)) > 0) {
-               if (n_read < sizeof(buf) && ferror(src_fp))
+       while ((n_read = claws_fread(buf, sizeof(gchar), sizeof(buf), src_fp)) > 0) {
+               if (n_read < sizeof(buf) && claws_ferror(src_fp))
                        break;
-               if (fwrite(buf, 1, n_read, dest_fp) < n_read) {
+               if (claws_fwrite(buf, 1, n_read, dest_fp) < n_read) {
                        g_warning("writing to %s failed.", dest);
-                       fclose(dest_fp);
-                       fclose(src_fp);
+                       claws_fclose(dest_fp);
+                       claws_fclose(src_fp);
                        claws_unlink(dest);
                        return -1;
                }
        }
 
-       if (ferror(src_fp)) {
-               FILE_OP_ERROR(src, "fread");
+       if (claws_ferror(src_fp)) {
+               FILE_OP_ERROR(src, "claws_fread");
                err = TRUE;
        }
-       fclose(src_fp);
-       if (fclose(dest_fp) == EOF) {
-               FILE_OP_ERROR(dest, "fclose");
+       claws_fclose(src_fp);
+       if (claws_fclose(dest_fp) == EOF) {
+               FILE_OP_ERROR(dest, "claws_fclose");
                err = TRUE;
        }
 
@@ -2473,23 +2473,23 @@ gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup)
        gchar *dest_bak = NULL;
        gboolean err = FALSE;
 
-       if ((src_fp = g_fopen(src, "rb")) == NULL) {
-               FILE_OP_ERROR(src, "g_fopen");
+       if ((src_fp = claws_fopen(src, "rb")) == NULL) {
+               FILE_OP_ERROR(src, "claws_fopen");
                return -1;
        }
        if (is_file_exist(dest)) {
                dest_bak = g_strconcat(dest, ".bak", NULL);
                if (rename_force(dest, dest_bak) < 0) {
                        FILE_OP_ERROR(dest, "rename");
-                       fclose(src_fp);
+                       claws_fclose(src_fp);
                        g_free(dest_bak);
                        return -1;
                }
        }
 
-       if ((dest_fp = g_fopen(dest, "wb")) == NULL) {
-               FILE_OP_ERROR(dest, "g_fopen");
-               fclose(src_fp);
+       if ((dest_fp = claws_fopen(dest, "wb")) == NULL) {
+               FILE_OP_ERROR(dest, "claws_fopen");
+               claws_fclose(src_fp);
                if (dest_bak) {
                        if (rename_force(dest_bak, dest) < 0)
                                FILE_OP_ERROR(dest_bak, "rename");
@@ -2503,13 +2503,13 @@ gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup)
                g_warning("can't change file mode: %s", dest);
        }
 
-       while ((n_read = fread(buf, sizeof(gchar), sizeof(buf), src_fp)) > 0) {
-               if (n_read < sizeof(buf) && ferror(src_fp))
+       while ((n_read = claws_fread(buf, sizeof(gchar), sizeof(buf), src_fp)) > 0) {
+               if (n_read < sizeof(buf) && claws_ferror(src_fp))
                        break;
-               if (fwrite(buf, 1, n_read, dest_fp) < n_read) {
+               if (claws_fwrite(buf, 1, n_read, dest_fp) < n_read) {
                        g_warning("writing to %s failed.", dest);
-                       fclose(dest_fp);
-                       fclose(src_fp);
+                       claws_fclose(dest_fp);
+                       claws_fclose(src_fp);
                        claws_unlink(dest);
                        if (dest_bak) {
                                if (rename_force(dest_bak, dest) < 0)
@@ -2520,13 +2520,13 @@ gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup)
                }
        }
 
-       if (ferror(src_fp)) {
-               FILE_OP_ERROR(src, "fread");
+       if (claws_ferror(src_fp)) {
+               FILE_OP_ERROR(src, "claws_fread");
                err = TRUE;
        }
-       fclose(src_fp);
-       if (safe_fclose(dest_fp) == EOF) {
-               FILE_OP_ERROR(dest, "fclose");
+       claws_fclose(src_fp);
+       if (claws_safe_fclose(dest_fp) == EOF) {
+               FILE_OP_ERROR(dest, "claws_fclose");
                err = TRUE;
        }
 
@@ -2583,10 +2583,10 @@ gint copy_file_part_to_fp(FILE *fp, off_t offset, size_t length, FILE *dest_fp)
        bytes_left = length;
        to_read = MIN(bytes_left, sizeof(buf));
 
-       while ((n_read = fread(buf, sizeof(gchar), to_read, fp)) > 0) {
-               if (n_read < to_read && ferror(fp))
+       while ((n_read = claws_fread(buf, sizeof(gchar), to_read, fp)) > 0) {
+               if (n_read < to_read && claws_ferror(fp))
                        break;
-               if (fwrite(buf, 1, n_read, dest_fp) < n_read) {
+               if (claws_fwrite(buf, 1, n_read, dest_fp) < n_read) {
                        return -1;
                }
                bytes_left -= n_read;
@@ -2595,8 +2595,8 @@ gint copy_file_part_to_fp(FILE *fp, off_t offset, size_t length, FILE *dest_fp)
                to_read = MIN(bytes_left, sizeof(buf));
        }
 
-       if (ferror(fp)) {
-               perror("fread");
+       if (claws_ferror(fp)) {
+               perror("claws_fread");
                return -1;
        }
 
@@ -2608,8 +2608,8 @@ gint copy_file_part(FILE *fp, off_t offset, size_t length, const gchar *dest)
        FILE *dest_fp;
        gboolean err = FALSE;
 
-       if ((dest_fp = g_fopen(dest, "wb")) == NULL) {
-               FILE_OP_ERROR(dest, "g_fopen");
+       if ((dest_fp = claws_fopen(dest, "wb")) == NULL) {
+               FILE_OP_ERROR(dest, "claws_fopen");
                return -1;
        }
 
@@ -2621,8 +2621,8 @@ gint copy_file_part(FILE *fp, off_t offset, size_t length, const gchar *dest)
        if (copy_file_part_to_fp(fp, offset, length, dest_fp) < 0)
                err = TRUE;
 
-       if (safe_fclose(dest_fp) == EOF) {
-               FILE_OP_ERROR(dest, "fclose");
+       if (claws_safe_fclose(dest_fp) == EOF) {
+               FILE_OP_ERROR(dest, "claws_fclose");
                err = TRUE;
        }
 
@@ -2682,14 +2682,14 @@ gint canonicalize_file(const gchar *src, const gchar *dest)
        if (src == NULL || dest == NULL)
                return -1;
 
-       if ((src_fp = g_fopen(src, "rb")) == NULL) {
-               FILE_OP_ERROR(src, "g_fopen");
+       if ((src_fp = claws_fopen(src, "rb")) == NULL) {
+               FILE_OP_ERROR(src, "claws_fopen");
                return -1;
        }
 
-       if ((dest_fp = g_fopen(dest, "wb")) == NULL) {
-               FILE_OP_ERROR(dest, "g_fopen");
-               fclose(src_fp);
+       if ((dest_fp = claws_fopen(dest, "wb")) == NULL) {
+               FILE_OP_ERROR(dest, "claws_fopen");
+               claws_fclose(src_fp);
                return -1;
        }
 
@@ -2698,7 +2698,7 @@ gint canonicalize_file(const gchar *src, const gchar *dest)
                g_warning("can't change file mode: %s", dest);
        }
 
-       while (fgets(buf, sizeof(buf), src_fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), src_fp) != NULL) {
                gint r = 0;
 
                len = strlen(buf);
@@ -2707,40 +2707,40 @@ gint canonicalize_file(const gchar *src, const gchar *dest)
 
                if (buf[len - 1] != '\n') {
                        last_linebreak = TRUE;
-                       r = fputs(buf, dest_fp);
+                       r = claws_fputs(buf, dest_fp);
                } else if (len > 1 && buf[len - 1] == '\n' && buf[len - 2] == '\r') {
-                       r = fputs(buf, dest_fp);
+                       r = claws_fputs(buf, dest_fp);
                } else {
                        if (len > 1) {
-                               r = fwrite(buf, 1, len - 1, dest_fp);
+                               r = claws_fwrite(buf, 1, len - 1, dest_fp);
                                if (r != (len -1))
                                        r = EOF;
                        }
                        if (r != EOF)
-                               r = fputs("\r\n", dest_fp);
+                               r = claws_fputs("\r\n", dest_fp);
                }
 
                if (r == EOF) {
                        g_warning("writing to %s failed.", dest);
-                       fclose(dest_fp);
-                       fclose(src_fp);
+                       claws_fclose(dest_fp);
+                       claws_fclose(src_fp);
                        claws_unlink(dest);
                        return -1;
                }
        }
 
        if (last_linebreak == TRUE) {
-               if (fputs("\r\n", dest_fp) == EOF)
+               if (claws_fputs("\r\n", dest_fp) == EOF)
                        err = TRUE;
        }
 
-       if (ferror(src_fp)) {
-               FILE_OP_ERROR(src, "fgets");
+       if (claws_ferror(src_fp)) {
+               FILE_OP_ERROR(src, "claws_fgets");
                err = TRUE;
        }
-       fclose(src_fp);
-       if (safe_fclose(dest_fp) == EOF) {
-               FILE_OP_ERROR(dest, "fclose");
+       claws_fclose(src_fp);
+       if (claws_safe_fclose(dest_fp) == EOF) {
+               FILE_OP_ERROR(dest, "claws_fclose");
                err = TRUE;
        }
 
@@ -2802,7 +2802,7 @@ gchar *get_outgoing_rfc2822_str(FILE *fp)
        str = g_string_new(NULL);
 
        /* output header part */
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                strretchomp(buf);
                if (!g_ascii_strncasecmp(buf, "Bcc:", 4)) {
                        gint next;
@@ -2815,7 +2815,7 @@ gchar *get_outgoing_rfc2822_str(FILE *fp)
                                        ungetc(next, fp);
                                        break;
                                }
-                               if (fgets(buf, sizeof(buf), fp) == NULL)
+                               if (claws_fgets(buf, sizeof(buf), fp) == NULL)
                                        break;
                        }
                } else {
@@ -2827,7 +2827,7 @@ gchar *get_outgoing_rfc2822_str(FILE *fp)
        }
 
        /* output body part */
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                strretchomp(buf);
                if (buf[0] == '.')
                        g_string_append_c(str, '.');
@@ -2926,7 +2926,7 @@ FILE *my_tmpfile(void)
        
 #endif
 
-       fp = fdopen(fd, "w+b");
+       fp = claws_fdopen(fd, "w+b");
        if (!fp)
                close(fd);
        else {
@@ -2944,7 +2944,7 @@ FILE *get_tmpfile_in_dir(const gchar *dir, gchar **filename)
        fd = g_mkstemp(*filename);
        if (fd < 0)
                return NULL;
-       return fdopen(fd, "w+");
+       return claws_fdopen(fd, "w+");
 }
 
 FILE *str_open_as_stream(const gchar *str)
@@ -2963,9 +2963,9 @@ FILE *str_open_as_stream(const gchar *str)
        len = strlen(str);
        if (len == 0) return fp;
 
-       if (fwrite(str, 1, len, fp) != len) {
-               FILE_OP_ERROR("str_open_as_stream", "fwrite");
-               fclose(fp);
+       if (claws_fwrite(str, 1, len, fp) != len) {
+               FILE_OP_ERROR("str_open_as_stream", "claws_fwrite");
+               claws_fclose(fp);
                return NULL;
        }
 
@@ -2981,26 +2981,26 @@ gint str_write_to_file(const gchar *str, const gchar *file)
        cm_return_val_if_fail(str != NULL, -1);
        cm_return_val_if_fail(file != NULL, -1);
 
-       if ((fp = g_fopen(file, "wb")) == NULL) {
-               FILE_OP_ERROR(file, "g_fopen");
+       if ((fp = claws_fopen(file, "wb")) == NULL) {
+               FILE_OP_ERROR(file, "claws_fopen");
                return -1;
        }
 
        len = strlen(str);
        if (len == 0) {
-               fclose(fp);
+               claws_fclose(fp);
                return 0;
        }
 
-       if (fwrite(str, 1, len, fp) != len) {
-               FILE_OP_ERROR(file, "fwrite");
-               fclose(fp);
+       if (claws_fwrite(str, 1, len, fp) != len) {
+               FILE_OP_ERROR(file, "claws_fwrite");
+               claws_fclose(fp);
                claws_unlink(file);
                return -1;
        }
 
-       if (safe_fclose(fp) == EOF) {
-               FILE_OP_ERROR(file, "fclose");
+       if (claws_safe_fclose(fp) == EOF) {
+               FILE_OP_ERROR(file, "claws_fclose");
                claws_unlink(file);
                return -1;
        }
@@ -3019,14 +3019,14 @@ static gchar *file_read_stream_to_str_full(FILE *fp, gboolean recode)
 
        array = g_byte_array_new();
 
-       while ((n_read = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
-               if (n_read < sizeof(buf) && ferror(fp))
+       while ((n_read = claws_fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
+               if (n_read < sizeof(buf) && claws_ferror(fp))
                        break;
                g_byte_array_append(array, buf, n_read);
        }
 
-       if (ferror(fp)) {
-               FILE_OP_ERROR("file stream", "fread");
+       if (claws_ferror(fp)) {
+               FILE_OP_ERROR("file stream", "claws_fread");
                g_byte_array_free(array, TRUE);
                return NULL;
        }
@@ -3073,7 +3073,7 @@ static gchar *file_read_to_str_full(const gchar *file, gboolean recode)
        }
 
 #ifdef G_OS_WIN32
-       fp = g_fopen (file, "rb");
+       fp = claws_fopen (file, "rb");
        if (fp == NULL) {
                FILE_OP_ERROR(file, "open");
                return NULL;
@@ -3114,18 +3114,18 @@ static gchar *file_read_to_str_full(const gchar *file, gboolean recode)
        }
        
        /* get the FILE pointer */
-       fp = fdopen(fd, "rb");
+       fp = claws_fdopen(fd, "rb");
 
        if (fp == NULL) {
-               FILE_OP_ERROR(file, "fdopen");
-               close(fd); /* if fp isn't NULL, we'll use fclose instead! */
+               FILE_OP_ERROR(file, "claws_fdopen");
+               close(fd); /* if fp isn't NULL, we'll use claws_fclose instead! */
                return NULL;
        }
 #endif
 
        str = file_read_stream_to_str_full(fp, recode);
 
-       fclose(fp);
+       claws_fclose(fp);
 
        return str;
 }
@@ -4429,12 +4429,12 @@ gchar *make_http_string(const gchar *bp, const gchar *ep)
 
 static gchar *mailcap_get_command_in_file(const gchar *path, const gchar *type, const gchar *file_to_open)
 {
-       FILE *fp = g_fopen(path, "rb");
+       FILE *fp = claws_fopen(path, "rb");
        gchar buf[BUFFSIZE];
        gchar *result = NULL;
        if (!fp)
                return NULL;
-       while (fgets(buf, sizeof (buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof (buf), fp) != NULL) {
                gchar **parts = g_strsplit(buf, ";", 3);
                gchar *trimmed = parts[0];
                while (trimmed[0] == ' ' || trimmed[0] == '\t')
@@ -4493,7 +4493,7 @@ static gchar *mailcap_get_command_in_file(const gchar *path, const gchar *type,
                                trimmed[strlen(trimmed)-1] = '\0';
                        result = g_strdup(trimmed);
                        g_strfreev(parts);
-                       fclose(fp);
+                       claws_fclose(fp);
                        if (needsterminal) {
                                gchar *tmp = g_strdup_printf("xterm -e %s", result);
                                g_free(result);
@@ -4503,7 +4503,7 @@ static gchar *mailcap_get_command_in_file(const gchar *path, const gchar *type,
                }
                g_strfreev(parts);
        }
-       fclose(fp);
+       claws_fclose(fp);
        return NULL;
 }
 gchar *mailcap_get_command_for_type(const gchar *type, const gchar *file_to_open)
@@ -4526,13 +4526,13 @@ void mailcap_update_default(const gchar *type, const gchar *command)
        gchar *path = NULL, *outpath = NULL;
        path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".mailcap", NULL);
        outpath = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".mailcap.new", NULL);
-       FILE *fp = g_fopen(path, "rb");
+       FILE *fp = claws_fopen(path, "rb");
        FILE *outfp = NULL;
        gchar buf[BUFFSIZE];
        gboolean err = FALSE;
 
        if (!fp) {
-               fp = g_fopen(path, "a");
+               fp = claws_fopen(path, "a");
                if (!fp) {
                        g_warning("failed to create file %s", path);
                        g_free(path);
@@ -4548,15 +4548,15 @@ void mailcap_update_default(const gchar *type, const gchar *command)
                }
        }
 
-       outfp = g_fopen(outpath, "wb");
+       outfp = claws_fopen(outpath, "wb");
        if (!outfp) {
                g_warning("failed to create file %s", outpath);
                g_free(path);
                g_free(outpath);
-               fclose(fp);
+               claws_fclose(fp);
                return;
        }
-       while (fp && fgets(buf, sizeof (buf), fp) != NULL) {
+       while (fp && claws_fgets(buf, sizeof (buf), fp) != NULL) {
                gchar **parts = g_strsplit(buf, ";", 3);
                gchar *trimmed = parts[0];
                while (trimmed[0] == ' ')
@@ -4569,7 +4569,7 @@ void mailcap_update_default(const gchar *type, const gchar *command)
                        continue;
                }
                else {
-                       if(fputs(buf, outfp) == EOF) {
+                       if(claws_fputs(buf, outfp) == EOF) {
                                err = TRUE;
                                break;
                        }
@@ -4580,9 +4580,9 @@ void mailcap_update_default(const gchar *type, const gchar *command)
                err = TRUE;
 
        if (fp)
-               fclose(fp);
+               claws_fclose(fp);
 
-       if (safe_fclose(outfp) == EOF)
+       if (claws_safe_fclose(outfp) == EOF)
                err = TRUE;
                
        if (!err)
@@ -4655,10 +4655,10 @@ gboolean file_is_email (const gchar *filename)
        gint score = 0;
        if (filename == NULL)
                return FALSE;
-       if ((fp = g_fopen(filename, "rb")) == NULL)
+       if ((fp = claws_fopen(filename, "rb")) == NULL)
                return FALSE;
        while (i < 60 && score < 3
-              && fgets(buffer, sizeof (buffer), fp) != NULL) {
+              && claws_fgets(buffer, sizeof (buffer), fp) != NULL) {
                if (!strncmp(buffer, "From:", strlen("From:")))
                        score++;
                else if (!strncmp(buffer, "Date:", strlen("Date:")))
@@ -4669,7 +4669,7 @@ gboolean file_is_email (const gchar *filename)
                        score++;
                i++;
        }
-       fclose(fp);
+       claws_fclose(fp);
        return (score >= 3);
 }
 
index 45fcd30..50cc9a5 100644 (file)
  * 
  */
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
+
 #include <glib.h>
 #include <stdio.h>
 #include <string.h>
@@ -25,6 +30,7 @@
 #include "xml.h"
 #include "utils.h"
 #include "codeconv.h"
+#include "claws_io.h"
 
 #define SPARSE_MEMORY
 /* if this is defined all attr.names and tag.names are stored
@@ -80,7 +86,7 @@ XMLFile *xml_open_file(const gchar *path)
 
        newfile = g_new(XMLFile, 1);
 
-       newfile->fp = g_fopen(path, "rb");
+       newfile->fp = claws_fopen(path, "rb");
        if (!newfile->fp) {
                g_free(newfile);
                return NULL;
@@ -97,6 +103,8 @@ XMLFile *xml_open_file(const gchar *path)
        newfile->level = 0;
        newfile->is_empty_element = FALSE;
 
+       newfile->path = g_strdup(path);
+
        return newfile;
 }
 
@@ -104,12 +112,13 @@ void xml_close_file(XMLFile *file)
 {
        cm_return_if_fail(file != NULL);
 
-       if (file->fp) fclose(file->fp);
+       if (file->fp) claws_fclose(file->fp);
 
        g_string_free(file->buf, TRUE);
 
        g_free(file->dtd);
        g_free(file->encoding);
+       g_free(file->path);
 
        while (file->tag_stack != NULL)
                xml_pop_tag(file);
@@ -126,7 +135,7 @@ static GNode *xml_build_tree(XMLFile *file, GNode *parent, guint level)
        while (xml_parse_next_tag(file) == 0) {
                if (file->level < level) break;
                if (file->level == level) {
-                       g_warning("xml_build_tree(): Parse error");
+                       g_warning("xml_build_tree(): Parse error in %s", file->path);
                        break;
                }
 
@@ -191,7 +200,7 @@ gint xml_get_dtd(XMLFile *file)
                        file->need_codeconv = FALSE;
                }
        } else {
-               g_warning("Can't get XML DTD");
+               g_warning("Can't get XML DTD in %s", file->path);
                return -1;
        }
 
@@ -214,7 +223,7 @@ next:
        }
 
        if (xml_get_parenthesis(file, buf, sizeof(buf)) < 0) {
-               g_warning("xml_parse_next_tag(): Can't parse next tag");
+               g_warning("xml_parse_next_tag(): Can't parse next tag  in %s", file->path);
                return -1;
        }
 
@@ -223,7 +232,7 @@ next:
        /* end-tag */
        if (buf[0] == '/') {
                if (strcmp(xml_get_current_tag(file)->tag, buf + 1) != 0) {
-                       g_warning("xml_parse_next_tag(): Tag name mismatch: %s (%s)", buf, xml_get_current_tag(file)->tag);
+                       g_warning("xml_parse_next_tag(): Tag name mismatch in %s : %s (%s)", file->path, buf, xml_get_current_tag(file)->tag);
                        return -1;
                }
                xml_pop_tag(file);
@@ -245,7 +254,7 @@ next:
        }
        
        if (strlen(buf) == 0) {
-               g_warning("xml_parse_next_tag(): Tag name is empty");
+               g_warning("xml_parse_next_tag(): Tag name is empty in %s", file->path);
                return -1;
        }
 
@@ -287,7 +296,7 @@ next:
                while (g_ascii_isspace(*bufp)) bufp++;
                attr_name = bufp;
                if ((p = strchr(attr_name, '=')) == NULL) {
-                       g_warning("xml_parse_next_tag(): Syntax error in tag (a) %s", attr_name);
+                       g_warning("xml_parse_next_tag(): Syntax error in %s, tag (a) %s", file->path, attr_name);
                        return -1;
                }
                bufp = p;
@@ -295,14 +304,14 @@ next:
                while (g_ascii_isspace(*bufp)) bufp++;
 
                if (*bufp != '"' && *bufp != '\'') {
-                       g_warning("xml_parse_next_tag(): Syntax error in tag (b) %s", bufp);
+                       g_warning("xml_parse_next_tag(): Syntax error in %s, tag (b) %s", file->path, bufp);
                        return -1;
                }
                quote = *bufp;
                bufp++;
                attr_value = bufp;
                if ((p = strchr(attr_value, quote)) == NULL) {
-                       g_warning("xml_parse_next_tag(): Syntax error in tag (c) %s", attr_value);
+                       g_warning("xml_parse_next_tag(): Syntax error in %s, tag (c) %s", file->path, attr_value);
                        return -1;
                }
                bufp = p;
@@ -414,7 +423,7 @@ static gint xml_read_line(XMLFile *file)
        gchar buf[XMLBUFSIZE];
        gint index;
 
-       if (fgets(buf, sizeof(buf), file->fp) == NULL)
+       if (claws_fgets(buf, sizeof(buf), file->fp) == NULL)
                return -1;
 
        index = file->bufp - file->buf->str;
@@ -581,22 +590,22 @@ gint xml_file_put_escape_str(FILE *fp, const gchar *str)
        for (p = str; *p != '\0'; p++) {
                switch (*p) {
                case '<':
-                       result = fputs("&lt;", fp);
+                       result = claws_fputs("&lt;", fp);
                        break;
                case '>':
-                       result = fputs("&gt;", fp);
+                       result = claws_fputs("&gt;", fp);
                        break;
                case '&':
-                       result = fputs("&amp;", fp);
+                       result = claws_fputs("&amp;", fp);
                        break;
                case '\'':
-                       result = fputs("&apos;", fp);
+                       result = claws_fputs("&apos;", fp);
                        break;
                case '\"':
-                       result = fputs("&quot;", fp);
+                       result = claws_fputs("&quot;", fp);
                        break;
                default:
-                       result = fputc(*p, fp);
+                       result = claws_fputc(*p, fp);
                }
        }
 
@@ -695,7 +704,7 @@ static int xml_write_tree_recursive(GNode *node, FILE *fp)
 
        depth = g_node_depth(node) - 1;
        for (i = 0; i < depth; i++)
-               TRY(fputs("    ", fp) != EOF);
+               TRY(claws_fputs("    ", fp) != EOF);
 
        tag = ((XMLNode *) node->data)->tag;
 
@@ -706,13 +715,13 @@ static int xml_write_tree_recursive(GNode *node, FILE *fp)
 
                TRY(fprintf(fp, " %s=\"", attr->name) > 0);
                TRY(xml_file_put_escape_str(fp, attr->value) == 0);
-               TRY(fputs("\"", fp) != EOF);
+               TRY(claws_fputs("\"", fp) != EOF);
                
        }
 
        if (node->children) {
                GNode *child;
-               TRY(fputs(">\n", fp) != EOF);
+               TRY(claws_fputs(">\n", fp) != EOF);
 
                child = node->children;
                while (child) {
@@ -724,10 +733,10 @@ static int xml_write_tree_recursive(GNode *node, FILE *fp)
                }
 
                for (i = 0; i < depth; i++)
-                       TRY(fputs("    ", fp) != EOF);
+                       TRY(claws_fputs("    ", fp) != EOF);
                TRY(fprintf(fp, "</%s>\n", tag->tag) > 0);
        } else
-               TRY(fputs(" />\n", fp) != EOF);
+               TRY(claws_fputs(" />\n", fp) != EOF);
        
        return 0;
 }
index 225a12e..6ca9059 100644 (file)
@@ -51,6 +51,7 @@ struct _XMLNode
 struct _XMLFile
 {
        FILE *fp;
+       gchar *path;
 
        GString *buf;
        gchar *bufp;
index 9aadc3b..1fc1c28 100644 (file)
  * ***********************************************************************
  */
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
 
 #include <glib.h>
 #include <stdio.h>
@@ -41,6 +45,7 @@
 #include "mgutils.h"
 #include "xmlprops.h"
 #include "utils.h"
+#include "claws_io.h"
 
 /* Element tag names */
 #define XMLS_ELTAG_PROP_LIST     "property-list"
@@ -126,12 +131,12 @@ void xmlprops_free( XmlProperty *props ) {
 static int xmlprops_write_elem_s( FILE *fp, gint lvl, gchar *name ) {
        gint i;
        for( i = 0; i < lvl; i++ ) {
-               if(fputs( "  ", fp ) == EOF)
+               if(claws_fputs( "  ", fp ) == EOF)
                        return -1;
        }
-       if(fputs( "<", fp ) == EOF)
+       if(claws_fputs( "<", fp ) == EOF)
                return -1;
-       if(fputs( name, fp ) == EOF)
+       if(claws_fputs( name, fp ) == EOF)
                return -1;
        
        return 0;
@@ -140,29 +145,29 @@ static int xmlprops_write_elem_s( FILE *fp, gint lvl, gchar *name ) {
 static int xmlprops_write_elem_e( FILE *fp, gint lvl, gchar *name ) {
        gint i;
        for( i = 0; i < lvl; i++ ) {
-               if(fputs( "  ", fp ) == EOF)
+               if(claws_fputs( "  ", fp ) == EOF)
                        return -1;
        }
-       if(fputs( "</", fp ) == EOF)
+       if(claws_fputs( "</", fp ) == EOF)
                return -1;
-       if(fputs( name, fp ) == EOF)
+       if(claws_fputs( name, fp ) == EOF)
                return -1;
-       if(fputs( ">\n", fp ) == EOF)
+       if(claws_fputs( ">\n", fp ) == EOF)
                return -1;
        
        return 0;
 }
 
 static int xmlprops_write_attr( FILE *fp, gchar *name, gchar *value ) {
-       if(fputs( " ", fp ) == EOF)
+       if(claws_fputs( " ", fp ) == EOF)
                return -1;
-       if(fputs( name, fp ) == EOF)
+       if(claws_fputs( name, fp ) == EOF)
                return -1;
-       if(fputs( "=\"", fp ) == EOF)
+       if(claws_fputs( "=\"", fp ) == EOF)
                return -1;
        if(xml_file_put_escape_str( fp, value ) < 0)
                return -1;
-       if(fputs( "\"", fp ) == EOF)
+       if(claws_fputs( "\"", fp ) == EOF)
                return -1;
        
        return 0;
@@ -177,7 +182,7 @@ static void xmlprops_write_vis( gpointer key, gpointer value, gpointer d ) {
                data->error = 1;
        if(xmlprops_write_attr( data->fp, XMLS_ATTAG_VALUE, value ) < 0)
                data->error = 1;
-       if(fputs( " />\n", data->fp ) == EOF)
+       if(claws_fputs( " />\n", data->fp ) == EOF)
                data->error = 1;
 }
 
@@ -200,7 +205,7 @@ static gint xmlprops_write_to( XmlProperty *props, const gchar *fileSpec ) {
                        goto revert;
                if(xmlprops_write_elem_s( fp, 0, XMLS_ELTAG_PROP_LIST ) < 0)
                        goto revert;
-               if(fputs( ">\n", fp ) == EOF)
+               if(claws_fputs( ">\n", fp ) == EOF)
                        goto revert;
 
                /* Output all properties */
index ade8db9..1344b2b 100644 (file)
@@ -2433,12 +2433,12 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
                gboolean prev_autowrap;
                GtkTextBuffer *buffer;
                BLOCK_WRAP();
-               while (fgets(buf, sizeof(buf), fp) != NULL) {
+               while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                        strcrchomp(buf);
                        gtk_text_buffer_insert(textbuf, &iter, buf, -1);
                }
                UNBLOCK_WRAP();
-               fclose(fp);
+               claws_fclose(fp);
        }
        
        compose_attach_parts(compose, msginfo);
@@ -2873,7 +2873,7 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
 
        if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
        procheader_get_header_fields(fp, hentry);
-       fclose(fp);
+       claws_fclose(fp);
 
        if (hentry[H_REPLY_TO].body != NULL) {
                if (hentry[H_REPLY_TO].body[0] != '\0') {
@@ -2998,7 +2998,7 @@ static gint compose_parse_manual_headers(Compose *compose, MsgInfo *msginfo, Hea
 
        if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
        procheader_get_header_fields(fp, entries);
-       fclose(fp);
+       claws_fclose(fp);
 
        he = entries;
        while (he != NULL && he->name != NULL) {
@@ -3672,8 +3672,8 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
        }
 
 
-       if ((fp = g_fopen(file, "rb")) == NULL) {
-               FILE_OP_ERROR(file, "fopen");
+       if ((fp = claws_fopen(file, "rb")) == NULL) {
+               FILE_OP_ERROR(file, "claws_fopen");
                return COMPOSE_INSERT_READ_ERROR;
        }
 
@@ -3692,7 +3692,7 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
        cur_encoding = conv_get_locale_charset_str_no_utf8();
 
        file_contents = g_string_new("");
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                gchar *str;
 
                if (g_utf8_validate(buf, -1, NULL) == TRUE)
@@ -3736,7 +3736,7 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
        }
 
        g_string_free(file_contents, TRUE);
-       fclose(fp);
+       claws_fclose(fp);
 
        return result;
 }
@@ -3788,11 +3788,11 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file,
                        return FALSE;
                }
        }
-       if ((fp = g_fopen(file, "rb")) == NULL) {
+       if ((fp = claws_fopen(file, "rb")) == NULL) {
                alertpanel_error(_("Can't read %s."), filename);
                return FALSE;
        }
-       fclose(fp);
+       claws_fclose(fp);
 
        ainfo = g_new0(AttachInfo, 1);
        auto_ainfo = g_auto_pointer_new_with_free
@@ -5532,7 +5532,7 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
                return -1;
 
        /* separator between header and body */
-       err |= (fputs("\n", fp) == EOF);
+       err |= (claws_fputs("\n", fp) == EOF);
 
        return (err ? -1:0);
 }
@@ -5565,8 +5565,8 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
                };
        gint ret = 0;
 
-       if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
-               FILE_OP_ERROR(compose->redirect_filename, "fopen");
+       if ((fp = claws_fopen(compose->redirect_filename, "rb")) == NULL) {
+               FILE_OP_ERROR(compose->redirect_filename, "claws_fopen");
                return -1;
        }
 
@@ -5584,7 +5584,7 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
                        buf = NULL;
                        continue;
                }
-               if (fputs(buf, fdest) == -1) {
+               if (claws_fputs(buf, fdest) == -1) {
                        g_free(buf);
                        buf = NULL;
                        goto error;
@@ -5593,7 +5593,7 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
                if (!prefs_common.redirect_keep_from) {
                        if (g_ascii_strncasecmp(buf, "From:",
                                          strlen("From:")) == 0) {
-                               err |= (fputs(" (by way of ", fdest) == EOF);
+                               err |= (claws_fputs(" (by way of ", fdest) == EOF);
                                if (compose->account->name
                                    && *compose->account->name) {
                                        gchar buffer[BUFFSIZE];
@@ -5609,13 +5609,13 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
                                } else
                                        err |= (fprintf(fdest, "%s",
                                                compose->account->address) < 0);
-                               err |= (fputs(")", fdest) == EOF);
+                               err |= (claws_fputs(")", fdest) == EOF);
                        }
                }
 
                g_free(buf);
                buf = NULL;
-               if (fputs("\n", fdest) == -1)
+               if (claws_fputs("\n", fdest) == -1)
                        goto error;
        }
 
@@ -5625,17 +5625,17 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
        if (compose_redirect_write_headers(compose, fdest))
                goto error;
 
-       while ((len = fread(rewrite_buf, sizeof(gchar), sizeof(rewrite_buf), fp)) > 0) {
-               if (fwrite(rewrite_buf, sizeof(gchar), len, fdest) != len)
+       while ((len = claws_fread(rewrite_buf, sizeof(gchar), sizeof(rewrite_buf), fp)) > 0) {
+               if (claws_fwrite(rewrite_buf, sizeof(gchar), len, fdest) != len)
                        goto error;
        }
 
-       fclose(fp);
+       claws_fclose(fp);
 
        return 0;
 
 error:
-       fclose(fp);
+       claws_fclose(fp);
 
        return -1;
 }
@@ -5897,7 +5897,7 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
                                debug_print("saving sent message unencrypted...\n");
                                FILE *tmpfp = get_tmpfile_in_dir(get_mime_tmp_dir(), &tmp_enc_file);
                                if (tmpfp) {
-                                       fclose(tmpfp);
+                                       claws_fclose(tmpfp);
 
                                        /* fp now points to a file with headers written,
                                         * let's make a copy. */
@@ -5908,9 +5908,9 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
                                        g_free(content);
 
                                        /* Now write the unencrypted body. */
-                                       if ((tmpfp = g_fopen(tmp_enc_file, "a")) != NULL) {
+                                       if ((tmpfp = claws_fopen(tmp_enc_file, "a")) != NULL) {
                                                procmime_write_mimeinfo(mimemsg, tmpfp);
-                                               fclose(tmpfp);
+                                               claws_fclose(tmpfp);
 
                                                outbox = folder_find_item_from_identifier(compose_get_save_to(compose));
                                                if (!outbox)
@@ -5948,8 +5948,8 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file)
        size_t len;
        gchar *chars, *tmp;
 
-       if ((fp = g_fopen(file, "wb")) == NULL) {
-               FILE_OP_ERROR(file, "fopen");
+       if ((fp = claws_fopen(file, "wb")) == NULL) {
+               FILE_OP_ERROR(file, "claws_fopen");
                return -1;
        }
 
@@ -5969,24 +5969,24 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file)
 
        g_free(tmp);
        if (!chars) {
-               fclose(fp);
+               claws_fclose(fp);
                claws_unlink(file);
                return -1;
        }
        /* write body */
        len = strlen(chars);
-       if (fwrite(chars, sizeof(gchar), len, fp) != len) {
-               FILE_OP_ERROR(file, "fwrite");
+       if (claws_fwrite(chars, sizeof(gchar), len, fp) != len) {
+               FILE_OP_ERROR(file, "claws_fwrite");
                g_free(chars);
-               fclose(fp);
+               claws_fclose(fp);
                claws_unlink(file);
                return -1;
        }
 
        g_free(chars);
 
-       if (safe_fclose(fp) == EOF) {
-               FILE_OP_ERROR(file, "fclose");
+       if (claws_safe_fclose(fp) == EOF) {
+               FILE_OP_ERROR(file, "claws_fclose");
                claws_unlink(file);
                return -1;
        }
@@ -6116,8 +6116,8 @@ static ComposeQueueResult compose_queue_sub(Compose *compose, gint *msgnum, Fold
        tmp = g_strdup_printf("%s%cqueue.%p%08x", get_tmp_dir(),
                              G_DIR_SEPARATOR, compose, (guint) rand());
        debug_print("queuing to %s\n", tmp);
-       if ((fp = g_fopen(tmp, "w+b")) == NULL) {
-               FILE_OP_ERROR(tmp, "fopen");
+       if ((fp = claws_fopen(tmp, "w+b")) == NULL) {
+               FILE_OP_ERROR(tmp, "claws_fopen");
                g_free(tmp);
                return COMPOSE_QUEUE_ERROR_WITH_ERRNO;
        }
@@ -6179,7 +6179,7 @@ static ComposeQueueResult compose_queue_sub(Compose *compose, gint *msgnum, Fold
                err |= (fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing) < 0);
                if (compose->use_encryption) {
                        if (!compose_warn_encryption(compose)) {
-                               fclose(fp);
+                               claws_fclose(fp);
                                claws_unlink(tmp);
                                g_free(tmp);
                                return COMPOSE_QUEUE_ERROR_NO_MSG;
@@ -6204,7 +6204,7 @@ static ComposeQueueResult compose_queue_sub(Compose *compose, gint *msgnum, Fold
                                 * key selection */
                                if (err == TRUE)
                                        g_warning("failed to write queue message");
-                               fclose(fp);
+                               claws_fclose(fp);
                                claws_unlink(tmp);
                                g_free(tmp);
                                return COMPOSE_QUEUE_ERROR_NO_ENCRYPTION_KEY;
@@ -6257,7 +6257,7 @@ static ComposeQueueResult compose_queue_sub(Compose *compose, gint *msgnum, Fold
 
        if (compose->redirect_filename != NULL) {
                if (compose_redirect_write_to_file(compose, fp) < 0) {
-                       fclose(fp);
+                       claws_fclose(fp);
                        claws_unlink(tmp);
                        g_free(tmp);
                        return COMPOSE_QUEUE_ERROR_WITH_ERRNO;
@@ -6265,7 +6265,7 @@ static ComposeQueueResult compose_queue_sub(Compose *compose, gint *msgnum, Fold
        } else {
                gint result = 0;
                if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND, TRUE)) < 0) {
-                       fclose(fp);
+                       claws_fclose(fp);
                        claws_unlink(tmp);
                        g_free(tmp);
                        return result;
@@ -6273,13 +6273,13 @@ static ComposeQueueResult compose_queue_sub(Compose *compose, gint *msgnum, Fold
        }
        if (err == TRUE) {
                g_warning("failed to write queue message");
-               fclose(fp);
+               claws_fclose(fp);
                claws_unlink(tmp);
                g_free(tmp);
                return COMPOSE_QUEUE_ERROR_WITH_ERRNO;
        }
-       if (safe_fclose(fp) == EOF) {
-               FILE_OP_ERROR(tmp, "fclose");
+       if (claws_safe_fclose(fp) == EOF) {
+               FILE_OP_ERROR(tmp, "claws_fclose");
                claws_unlink(tmp);
                g_free(tmp);
                return COMPOSE_QUEUE_ERROR_WITH_ERRNO;
@@ -7050,11 +7050,11 @@ void compose_add_extra_header_entries(GtkListStore *model)
 
        if (extra_headers == NULL) {
                exhrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "extraheaderrc", NULL);
-               if ((exh = g_fopen(exhrc, "rb")) == NULL) {
+               if ((exh = claws_fopen(exhrc, "rb")) == NULL) {
                        debug_print("extra headers file not found\n");
                        goto extra_headers_done;
                }
-               while (fgets(buf, BUFFSIZE, exh) != NULL) {
+               while (claws_fgets(buf, BUFFSIZE, exh) != NULL) {
                        lastc = strlen(buf) - 1;        /* remove trailing control chars */
                        while (lastc >= 0 && buf[lastc] != ':')
                                buf[lastc--] = '\0';
@@ -7072,7 +7072,7 @@ void compose_add_extra_header_entries(GtkListStore *model)
                                        g_message("invalid extra header line: %s\n", buf);
                        }
                }
-               fclose(exh);
+               claws_fclose(exh);
 extra_headers_done:
                g_free(exhrc);
                extra_headers = g_slist_prepend(extra_headers, g_strdup("")); /* end of list */
@@ -10260,12 +10260,12 @@ static void compose_register_draft(MsgInfo *info)
 {
        gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                      DRAFTED_AT_EXIT, NULL);
-       FILE *fp = g_fopen(filepath, "ab");
+       FILE *fp = claws_fopen(filepath, "ab");
        
        if (fp) {
                fprintf(fp, "%s\t%d\n", folder_item_get_identifier(info->folder), 
                                info->msgnum);
-               fclose(fp);
+               claws_fclose(fp);
        }
                
        g_free(filepath);       
@@ -10306,8 +10306,8 @@ gboolean compose_draft (gpointer data, guint action)
 
        tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
                              G_DIR_SEPARATOR, compose);
-       if ((fp = g_fopen(tmp, "wb")) == NULL) {
-               FILE_OP_ERROR(tmp, "fopen");
+       if ((fp = claws_fopen(tmp, "wb")) == NULL) {
+               FILE_OP_ERROR(tmp, "claws_fopen");
                goto warn_err;
        }
 
@@ -10373,15 +10373,15 @@ gboolean compose_draft (gpointer data, guint action)
        err |= (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0);
 
        if (err) {
-               fclose(fp);
+               claws_fclose(fp);
                goto warn_err;
        }
 
        if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE, action != COMPOSE_AUTO_SAVE) < 0) {
-               fclose(fp);
+               claws_fclose(fp);
                goto warn_err;
        }
-       if (safe_fclose(fp) == EOF) {
+       if (claws_safe_fclose(fp) == EOF) {
                goto warn_err;
        }
        
@@ -10551,11 +10551,11 @@ void compose_reopen_exit_drafts(void)
 {
        gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                      DRAFTED_AT_EXIT, NULL);
-       FILE *fp = g_fopen(filepath, "rb");
+       FILE *fp = claws_fopen(filepath, "rb");
        gchar buf[1024];
        
        if (fp) {
-               while (fgets(buf, sizeof(buf), fp)) {
+               while (claws_fgets(buf, sizeof(buf), fp)) {
                        gchar **parts = g_strsplit(buf, "\t", 2);
                        const gchar *folder = parts[0];
                        int msgnum = parts[1] ? atoi(parts[1]):-1;
@@ -10568,7 +10568,7 @@ void compose_reopen_exit_drafts(void)
                        }
                        g_strfreev(parts);
                }       
-               fclose(fp);
+               claws_fclose(fp);
        }       
        g_free(filepath);
        compose_clear_exit_drafts();
index e149047..b8b0eb3 100644 (file)
  * 
  */
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
+
 #include <glib.h>
 #include <stdio.h>
 #include <string.h>
@@ -24,6 +29,7 @@
 
 #include "enriched.h"
 #include "utils.h"
+#include "claws_io.h"
 
 #define ERTFBUFSIZE    8192
 
@@ -114,7 +120,7 @@ static ERTFState ertf_read_line(ERTFParser *parser)
        gchar buf2[ERTFBUFSIZE];
        gint index;
 
-       if (fgets(buf, sizeof(buf), parser->fp) == NULL) {
+       if (claws_fgets(buf, sizeof(buf), parser->fp) == NULL) {
                parser->state = ERTF_EOF;
                return ERTF_EOF;
        }
index 48823e1..4a11f4f 100644 (file)
@@ -2626,27 +2626,27 @@ static void fetch_content_run(struct etpan_thread_op * op)
                        goto free;
                }
                
-               f = fdopen(fd, "wb");
+               f = claws_fdopen(fd, "wb");
                if (f == NULL) {
                        result->error = MAILIMAP_ERROR_FETCH;
                        goto close;
                }
                
-               r = fwrite(content, 1, content_size, f);
+               r = claws_fwrite(content, 1, content_size, f);
                if (r < content_size) {
                        result->error = MAILIMAP_ERROR_FETCH;
-                       goto fclose;
+                       goto do_fclose;
                }
                
-               r = safe_fclose(f);
+               r = claws_safe_fclose(f);
                if (r == EOF) {
                        result->error = MAILIMAP_ERROR_FETCH;
                        goto unlink;
                }
                goto free;
                
-       fclose:
-               fclose(f);
+       do_fclose:
+               claws_fclose(f);
                goto unlink;
        close:
                close(fd);
index d0bfefd..5dbec5b 100644 (file)
@@ -256,12 +256,12 @@ void exporthtml_set_attributes( ExportHtmlCtl *ctl, const gboolean value ) {
 static gint exporthtml_create_css_dfl( const gchar *fileSpec ) {
        FILE *cssFile;
 
-       cssFile = g_fopen( fileSpec, "rb" );
+       cssFile = claws_fopen( fileSpec, "rb" );
        if( cssFile ) {
-               fclose( cssFile );
+               claws_fclose( cssFile );
                return MGU_SUCCESS;
        }
-       cssFile = g_fopen( fileSpec, "wb" );
+       cssFile = claws_fopen( fileSpec, "wb" );
        if( ! cssFile ) {
                return MGU_OPEN_FILE;
        }
@@ -302,7 +302,7 @@ static gint exporthtml_create_css_dfl( const gchar *fileSpec ) {
        fprintf( cssFile, ".tab-attr {\n" );
        fprintf( cssFile, "}\n" );
 
-       safe_fclose( cssFile );
+       claws_safe_fclose( cssFile );
        return MGU_SUCCESS;
 }
 
@@ -314,12 +314,12 @@ static gint exporthtml_create_css_dfl( const gchar *fileSpec ) {
 static gint exporthtml_create_css_full( const gchar *fileSpec ) {
        FILE *cssFile;
 
-       cssFile = g_fopen( fileSpec, "rb" );
+       cssFile = claws_fopen( fileSpec, "rb" );
        if( cssFile ) {
-               fclose( cssFile );
+               claws_fclose( cssFile );
                return MGU_SUCCESS;
        }
-       cssFile = g_fopen( fileSpec, "wb" );
+       cssFile = claws_fopen( fileSpec, "wb" );
        if( ! cssFile ) {
                return MGU_OPEN_FILE;
        }
@@ -366,7 +366,7 @@ static gint exporthtml_create_css_full( const gchar *fileSpec ) {
        fprintf( cssFile, ".tab-attr {\n" );
        fprintf( cssFile, "}\n" );
 
-       safe_fclose( cssFile );
+       claws_safe_fclose( cssFile );
        return MGU_SUCCESS;
 }
 
@@ -964,7 +964,7 @@ void exporthtml_process(
        static gchar *title;
        gchar buf[512];
 
-       htmlFile = g_fopen( ctl->path, "wb" );
+       htmlFile = claws_fopen( ctl->path, "wb" );
        if( ! htmlFile ) {
                /* Cannot open file */
                g_print( "Cannot open file for write\n" );
@@ -995,7 +995,7 @@ void exporthtml_process(
        fprintf( htmlFile, "</body>\n" );
        fprintf( htmlFile, "</html>\n" );
 
-       safe_fclose( htmlFile );
+       claws_safe_fclose( htmlFile );
        ctl->retVal = MGU_SUCCESS;
 
        /* Create stylesheet files */
index ded6a3e..54e6bd0 100644 (file)
@@ -533,7 +533,7 @@ void exportldif_process( ExportLdifCtl *ctl, AddressCache *cache )
        ItemFolder *rootFolder;
        FILE *ldifFile;
 
-       ldifFile = g_fopen( ctl->path, "wb" );
+       ldifFile = claws_fopen( ctl->path, "wb" );
        if( ! ldifFile ) {
                /* Cannot open file */
                ctl->retVal = MGU_OPEN_FILE;
@@ -542,7 +542,7 @@ void exportldif_process( ExportLdifCtl *ctl, AddressCache *cache )
 
        rootFolder = cache->rootFolder;
        exportldif_fmt_folder( ctl, ldifFile, rootFolder );
-       safe_fclose( ldifFile );
+       claws_safe_fclose( ldifFile );
        ctl->retVal = MGU_SUCCESS;
 }
 
index 503a049..97c5d01 100644 (file)
@@ -63,6 +63,7 @@
 #include "privacy.h"
 #include "prefs_common.h"
 #include "prefs_migration.h"
+#include "claws_io.h"
 
 /* Dependecies to be removed ?! */
 #include "prefs_account.h"
@@ -2990,12 +2991,12 @@ static gint folder_item_get_msg_num_by_file(FolderItem *dest, const gchar *file)
        gint msgnum = 0;
        gchar buf[BUFFSIZE];
 
-       if ((fp = g_fopen(file, "rb")) == NULL)
+       if ((fp = claws_fopen(file, "rb")) == NULL)
                return 0;
 
        if ((folder_has_parent_of_type(dest, F_QUEUE)) || 
            (folder_has_parent_of_type(dest, F_DRAFT)))
-               while (fgets(buf, sizeof(buf), fp) != NULL) {
+               while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                        /* new way */
                        if ((!strncmp(buf, "X-Claws-End-Special-Headers: 1",
                                strlen("X-Claws-End-Special-Headers:"))) ||
@@ -3029,7 +3030,7 @@ static gint folder_item_get_msg_num_by_file(FolderItem *dest, const gchar *file)
        
        g_free(hentry[0].body);
        hentry[0].body = NULL;
-       fclose(fp);
+       claws_fclose(fp);
 
        return msgnum;
 }
index f5893e1..b86de3a 100644 (file)
@@ -43,6 +43,7 @@
 #include "menu.h"
 #include "textview.h"
 #include "main.h"
+#include "claws_io.h"
 
 extern SessionStats session_stats;
 static GtkTextBuffer *stats_text_buffer;
@@ -638,14 +639,14 @@ static GtkWidget *about_create_child_page_release_notes(void)
        gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
 
        path = g_strconcat(DOCDIR, G_DIR_SEPARATOR_S, RELEASE_NOTES_FILE, NULL);
-       if ((fp = g_fopen(path, "rb")) == NULL) {
-               if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
+       if ((fp = claws_fopen(path, "rb")) == NULL) {
+               if (ENOENT != errno) FILE_OP_ERROR(path, "claws_fopen");
                g_free(path);
                return scrolledwin;
        }
        g_free(path);
 
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                const gchar *src_codeset = conv_get_locale_charset_str();
                const gchar *dest_codeset = CS_UTF_8;
                gchar *tmp;
@@ -659,7 +660,7 @@ static GtkWidget *about_create_child_page_release_notes(void)
                gtk_text_buffer_insert(buffer, &iter, tmp, -1);
                g_free(tmp);
        }
-       fclose(fp);
+       claws_fclose(fp);
 
        return scrolledwin;
 }
index da8625e..190b467 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
+
 #include <glib.h>
 #include <stdio.h>
 #include <string.h>
@@ -25,6 +30,7 @@
 #include "codeconv.h"
 #include "utils.h"
 #include "entity.h"
+#include "claws_io.h"
 
 #define SC_HTMLBUFSIZE 8192
 #define HR_STR         "────────────────────────────────────────────────"
@@ -136,7 +142,7 @@ static SC_HTMLState sc_html_read_line(SC_HTMLParser *parser)
        if (parser->fp == NULL)
                return SC_HTML_EOF;
 
-       n = fread(buf, 1, sizeof(buf) - 1, parser->fp);
+       n = claws_fread(buf, 1, sizeof(buf) - 1, parser->fp);
        if (n == 0) {
                parser->state = SC_HTML_EOF;
                return SC_HTML_EOF;
index 4982b61..5871b79 100644 (file)
@@ -71,6 +71,7 @@
 #include "tags.h"
 #include "main.h"
 #include "passwordstore.h"
+#include "claws_io.h"
 
 typedef struct _IMAPFolder     IMAPFolder;
 typedef struct _IMAPSession    IMAPSession;
@@ -1377,17 +1378,17 @@ static guint get_file_size_with_crs(const gchar *filename)
        if (filename == NULL)
                return -1;
        
-       fp = g_fopen(filename, "rb");
+       fp = claws_fopen(filename, "rb");
        if (!fp)
                return -1;
        
-       while (fgets(buf, sizeof (buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof (buf), fp) != NULL) {
                cnt += strlen(buf);
                if (!strstr(buf, "\r\n") && strstr(buf, "\n"))
                        cnt++;
        }
        
-       fclose(fp);
+       claws_fclose(fp);
        return cnt;
 }
 
index fc3927c..a29b02b 100644 (file)
@@ -56,6 +56,7 @@
 #include "codeconv.h"
 #include "adbookbase.h"
 #include "utils.h"
+#include "claws_io.h"
 
 #define JPILOT_DBHOME_DIR   ".jpilot"
 #define JPILOT_DBHOME_FILE  "AddressDB.pdb"
@@ -538,10 +539,10 @@ static int jpilot_get_info_size( FILE *in, int *size ) {
        int r;
 
        fseek(in, 0, SEEK_SET);
-       r = fread(&rdbh, sizeof(RawDBHeader), 1, in);
+       r = claws_fread(&rdbh, sizeof(RawDBHeader), 1, in);
        if (r < 1)
                return MGU_ERROR_READ;
-       if (feof(in)) {
+       if (claws_feof(in)) {
                return MGU_EOF;
        }
 
@@ -560,7 +561,7 @@ static int jpilot_get_info_size( FILE *in, int *size ) {
                return MGU_SUCCESS;
        }
 
-       r = fread(&rh, sizeof(record_header), 1, in);
+       r = claws_fread(&rh, sizeof(record_header), 1, in);
        if (r < 1)
                return MGU_ERROR_READ;
 
@@ -589,7 +590,7 @@ static gint jpilot_get_file_info( JPilotFile *pilotFile, unsigned char **buf, in
        *buf_size=0;
 
        if( pilotFile->path ) {
-               in = g_fopen( pilotFile->path, "rb" );
+               in = claws_fopen( pilotFile->path, "rb" );
                if( !in ) {
                        return MGU_OPEN_FILE;
                }
@@ -598,15 +599,15 @@ static gint jpilot_get_file_info( JPilotFile *pilotFile, unsigned char **buf, in
                return MGU_NO_FILE;
        }
 
-       num = fread( &rdbh, sizeof( RawDBHeader ), 1, in );
+       num = claws_fread( &rdbh, sizeof( RawDBHeader ), 1, in );
        if( num != 1 ) {
-               if( ferror(in) ) {
-                       fclose(in);
+               if( claws_ferror(in) ) {
+                       claws_fclose(in);
                        return MGU_ERROR_READ;
                }
        }
-       if (feof(in)) {
-               fclose(in);
+       if (claws_feof(in)) {
+               claws_fclose(in);
                return MGU_EOF;
        }
 
@@ -615,28 +616,28 @@ static gint jpilot_get_file_info( JPilotFile *pilotFile, unsigned char **buf, in
 
        num = jpilot_get_info_size(in, &rec_size);
        if (num) {
-               fclose(in);
+               claws_fclose(in);
                return MGU_ERROR_READ;
        }
 
        if (fseek(in, dbh.app_info_offset, SEEK_SET) < 0) {
-               fclose(in);
+               claws_fclose(in);
                return MGU_ERROR_READ;
        }
        *buf = ( char * ) malloc(rec_size);
        if (!(*buf)) {
-               fclose(in);
+               claws_fclose(in);
                return MGU_OO_MEMORY;
        }
-       num = fread(*buf, rec_size, 1, in);
+       num = claws_fread(*buf, rec_size, 1, in);
        if (num != 1) {
-               if (ferror(in)) {
-                       fclose(in);
+               if (claws_ferror(in)) {
+                       claws_fclose(in);
                        free(*buf);
                        return MGU_ERROR_READ;
                }
        }
-       fclose(in);
+       claws_fclose(in);
 
        *buf_size = rec_size;
 
@@ -685,8 +686,8 @@ static int read_header(FILE *pc_in, PC3RecordHeader *header) {
 
        memset(header, 0, sizeof(PC3RecordHeader));
 
-       num = fread(&l, sizeof(l), 1, pc_in);
-       if (feof(pc_in)) {
+       num = claws_fread(&l, sizeof(l), 1, pc_in);
+       if (claws_feof(pc_in)) {
                return -1;
        }
        if (num!=1) {
@@ -697,8 +698,8 @@ static int read_header(FILE *pc_in, PC3RecordHeader *header) {
        if (len > 255 || len < sizeof(l)) {
                return -1;
        }
-       num = fread(packed_header+sizeof(l), len-sizeof(l), 1, pc_in);
-       if (feof(pc_in)) {
+       num = claws_fread(packed_header+sizeof(l), len-sizeof(l), 1, pc_in);
+       if (claws_feof(pc_in)) {
                return -1;
        }
        if (num!=1) {
@@ -722,14 +723,14 @@ static gint jpilot_read_next_pc( FILE *in, buf_rec *br ) {
        int rec_len, num;
        char *record;
 
-       if( feof( in ) ) {
+       if( claws_feof( in ) ) {
                return MGU_EOF;
        }
        num = read_header( in, &header );
        if( num < 1 ) {
-               if( ferror( in ) )
+               if( claws_ferror( in ) )
                        return MGU_ERROR_READ;
-               else if( feof( in ) )
+               else if( claws_feof( in ) )
                        return MGU_EOF;
                else
                        return -1;
@@ -739,9 +740,9 @@ static gint jpilot_read_next_pc( FILE *in, buf_rec *br ) {
        if( ! record ) {
                return MGU_OO_MEMORY;
        }
-       num = fread( record, rec_len, 1, in );
+       num = claws_fread( record, rec_len, 1, in );
        if( num != 1 ) {
-               if( ferror( in ) ) {
+               if( claws_ferror( in ) ) {
                        free( record );
                        return MGU_ERROR_READ;
                }
@@ -789,20 +790,20 @@ static gint jpilot_read_db_files( JPilotFile *pilotFile, GList **records ) {
                return MGU_BAD_ARGS;
        }
 
-       in = g_fopen( pilotFile->path, "rb" );
+       in = claws_fopen( pilotFile->path, "rb" );
        if (!in) {
                return MGU_OPEN_FILE;
        }
 
        /* Read the database header */
-       num = fread( &rdbh, sizeof( RawDBHeader ), 1, in );
+       num = claws_fread( &rdbh, sizeof( RawDBHeader ), 1, in );
        if( num != 1 ) {
-               if( ferror( in ) ) {
-                       fclose( in );
+               if( claws_ferror( in ) ) {
+                       claws_fclose( in );
                        return MGU_ERROR_READ;
                }
-               if( feof( in ) ) {
-                       fclose( in );
+               if( claws_feof( in ) ) {
+                       claws_fclose( in );
                        return MGU_EOF;
                }
        }
@@ -814,13 +815,13 @@ static gint jpilot_read_db_files( JPilotFile *pilotFile, GList **records ) {
        prev_offset = 0;
 
        for( i = 1; i < num_records + 1; i++ ) {
-               num = fread( &rh, sizeof( record_header ), 1, in );
+               num = claws_fread( &rh, sizeof( record_header ), 1, in );
                if( num != 1 ) {
-                       if( ferror( in ) ) {
+                       if( claws_ferror( in ) ) {
                                break;
                        }
-                       if( feof( in ) ) {
-                               fclose( in );
+                       if( claws_feof( in ) ) {
+                               claws_fclose( in );
                                if (mem_rh)
                                        free_mem_rec_header( &mem_rh );
                                return MGU_EOF;
@@ -872,10 +873,10 @@ static gint jpilot_read_db_files( JPilotFile *pilotFile, GList **records ) {
                }
                if (fseek( in, next_offset, SEEK_SET ) < 0) {
                        free_mem_rec_header( &mem_rh );
-                       fclose(in);
+                       claws_fclose(in);
                        return MGU_ERROR_READ;
                }
-               while( ! feof( in ) ) {
+               while( ! claws_feof( in ) ) {
                        fpos = ftell( in );
                        if( out_of_order ) {
                                find_next_offset(
@@ -895,9 +896,9 @@ static gint jpilot_read_db_files( JPilotFile *pilotFile, GList **records ) {
                        rec_size = next_offset - fpos;
                        buf = malloc( rec_size );
                        if( ! buf ) break;
-                       num = fread( buf, rec_size, 1, in );
+                       num = claws_fread( buf, rec_size, 1, in );
                        if( ( num != 1 ) ) {
-                               if( ferror( in ) ) {
+                               if( claws_ferror( in ) ) {
                                        free( buf );
                                        break;
                                }
@@ -919,20 +920,20 @@ static gint jpilot_read_db_files( JPilotFile *pilotFile, GList **records ) {
                        recs_returned++;
                }
        }
-       fclose( in );
+       claws_fclose( in );
        free_mem_rec_header( &mem_rh );
 
        /* Read the PC3 file, if present */
        pcFile = jpilot_get_pc3_file( pilotFile );
        if( pcFile == NULL ) return MGU_SUCCESS;
-       pc_in = g_fopen( pcFile, "rb");
+       pc_in = claws_fopen( pcFile, "rb");
        g_free( pcFile );
 
        if( pc_in == NULL ) {
                return MGU_SUCCESS;
        }
 
-       while( ! feof( pc_in ) ) {
+       while( ! claws_feof( pc_in ) ) {
                gboolean linked;
 
                temp_br = malloc( sizeof( buf_rec ) );
@@ -982,7 +983,7 @@ static gint jpilot_read_db_files( JPilotFile *pilotFile, GList **records ) {
                        free( temp_br );
                }
        }
-       fclose( pc_in );
+       claws_fclose( pc_in );
 
        return MGU_SUCCESS;
 }
@@ -1616,8 +1617,8 @@ gchar *jpilot_find_pilotdb( void ) {
        strncat( str, JPILOT_DBHOME_FILE, WORK_BUFLEN - strlen(str) );
 
        /* Attempt to open */
-       if( ( fp = g_fopen( str, "rb" ) ) != NULL ) {
-               fclose( fp );
+       if( ( fp = claws_fopen( str, "rb" ) ) != NULL ) {
+               claws_fclose( fp );
        }
        else {
                /* Truncate filename */
index 5b0750a..16a20d7 100644 (file)
@@ -424,10 +424,10 @@ static GSList *ldapqry_add_single_value( LDAP *ld, LDAPMessage *entry, char *att
                                list = g_slist_append( list, g_strndup( vals[0]->bv_val, vals[0]->bv_len ));
                        } else {
                                char *file = get_tmp_file();
-                               FILE *fp = g_fopen(file, "wb");
+                               FILE *fp = claws_fopen(file, "wb");
                                if (fp) {
-                                       fwrite(vals[0]->bv_val, 1, vals[0]->bv_len, fp);
-                                       safe_fclose(fp);
+                                       claws_fwrite(vals[0]->bv_val, 1, vals[0]->bv_len, fp);
+                                       claws_safe_fclose(fp);
                                }
                                list = g_slist_append( list, file);
                        }
index 93ce800..a632123 100644 (file)
@@ -32,6 +32,7 @@
 #include "addrcache.h"
 
 #include "utils.h"
+#include "claws_io.h"
 
 #define        LDIF_SEP_TAG    ':'
 #define        LDIF_LANG_TAG   ';'
@@ -176,7 +177,7 @@ void ldif_free( LdifFile *ldifFile ) {
        cm_return_if_fail( ldifFile != NULL );
 
        /* Close file */
-       if( ldifFile->file ) fclose( ldifFile->file );
+       if( ldifFile->file ) claws_fclose( ldifFile->file );
 
        /* Free internal stuff */
        g_free( ldifFile->path );
@@ -207,7 +208,7 @@ void ldif_free( LdifFile *ldifFile ) {
 static gint ldif_open_file( LdifFile* ldifFile ) {
        /* g_print( "Opening file\n" ); */
        if( ldifFile->path ) {
-               ldifFile->file = g_fopen( ldifFile->path, "rb" );
+               ldifFile->file = claws_fopen( ldifFile->path, "rb" );
                if( ! ldifFile->file ) {
                        /* g_print( "can't open %s\n", ldifFile->path ); */
                        ldifFile->retVal = MGU_OPEN_FILE;
@@ -231,7 +232,7 @@ static gint ldif_open_file( LdifFile* ldifFile ) {
  */
 static void ldif_close_file( LdifFile *ldifFile ) {
        cm_return_if_fail( ldifFile != NULL );
-       if( ldifFile->file ) fclose( ldifFile->file );
+       if( ldifFile->file ) claws_fclose( ldifFile->file );
        ldifFile->file = NULL;
 }
 
@@ -246,14 +247,14 @@ static gchar *ldif_get_line( LdifFile *ldifFile ) {
        int i = 0;
        int cur_alloc = LDIFBUFSIZE;
 
-       if( feof( ldifFile->file ) ) {
+       if( claws_feof( ldifFile->file ) ) {
                g_free(buf);
                return NULL;
        }
 
        while( i < cur_alloc-1 ) {
                ch = fgetc( ldifFile->file );
-               if (ferror( ldifFile->file ))
+               if (claws_ferror( ldifFile->file ))
                        ldifFile->retVal = MGU_ERROR_READ;
                if( ch == '\0' || ch == EOF ) {
                        if( i == 0 ) return NULL;
index 0bfee71..631e366 100644 (file)
@@ -443,12 +443,12 @@ static int migrate_common_rc(const gchar *old_rc, const gchar *new_rc)
        gchar buf[BUFFSIZE];
        gboolean err = FALSE;
 
-       oldfp = g_fopen(old_rc, "r");
+       oldfp = claws_fopen(old_rc, "r");
        if (!oldfp)
                return -1;
-       newfp = g_fopen(new_rc, "w");
+       newfp = claws_fopen(new_rc, "w");
        if (!newfp) {
-               fclose(oldfp);
+               claws_fclose(oldfp);
                return -1;
        }
        
@@ -464,21 +464,21 @@ static int migrate_common_rc(const gchar *old_rc, const gchar *new_rc)
                old_plugin_path = g_strdup(new_plugin_path);
        }
        debug_print("replacing %s with %s\n", old_plugin_path, new_plugin_path);
-       while (fgets(buf, sizeof(buf), oldfp)) {
+       while (claws_fgets(buf, sizeof(buf), oldfp)) {
                if (strncmp(buf, old_plugin_path, strlen(old_plugin_path))) {
-                       err |= (fputs(buf, newfp) == EOF);
+                       err |= (claws_fputs(buf, newfp) == EOF);
                } else {
                        debug_print("->replacing %s\n", buf);
                        debug_print("  with %s%s\n", new_plugin_path, buf+strlen(old_plugin_path));
-                       err |= (fputs(new_plugin_path, newfp) == EOF);
-                       err |= (fputs(buf+strlen(old_plugin_path), newfp) == EOF);
+                       err |= (claws_fputs(new_plugin_path, newfp) == EOF);
+                       err |= (claws_fputs(buf+strlen(old_plugin_path), newfp) == EOF);
                }
        }
        g_free(plugin_path);
        g_free(new_plugin_path);
        g_free(old_plugin_path);
-       fclose(oldfp);
-       if (safe_fclose(newfp) == EOF)
+       claws_fclose(oldfp);
+       if (claws_safe_fclose(newfp) == EOF)
                err = TRUE;
        
        return (err ? -1:0);
@@ -738,7 +738,7 @@ static void win32_open_log(void)
                if (rename_force(logfile, oldlogfile) < 0)
                        FILE_OP_ERROR(logfile, "rename");
        }
-       win32_debug_fp = g_fopen(logfile, "w");
+       win32_debug_fp = claws_fopen(logfile, "w");
        g_free(logfile);
        g_free(oldlogfile);
        if (win32_debug_fp)
@@ -761,7 +761,7 @@ static void win32_close_log(void)
                g_log_remove_handler("", win32_log_handler_app_id);
                g_log_remove_handler("GLib", win32_log_handler_glib_id);
                g_log_remove_handler("Gtk", win32_log_handler_gtk_id);
-               fclose(win32_debug_fp);
+               claws_fclose(win32_debug_fp);
                win32_debug_fp=NULL;
        }
 }              
@@ -1788,12 +1788,12 @@ static GString * parse_cmd_compose_from_file(const gchar *fn)
        if (isstdin)
                fp = stdin;
        else {
-               fp = g_fopen(fn, "r");
+               fp = claws_fopen(fn, "r");
                if (!fp)
                        G_PRINT_EXIT(_("Cannot open filename for reading\n"));
        }
 
-       while (fgets(fb, sizeof(fb), fp)) {
+       while (claws_fgets(fb, sizeof(fb), fp)) {
                gchar *tmp;     
                strretchomp(fb);
                if (*fb == '\0')
@@ -1823,11 +1823,11 @@ static GString * parse_cmd_compose_from_file(const gchar *fn)
        g_string_append(body, to);
        g_free(to);
        g_string_append(body, "?body=");
-       while (fgets(fb, sizeof(fb), fp)) {
+       while (claws_fgets(fb, sizeof(fb), fp)) {
                g_string_append_uri_escaped(body, fb, NULL, TRUE);
        }
        if (!isstdin)
-               fclose(fp);
+               claws_fclose(fp);
        /* append the remaining headers */
        g_string_append(body, headers->str);
        g_string_free(headers, TRUE);
@@ -2415,7 +2415,7 @@ static gint prohibit_duplicate_launch(void)
                        fd_gets(uxsock, buf, sizeof(buf) - 1);
                        buf[sizeof(buf) - 1] = '\0';
                        if (!strncmp(buf, ".\n", 2)) break;
-                       fputs(buf, stdout);
+                       claws_fputs(buf, stdout);
                }
        } else if (cmd.exit) {
                fd_write_all(uxsock, "exit\n", 5);
@@ -2426,7 +2426,7 @@ static gint prohibit_duplicate_launch(void)
                        fd_gets(uxsock, buf, sizeof(buf) - 1);
                        buf[sizeof(buf) - 1] = '\0';
                        if (!strncmp(buf, ".\n", 2)) break;
-                       fputs(buf, stdout);
+                       claws_fputs(buf, stdout);
                }
        } else if (cmd.reset_statistics) {
                fd_write(uxsock, "reset_statistics\n", 17);
@@ -2446,7 +2446,7 @@ static gint prohibit_duplicate_launch(void)
                        fd_gets(uxsock, buf, sizeof(buf) - 1);
                        buf[sizeof(buf) - 1] = '\0';
                        if (!strncmp(buf, ".\n", 2)) break;
-                       fputs(buf, stdout);
+                       claws_fputs(buf, stdout);
                }
        } else {
 #ifndef G_OS_WIN32
index 5b67051..c87c897 100644 (file)
@@ -49,6 +49,7 @@
 #include "tags.h"
 #include "folder_item_prefs.h"
 #include "procmsg.h"
+#include "claws_io.h"
 
 /*!
  *\brief       Keyword lookup element
@@ -1623,7 +1624,7 @@ static gboolean matcherlist_match_binary_content(MatcherList *matchers, MimeInfo
        if (!outfp)
                return FALSE;
 
-       while (fgets(buf, sizeof(buf), outfp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), outfp) != NULL) {
                strretchomp(buf);
 
                for (l = matchers->matchers ; l != NULL ; l = g_slist_next(l)) {
@@ -1664,14 +1665,14 @@ static gboolean matcherlist_match_binary_content(MatcherList *matchers, MimeInfo
                         * no need to check the others. */
                        if (matcher->result && matcher->done) {
                                if (!matchers->bool_and) {
-                                       fclose(outfp);
+                                       claws_fclose(outfp);
                                        return TRUE;
                                }
                        }
                }
        }
 
-       fclose(outfp);
+       claws_fclose(outfp);
        return FALSE;
 }
 
@@ -1823,8 +1824,8 @@ static gboolean matcherlist_match_file(MatcherList *matchers, MsgInfo *info,
        if (file == NULL)
                return FALSE;
 
-       if ((fp = g_fopen(file, "rb")) == NULL) {
-               FILE_OP_ERROR(file, "fopen");
+       if ((fp = claws_fopen(file, "rb")) == NULL) {
+               FILE_OP_ERROR(file, "claws_fopen");
                g_free(file);
                return result;
        }
@@ -1866,7 +1867,7 @@ static gboolean matcherlist_match_file(MatcherList *matchers, MsgInfo *info,
 
        g_free(file);
 
-       fclose(fp);
+       claws_fclose(fp);
        
        return result;
 }
@@ -2429,42 +2430,42 @@ static int prefs_filtering_write(FILE *fp, GSList *prefs_filtering)
                        continue;
 
                if (prop->enabled) {
-                       if (fputs("enabled ", fp) == EOF) {
-                               FILE_OP_ERROR("filtering config", "fputs");
+                       if (claws_fputs("enabled ", fp) == EOF) {
+                               FILE_OP_ERROR("filtering config", "claws_fputs");
                                return -1;
                        }
                } else {
-                       if (fputs("disabled ", fp) == EOF) {
-                               FILE_OP_ERROR("filtering config", "fputs");
+                       if (claws_fputs("disabled ", fp) == EOF) {
+                               FILE_OP_ERROR("filtering config", "claws_fputs");
                                return -1;
                        }
                }
 
-               if (fputs("rulename \"", fp) == EOF) {
-                       FILE_OP_ERROR("filtering config", "fputs");
+               if (claws_fputs("rulename \"", fp) == EOF) {
+                       FILE_OP_ERROR("filtering config", "claws_fputs");
                        g_free(filtering_str);
                        return -1;
                }
                tmp_name = prop->name;
                while (tmp_name && *tmp_name != '\0') {
                        if (*tmp_name != '"') {
-                               if (fputc(*tmp_name, fp) == EOF) {
-                                       FILE_OP_ERROR("filtering config", "fputs || fputc");
+                               if (claws_fputc(*tmp_name, fp) == EOF) {
+                                       FILE_OP_ERROR("filtering config", "claws_fputs || claws_fputc");
                                        g_free(filtering_str);
                                        return -1;
                                }
                        } else if (*tmp_name == '"') {
-                               if (fputc('\\', fp) == EOF ||
-                                   fputc('"', fp) == EOF) {
-                                       FILE_OP_ERROR("filtering config", "fputs || fputc");
+                               if (claws_fputc('\\', fp) == EOF ||
+                                   claws_fputc('"', fp) == EOF) {
+                                       FILE_OP_ERROR("filtering config", "claws_fputs || claws_fputc");
                                        g_free(filtering_str);
                                        return -1;
                                }
                        }
                        tmp_name ++;
                }
-               if (fputs("\" ", fp) == EOF) {
-                       FILE_OP_ERROR("filtering config", "fputs");
+               if (claws_fputs("\" ", fp) == EOF) {
+                       FILE_OP_ERROR("filtering config", "claws_fputs");
                        g_free(filtering_str);
                        return -1;
                }
@@ -2473,17 +2474,17 @@ static int prefs_filtering_write(FILE *fp, GSList *prefs_filtering)
                        gchar *tmp = NULL;
 
                        tmp = g_strdup_printf("account %d ", prop->account_id);
-                       if (fputs(tmp, fp) == EOF) {
-                               FILE_OP_ERROR("filtering config", "fputs");
+                       if (claws_fputs(tmp, fp) == EOF) {
+                               FILE_OP_ERROR("filtering config", "claws_fputs");
                                g_free(tmp);
                                return -1;
                        }
                        g_free(tmp);
                }
 
-               if(fputs(filtering_str, fp) == EOF ||
-                   fputc('\n', fp) == EOF) {
-                       FILE_OP_ERROR("filtering config", "fputs || fputc");
+               if(claws_fputs(filtering_str, fp) == EOF ||
+                   claws_fputc('\n', fp) == EOF) {
+                       FILE_OP_ERROR("filtering config", "claws_fputs || claws_fputc");
                        g_free(filtering_str);
                        return -1;
                }
@@ -2531,7 +2532,7 @@ static gboolean prefs_matcher_write_func(GNode *node, gpointer d)
                        data->error = TRUE;
                        goto fail;
                }
-               if (fputc('\n', data->fp) == EOF) {
+               if (claws_fputc('\n', data->fp) == EOF) {
                        data->error = TRUE;
                        goto fail;
                }
@@ -2569,19 +2570,19 @@ static int prefs_matcher_save(FILE *fp)
         /* pre global rules */
         if (fprintf(fp, "[preglobal]\n") < 0 ||
             prefs_filtering_write(fp, pre_global_processing) < 0 ||
-            fputc('\n', fp) == EOF)
+            claws_fputc('\n', fp) == EOF)
                return -1;
 
         /* post global rules */
         if (fprintf(fp, "[postglobal]\n") < 0 ||
             prefs_filtering_write(fp, post_global_processing) < 0 ||
-            fputc('\n', fp) == EOF)
+            claws_fputc('\n', fp) == EOF)
                return -1;
         
         /* filtering rules */
        if (fprintf(fp, "[filtering]\n") < 0 ||
             prefs_filtering_write(fp, filtering_rules) < 0 ||
-            fputc('\n', fp) == EOF)
+            claws_fputc('\n', fp) == EOF)
                return -1;
 
        return 0;
@@ -2629,11 +2630,11 @@ void prefs_matcher_read_config(void)
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MATCHER_RC, NULL);
 
-       f = g_fopen(rcpath, "rb");
+       f = claws_fopen(rcpath, "rb");
        g_free(rcpath);
 
        if (f != NULL) {
                matcher_parser_start_parsing(f);
-               fclose(matcher_parserin);
+               claws_fclose(matcher_parserin);
        }
 }
index 68b3d01..2f7db0d 100644 (file)
@@ -23,7 +23,6 @@
 #endif
 
 
-#define _GNU_SOURCE
 #include <stdio.h>
 
 #ifdef USE_PTHREAD
 
 #define MESSAGEBUFSIZE 8192
 
-#ifdef HAVE_FGETS_UNLOCKED
-#define SC_FGETS fgets_unlocked
-#define SC_FPUTS fputs_unlocked
-#define SC_FPUTC fputc_unlocked
-#else
-#define SC_FGETS fgets
-#define SC_FPUTS fputs
-#define SC_FPUTC fputc
-#endif
-
 #define FPUTS_TO_TMP_ABORT_IF_FAIL(s) \
 { \
        lines++; \
-       if (fputs(s, tmp_fp) == EOF) { \
+       if (claws_fputs(s, tmp_fp) == EOF) { \
                g_warning("can't write to temporary file"); \
-               fclose(tmp_fp); \
-               fclose(mbox_fp); \
+               claws_fclose(tmp_fp); \
+               claws_fclose(mbox_fp); \
                claws_unlink(tmp_file); \
                g_free(tmp_file); \
                return -1; \
@@ -103,24 +92,24 @@ 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 = g_fopen(mbox, "rb")) == NULL) {
-               FILE_OP_ERROR(mbox, "fopen");
+       if ((mbox_fp = claws_fopen(mbox, "rb")) == NULL) {
+               FILE_OP_ERROR(mbox, "claws_fopen");
                alertpanel_error(_("Could not open mbox file:\n%s\n"), mbox);
                return -1;
        }
 
        /* ignore empty lines on the head */
        do {
-               if (fgets(buf, sizeof(buf), mbox_fp) == NULL) {
+               if (claws_fgets(buf, sizeof(buf), mbox_fp) == NULL) {
                        g_warning("can't read mbox file.");
-                       fclose(mbox_fp);
+                       claws_fclose(mbox_fp);
                        return -1;
                }
        } while (buf[0] == '\n' || buf[0] == '\r');
 
        if (strncmp(buf, "From ", 5) != 0) {
                g_warning("invalid mbox format: %s", mbox);
-               fclose(mbox_fp);
+               claws_fclose(mbox_fp);
                return -1;
        }
 
@@ -148,10 +137,10 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, gboolean apply_filter,
                        GTK_EVENTS_FLUSH();
                }
        
-               if ((tmp_fp = g_fopen(tmp_file, "wb")) == NULL) {
-                       FILE_OP_ERROR(tmp_file, "fopen");
+               if ((tmp_fp = claws_fopen(tmp_file, "wb")) == NULL) {
+                       FILE_OP_ERROR(tmp_file, "claws_fopen");
                        g_warning("can't open temporary file");
-                       fclose(mbox_fp);
+                       claws_fclose(mbox_fp);
                        g_free(tmp_file);
                        return -1;
                }
@@ -163,7 +152,7 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, gboolean apply_filter,
                lines = 0;
 
                /* process all lines from mboxrc file */
-               while (fgets(buf, sizeof(buf), mbox_fp) != NULL) {
+               while (claws_fgets(buf, sizeof(buf), mbox_fp) != NULL) {
                        int offset;
 
                        /* eat empty lines */
@@ -219,22 +208,22 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, gboolean apply_filter,
                }
 
                /* more emails to expect? */
-               more = !feof(mbox_fp);
+               more = !claws_feof(mbox_fp);
 
                /* warn if email part is empty (it's the minimum check 
                   we can do */
                if (lines == 0) {
                        g_warning("malformed mbox: %s: message %d is empty", mbox, msgs);
-                       fclose(tmp_fp);
-                       fclose(mbox_fp);
+                       claws_fclose(tmp_fp);
+                       claws_fclose(mbox_fp);
                        claws_unlink(tmp_file);
                        return -1;
                }
 
-               if (safe_fclose(tmp_fp) == EOF) {
-                       FILE_OP_ERROR(tmp_file, "fclose");
+               if (claws_safe_fclose(tmp_fp) == EOF) {
+                       FILE_OP_ERROR(tmp_file, "claws_fclose");
                        g_warning("can't write to temporary file");
-                       fclose(mbox_fp);
+                       claws_fclose(mbox_fp);
                        claws_unlink(tmp_file);
                        g_free(tmp_file);
                        return -1;
@@ -242,7 +231,7 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, gboolean apply_filter,
 
                if (apply_filter) {
                        if ((msgnum = folder_item_add_msg(dropfolder, tmp_file, NULL, TRUE)) < 0) {
-                               fclose(mbox_fp);
+                               claws_fclose(mbox_fp);
                                claws_unlink(tmp_file);
                                g_free(tmp_file);
                                return -1;
@@ -303,7 +292,7 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, gboolean apply_filter,
        folder_item_update_thaw();
        
        g_free(tmp_file);
-       fclose(mbox_fp);
+       claws_fclose(mbox_fp);
        debug_print("%d messages found.\n", msgs);
 
        return msgs;
@@ -320,8 +309,8 @@ gint lock_mbox(const gchar *base, LockType type)
                FILE *lockfp;
 
                lockfile = g_strdup_printf("%s.%d", base, getpid());
-               if ((lockfp = g_fopen(lockfile, "wb")) == NULL) {
-                       FILE_OP_ERROR(lockfile, "fopen");
+               if ((lockfp = claws_fopen(lockfile, "wb")) == NULL) {
+                       FILE_OP_ERROR(lockfile, "claws_fopen");
                        g_warning("can't create lock file '%s', use 'flock' instead of 'file' if possible.", lockfile);
                        g_free(lockfile);
                        return -1;
@@ -330,12 +319,12 @@ gint lock_mbox(const gchar *base, LockType type)
                if (fprintf(lockfp, "%d\n", getpid()) < 0) {
                        FILE_OP_ERROR(lockfile, "fprintf");
                        g_free(lockfile);
-                       fclose(lockfp);
+                       claws_fclose(lockfp);
                        return -1;
                }
 
-               if (safe_fclose(lockfp) == EOF) {
-                       FILE_OP_ERROR(lockfile, "fclose");
+               if (claws_safe_fclose(lockfp) == EOF) {
+                       FILE_OP_ERROR(lockfile, "claws_fclose");
                        g_free(lockfile);
                        return -1;
                }
@@ -485,8 +474,8 @@ gint copy_mbox(gint srcfd, const gchar *dest)
                return -1;
        }
 
-       if ((dest_fp = g_fopen(dest, "wb")) == NULL) {
-               FILE_OP_ERROR(dest, "fopen");
+       if ((dest_fp = claws_fopen(dest, "wb")) == NULL) {
+               FILE_OP_ERROR(dest, "claws_fopen");
                return -1;
        }
 
@@ -496,9 +485,9 @@ gint copy_mbox(gint srcfd, const gchar *dest)
        }
 
        while ((n_read = read(srcfd, buf, sizeof(buf))) > 0) {
-               if (fwrite(buf, 1, n_read, dest_fp) < n_read) {
+               if (claws_fwrite(buf, 1, n_read, dest_fp) < n_read) {
                        g_warning("writing to %s failed.", dest);
-                       fclose(dest_fp);
+                       claws_fclose(dest_fp);
                        claws_unlink(dest);
                        return -1;
                }
@@ -510,8 +499,8 @@ gint copy_mbox(gint srcfd, const gchar *dest)
                err = TRUE;
        }
 
-       if (safe_fclose(dest_fp) == EOF) {
-               FILE_OP_ERROR(dest, "fclose");
+       if (claws_safe_fclose(dest_fp) == EOF) {
+               FILE_OP_ERROR(dest, "claws_fclose");
                err = TRUE;
        }
 
@@ -527,12 +516,12 @@ void empty_mbox(const gchar *mbox)
 {
        FILE *fp;
 
-       if ((fp = g_fopen(mbox, "wb")) == NULL) {
-               FILE_OP_ERROR(mbox, "fopen");
+       if ((fp = claws_fopen(mbox, "wb")) == NULL) {
+               FILE_OP_ERROR(mbox, "claws_fopen");
                g_warning("can't truncate mailbox to zero.");
                return;
        }
-       safe_fclose(fp);
+       claws_safe_fclose(fp);
 }
 
 gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
@@ -556,16 +545,12 @@ gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
                }
        }
 
-       if ((mbox_fp = g_fopen(mbox, "wb")) == NULL) {
-               FILE_OP_ERROR(mbox, "fopen");
+       if ((mbox_fp = claws_fopen(mbox, "wb")) == NULL) {
+               FILE_OP_ERROR(mbox, "claws_fopen");
                alertpanel_error(_("Could not create mbox file:\n%s\n"), mbox);
                return -1;
        }
 
-#ifdef HAVE_FGETS_UNLOCKED
-       flockfile(mbox_fp);
-#endif
-
        statusbar_print_all(_("Exporting to mbox..."));
        for (cur = mlist; cur != NULL; cur = cur->next) {
                int len;
@@ -577,9 +562,6 @@ gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
                        continue;
                }
 
-#ifdef HAVE_FGETS_UNLOCKED
-               flockfile(msg_fp);
-#endif
                strncpy2(buf,
                         msginfo->from ? msginfo->from :
                         cur_account && cur_account->address ?
@@ -590,17 +572,14 @@ gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
                if (fprintf(mbox_fp, "From %s %s",
                        buf, ctime_r(&msginfo->date_t, buft)) < 0) {
                        err = -1;
-#ifdef HAVE_FGETS_UNLOCKED
-                       funlockfile(msg_fp);
-#endif
-                       fclose(msg_fp);
+                       claws_fclose(msg_fp);
                        goto out;
                }
 
                buf[0] = '\0';
                
                /* write email to mboxrc */
-               while (SC_FGETS(buf, sizeof(buf), msg_fp) != NULL) {
+               while (claws_fgets(buf, sizeof(buf), msg_fp) != NULL) {
                        /* quote any From, >From, >>From, etc., according to mbox format specs */
                        int offset;
 
@@ -610,21 +589,15 @@ gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
                                offset++;
                        }
                        if (!strncmp(buf+offset, "From ", 5)) {
-                               if (SC_FPUTC('>', mbox_fp) == EOF) {
+                               if (claws_fputc('>', mbox_fp) == EOF) {
                                        err = -1;
-#ifdef HAVE_FGETS_UNLOCKED
-                                       funlockfile(msg_fp);
-#endif
-                                       fclose(msg_fp);
+                                       claws_fclose(msg_fp);
                                        goto out;
                                }
                        }
-                       if (SC_FPUTS(buf, mbox_fp) == EOF) {
+                       if (claws_fputs(buf, mbox_fp) == EOF) {
                                err = -1;
-#ifdef HAVE_FGETS_UNLOCKED
-                               funlockfile(msg_fp);
-#endif
-                               fclose(msg_fp);
+                               claws_fclose(msg_fp);
                                goto out;
                        }
                }
@@ -634,31 +607,22 @@ gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
                if (len > 0) {
                        len--;
                        if ((buf[len] != '\n') && (buf[len] != '\r')) {
-                               if (SC_FPUTC('\n', mbox_fp) == EOF) {
+                               if (claws_fputc('\n', mbox_fp) == EOF) {
                                        err = -1;
-#ifdef HAVE_FGETS_UNLOCKED
-                                       funlockfile(msg_fp);
-#endif
-                                       fclose(msg_fp);
+                                       claws_fclose(msg_fp);
                                        goto out;
                                }
                        }
                }
 
                /* add a trailing empty line */
-               if (SC_FPUTC('\n', mbox_fp) == EOF) {
+               if (claws_fputc('\n', mbox_fp) == EOF) {
                        err = -1;
-#ifdef HAVE_FGETS_UNLOCKED
-                       funlockfile(msg_fp);
-#endif
-                       fclose(msg_fp);
+                       claws_fclose(msg_fp);
                        goto out;
                }
 
-#ifdef HAVE_FGETS_UNLOCKED
-               funlockfile(msg_fp);
-#endif
-               safe_fclose(msg_fp);
+               claws_safe_fclose(msg_fp);
                statusbar_progress_all(msgs++,total, 500);
                if (msgs%500 == 0)
                        GTK_EVENTS_FLUSH();
@@ -668,10 +632,7 @@ out:
        statusbar_progress_all(0,0,0);
        statusbar_pop_all();
 
-#ifdef HAVE_FGETS_UNLOCKED
-       funlockfile(mbox_fp);
-#endif
-       safe_fclose(mbox_fp);
+       claws_safe_fclose(mbox_fp);
 
        return err;
 }
index 0f54089..409e864 100644 (file)
@@ -893,8 +893,8 @@ static gint disposition_notification_send(MsgInfo *msginfo)
        g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%p",
                   get_rc_dir(), G_DIR_SEPARATOR, msginfo);
 
-       if ((fp = g_fopen(tmp, "wb")) == NULL) {
-               FILE_OP_ERROR(tmp, "fopen");
+       if ((fp = claws_fopen(tmp, "wb")) == NULL) {
+               FILE_OP_ERROR(tmp, "claws_fopen");
                return -1;
        }
 
@@ -1062,8 +1062,8 @@ static gint disposition_notification_send(MsgInfo *msginfo)
        if (ok < 0)
                goto FILE_ERROR;        
 
-       if (safe_fclose(fp) == EOF) {
-               FILE_OP_ERROR(tmp, "fclose");
+       if (claws_safe_fclose(fp) == EOF) {
+               FILE_OP_ERROR(tmp, "claws_fclose");
                claws_unlink(tmp);
                return -1;
        }
@@ -1100,7 +1100,7 @@ static gint disposition_notification_send(MsgInfo *msginfo)
        return ok;
 
 FILE_ERROR:
-       fclose(fp);
+       claws_fclose(fp);
        claws_unlink(tmp);
        return -1;
 }
index 69d0eca..b0967a8 100644 (file)
--- a/src/mh.c
+++ b/src/mh.c
@@ -1011,8 +1011,8 @@ 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 = g_fopen(mh_sequences_filename, "a+b")) != NULL) {
-               fclose(mh_sequences_file);
+       if ((mh_sequences_file = claws_fopen(mh_sequences_filename, "a+b")) != NULL) {
+               claws_fclose(mh_sequences_file);
        }
        g_free(mh_sequences_filename);
        g_free(path);
@@ -1324,9 +1324,9 @@ static gchar *get_unseen_seq_name(void)
                gchar *profile_path = g_strconcat(
                        get_home_dir(), G_DIR_SEPARATOR_S,
                        ".mh_profile", NULL);
-               FILE *fp = g_fopen(profile_path, "r");
+               FILE *fp = claws_fopen(profile_path, "r");
                if (fp) {
-                       while (fgets(buf, sizeof(buf), fp) != NULL) {
+                       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                                if (!strncmp(buf, "Unseen-Sequence:", strlen("Unseen-Sequence:"))) {
                                        gchar *seq_tmp = buf+strlen("Unseen-Sequence:");
                                        while (*seq_tmp == ' ')
@@ -1336,7 +1336,7 @@ static gchar *get_unseen_seq_name(void)
                                        break;
                                }
                        }
-                       fclose(fp);
+                       claws_fclose(fp);
                }
                if (!seq_name)
                        seq_name = g_strdup("unseen");
@@ -1365,7 +1365,7 @@ static void mh_write_sequences(FolderItem *item, gboolean remove_unseen)
                                            ".mh_sequences", NULL);
        mh_sequences_new = g_strconcat(path, G_DIR_SEPARATOR_S,
                                            ".mh_sequences.new", NULL);
-       if ((mh_sequences_new_fp = g_fopen(mh_sequences_new, "w+b")) != NULL) {
+       if ((mh_sequences_new_fp = claws_fopen(mh_sequences_new, "w+b")) != NULL) {
                GSList *msglist = folder_item_get_msg_list(item);
                GSList *cur;
                MsgInfo *info = NULL;
@@ -1411,18 +1411,18 @@ static void mh_write_sequences(FolderItem *item, gboolean remove_unseen)
                                        get_unseen_seq_name(), sequence);
                }
                /* rewrite the rest of the file */
-               if ((mh_sequences_old_fp = g_fopen(mh_sequences_old, "r+b")) != NULL) {
-                       while (fgets(buf, sizeof(buf), mh_sequences_old_fp) != NULL) {
+               if ((mh_sequences_old_fp = claws_fopen(mh_sequences_old, "r+b")) != NULL) {
+                       while (claws_fgets(buf, sizeof(buf), mh_sequences_old_fp) != NULL) {
                                if (strncmp(buf, get_unseen_seq_name(), strlen(get_unseen_seq_name())))
                                        if (fprintf(mh_sequences_new_fp, "%s", buf) < 0) {
                                                err = TRUE;
                                                break;
                                        }
                        }
-                       fclose(mh_sequences_old_fp);
+                       claws_fclose(mh_sequences_old_fp);
                }
                
-               if (safe_fclose(mh_sequences_new_fp) == EOF)
+               if (claws_safe_fclose(mh_sequences_new_fp) == EOF)
                        err = TRUE;
 
                if (!err) {
index 614bcd7..f6eac4c 100644 (file)
@@ -55,6 +55,7 @@
 #include "timing.h"
 #include "manage_window.h"
 #include "privacy.h"
+#include "claws_io.h"
 
 typedef enum
 {
@@ -792,21 +793,21 @@ static void mimeview_show_message_part(MimeView *mimeview, MimeInfo *partinfo)
        fname = mimeview->file;
        if (!fname) return;
 
-       if ((fp = g_fopen(fname, "rb")) == NULL) {
-               FILE_OP_ERROR(fname, "fopen");
+       if ((fp = claws_fopen(fname, "rb")) == NULL) {
+               FILE_OP_ERROR(fname, "claws_fopen");
                return;
        }
 
        if (fseek(fp, partinfo->offset, SEEK_SET) < 0) {
                FILE_OP_ERROR(mimeview->file, "fseek");
-               fclose(fp);
+               claws_fclose(fp);
                return;
        }
 
        mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
        textview_show_part(mimeview->textview, partinfo, fp);
 
-       fclose(fp);
+       claws_fclose(fp);
 }
 
 static MimeViewer *get_viewer_for_content_type(MimeView *mimeview, const gchar *content_type)
@@ -1692,7 +1693,7 @@ static void mimeview_drag_data_get(GtkWidget          *widget,
                GPtrArray *headers = NULL;
                FILE *fp;
 
-               fp = g_fopen(partinfo->data.filename, "rb");
+               fp = claws_fopen(partinfo->data.filename, "rb");
                if (fp != NULL && fseek(fp, partinfo->offset, SEEK_SET) == 0) {
                        headers = procheader_get_header_array_asis(fp);
                        if (headers) {
@@ -1709,7 +1710,7 @@ static void mimeview_drag_data_get(GtkWidget          *widget,
                        }
                }
                if (fp != NULL)
-                       fclose(fp);
+                       claws_fclose(fp);
                if (name)
                        filename = g_path_get_basename(name);
                g_free(name);
index 8909ea7..ca9d965 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "defs.h"
 
-#define _GNU_SOURCE
 #include <stdio.h>
 
 #include <glib.h>
 #include "prefs_common.h"
 #include "claws_io.h"
 
-#ifdef HAVE_FWRITE_UNLOCKED
-#define SC_FWRITE fwrite_unlocked
-#else
-#define SC_FWRITE fwrite
-#endif
-
 #if G_BYTE_ORDER == G_BIG_ENDIAN
 #define bswap_32(x) \
      ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) | \
@@ -312,7 +305,7 @@ gint msgcache_get_memory_usage(MsgCache *cache)
        guint32 idata; \
        size_t ni; \
  \
-       if ((ni = fread(&idata, sizeof(idata), 1, fp)) != 1) { \
+       if ((ni = claws_fread(&idata, sizeof(idata), 1, fp)) != 1) { \
                g_warning("read_int: Cache data corrupted, read %zd of %zd at " \
                          "offset %ld", ni, sizeof(idata), ftell(fp)); \
                procmsg_msginfo_free(&msginfo); \
@@ -357,7 +350,7 @@ gint msgcache_get_memory_usage(MsgCache *cache)
        guint32 idata;                                  \
                                                        \
        idata = (guint32)bswap_32(n);                   \
-       if (SC_FWRITE(&idata, sizeof(idata), 1, fp) != 1)       \
+       if (claws_fwrite(&idata, sizeof(idata), 1, fp) != 1)    \
                w_err = 1;                              \
        wrote += 4;                                     \
 }
@@ -381,7 +374,7 @@ gint msgcache_get_memory_usage(MsgCache *cache)
                len = strlen(data);                     \
        WRITE_CACHE_DATA_INT(len, fp);                  \
        if (w_err == 0 && len > 0) {                    \
-               if (SC_FWRITE(data, 1, len, fp) != len) \
+               if (claws_fwrite(data, 1, len, fp) != len)      \
                        w_err = 1;                      \
                wrote += len;                           \
        } \
@@ -413,8 +406,8 @@ static FILE *msgcache_open_data_file(const gchar *file, guint version,
 
        if (mode == DATA_WRITE) {
                int w_err = 0, wrote = 0;
-               if ((fp = g_fopen(file, "wb")) == NULL) {
-                       FILE_OP_ERROR(file, "fopen");
+               if ((fp = claws_fopen(file, "wb")) == NULL) {
+                       FILE_OP_ERROR(file, "claws_fopen");
                        return NULL;
                }
                if (change_file_mode_rw(fp, file) < 0)
@@ -423,23 +416,23 @@ static FILE *msgcache_open_data_file(const gchar *file, guint version,
                WRITE_CACHE_DATA_INT(version, fp);
                if (w_err != 0) {
                        g_warning("failed to write int");
-                       fclose(fp);
+                       claws_fclose(fp);
                        return NULL;
                }
                return fp;
        }
 
        /* check version */
-       if ((fp = g_fopen(file, "rb")) == NULL)
+       if ((fp = claws_fopen(file, "rb")) == NULL)
                debug_print("Mark/Cache file '%s' not found\n", file);
        else {
                if (buf && buf_size > 0)
                        setvbuf(fp, buf, _IOFBF, buf_size);
-               if (fread(&data_ver, sizeof(data_ver), 1, fp) != 1 ||
+               if (claws_fread(&data_ver, sizeof(data_ver), 1, fp) != 1 ||
                         version != bswap_32(data_ver)) {
                        g_message("%s: Mark/Cache version is different (%u != %u).\n",
                                  file, bswap_32(data_ver), version);
-                       fclose(fp);
+                       claws_fclose(fp);
                        fp = NULL;
                }
                data_ver = bswap_32(data_ver);
@@ -450,9 +443,9 @@ static FILE *msgcache_open_data_file(const gchar *file, guint version,
 
        if (fp) {
                /* reopen with append mode */
-               fclose(fp);
-               if ((fp = g_fopen(file, "ab")) == NULL)
-                       FILE_OP_ERROR(file, "fopen");
+               claws_fclose(fp);
+               if ((fp = claws_fopen(file, "ab")) == NULL)
+                       FILE_OP_ERROR(file, "claws_fopen");
        } else {
                /* open with overwrite mode if mark file doesn't exist or
                   version is different */
@@ -472,7 +465,7 @@ static gint msgcache_read_cache_data_str(FILE *fp, gchar **str,
 
        *str = NULL;
        if (!swapping) {
-               if ((ni = fread(&len, sizeof(len), 1, fp) != 1) ||
+               if ((ni = claws_fread(&len, sizeof(len), 1, fp) != 1) ||
                    len > G_MAXINT) {
                        g_warning("read_data_str: Cache data (len) corrupted, read %zd "
                                  "of %zd bytes at offset %ld", ni, sizeof(len),
@@ -480,7 +473,7 @@ static gint msgcache_read_cache_data_str(FILE *fp, gchar **str,
                        return -1;
                }
        } else {
-               if ((ni = fread(&len, sizeof(len), 1, fp) != 1) ||
+               if ((ni = claws_fread(&len, sizeof(len), 1, fp) != 1) ||
                    bswap_32(len) > G_MAXINT) {
                        g_warning("read_data_str: Cache data (len) corrupted, read %zd "
                                  "of %zd bytes at offset %ld", ni, sizeof(len),
@@ -499,7 +492,7 @@ static gint msgcache_read_cache_data_str(FILE *fp, gchar **str,
                return -1;
        }
 
-       if ((ni = fread(tmpstr, 1, len, fp)) != len) {
+       if ((ni = claws_fread(tmpstr, 1, len, fp)) != len) {
                g_warning("read_data_str: Cache data corrupted, read %zd of %u "
                          "bytes at offset %ld",
                          ni, len, ftell(fp));
@@ -612,7 +605,7 @@ MsgCache *msgcache_read_cache(FolderItem *item, const gchar *cache_file)
        }
 
        if (msgcache_read_cache_data_str(fp, &srccharset, NULL) < 0) {
-               fclose(fp);
+               claws_fclose(fp);
                return NULL;
        }
        dstcharset = CS_UTF_8;
@@ -718,7 +711,7 @@ MsgCache *msgcache_read_cache(FolderItem *item, const gchar *cache_file)
                                g_hash_table_insert(cache->msgid_table, msginfo->msgid, msginfo);
                }
        } else {
-               while (fread(&num, sizeof(num), 1, fp) == 1) {
+               while (claws_fread(&num, sizeof(num), 1, fp) == 1) {
                        if (swapping)
                                num = bswap_32(num);
 
@@ -776,7 +769,7 @@ bail_err:
                munmap(cache_data, map_len);
 #endif
        }
-       fclose(fp);
+       claws_fclose(fp);
        if (conv != NULL) {
                if (conv->free != NULL)
                        conv->free(conv);
@@ -863,10 +856,10 @@ void msgcache_read_mark(MsgCache *cache, const gchar *mark_file)
                        }
                }
        } else {
-               while (fread(&num, sizeof(num), 1, fp) == 1) {
+               while (claws_fread(&num, sizeof(num), 1, fp) == 1) {
                        if (swapping)
                                num = bswap_32(num);
-                       if (fread(&perm_flags, sizeof(perm_flags), 1, fp) != 1) {
+                       if (claws_fread(&perm_flags, sizeof(perm_flags), 1, fp) != 1) {
                                error = TRUE;
                                break;
                        }
@@ -886,7 +879,7 @@ bail_err:
                munmap(cache_data, map_len);
 #endif
        }
-       fclose(fp);
+       claws_fclose(fp);
        if (error) {
                debug_print("error reading cache mark from %s\n", mark_file);
        }
@@ -967,7 +960,7 @@ void msgcache_read_tags(MsgCache *cache, const gchar *tags_file)
                        }
                }
        } else {
-               while (fread(&num, sizeof(num), 1, fp) == 1) {
+               while (claws_fread(&num, sizeof(num), 1, fp) == 1) {
                        gint id = -1;
                        if (swapping)
                                num = bswap_32(num);
@@ -976,7 +969,7 @@ void msgcache_read_tags(MsgCache *cache, const gchar *tags_file)
                                g_slist_free(msginfo->tags);
                                msginfo->tags = NULL;
                                do {
-                                       if (fread(&id, sizeof(id), 1, fp) != 1) 
+                                       if (claws_fread(&id, sizeof(id), 1, fp) != 1) 
                                                id = -1;
                                        if (swapping)
                                                id = bswap_32(id);
@@ -998,7 +991,7 @@ bail_err:
                munmap(cache_data, map_len);
 #endif
        }
-       fclose(fp);
+       claws_fclose(fp);
        if (error) {
                debug_print("error reading cache tags from %s\n", tags_file);
        }
@@ -1144,7 +1137,7 @@ gint msgcache_write(const gchar *cache_file, const gchar *mark_file, const gchar
        if (w_err != 0) {
                g_warning("failed to write charset");
                if (write_fps.cache_fp)
-                       fclose(write_fps.cache_fp);
+                       claws_fclose(write_fps.cache_fp);
                claws_unlink(new_cache);
                g_free(new_cache);
                g_free(new_mark);
@@ -1157,7 +1150,7 @@ gint msgcache_write(const gchar *cache_file, const gchar *mark_file, const gchar
                        DATA_WRITE, NULL, 0);
                if (write_fps.mark_fp == NULL) {
                        if (write_fps.cache_fp)
-                               fclose(write_fps.cache_fp);
+                               claws_fclose(write_fps.cache_fp);
                        claws_unlink(new_cache);
                        g_free(new_cache);
                        g_free(new_mark);
@@ -1173,9 +1166,9 @@ gint msgcache_write(const gchar *cache_file, const gchar *mark_file, const gchar
                        DATA_WRITE, NULL, 0);
                if (write_fps.tags_fp == NULL) {
                        if (write_fps.cache_fp)
-                               fclose(write_fps.cache_fp);
+                               claws_fclose(write_fps.cache_fp);
                        if (write_fps.mark_fp)
-                               fclose(write_fps.mark_fp);
+                               claws_fclose(write_fps.mark_fp);
                        claws_unlink(new_cache);
                        claws_unlink(new_mark);
                        g_free(new_cache);
@@ -1200,34 +1193,16 @@ gint msgcache_write(const gchar *cache_file, const gchar *mark_file, const gchar
        if (write_fps.tags_fp)
                write_fps.tags_size = ftell(write_fps.tags_fp);
 
-#ifdef HAVE_FWRITE_UNLOCKED
-       /* lock files for write once (instead of once per fwrite) */
-       if (write_fps.cache_fp)
-               flockfile(write_fps.cache_fp);
-       if (write_fps.mark_fp)
-               flockfile(write_fps.mark_fp);
-       if (write_fps.tags_fp)
-               flockfile(write_fps.tags_fp);
-#endif
        /* write data to the files */
        g_hash_table_foreach(cache->msgnum_table, msgcache_write_func, (gpointer)&write_fps);
-#ifdef HAVE_FWRITE_UNLOCKED
-       /* unlock files */
-       if (write_fps.cache_fp)
-               funlockfile(write_fps.cache_fp);
-       if (write_fps.mark_fp)
-               funlockfile(write_fps.mark_fp);
-       if (write_fps.tags_fp)
-               funlockfile(write_fps.tags_fp);
-#endif
 
        /* close files */
        if (write_fps.cache_fp)
-               write_fps.error |= (safe_fclose(write_fps.cache_fp) != 0);
+               write_fps.error |= (claws_safe_fclose(write_fps.cache_fp) != 0);
        if (write_fps.mark_fp)
-               write_fps.error |= (safe_fclose(write_fps.mark_fp) != 0);
+               write_fps.error |= (claws_safe_fclose(write_fps.mark_fp) != 0);
        if (write_fps.tags_fp)
-               write_fps.error |= (safe_fclose(write_fps.tags_fp) != 0);
+               write_fps.error |= (claws_safe_fclose(write_fps.tags_fp) != 0);
 
 
        if (write_fps.error != 0) {
index 4564347..8ae8508 100644 (file)
@@ -31,6 +31,7 @@
 #include "mutt.h"
 #include "addritem.h"
 #include "addrcache.h"
+#include "claws_io.h"
 
 #define MUTT_HOME_FILE  ".muttrc"
 #define MUTTBUFSIZE     2048
@@ -74,7 +75,7 @@ void mutt_free( MuttFile *muttFile ) {
        cm_return_if_fail( muttFile != NULL );
 
        /* Close file */
-       if( muttFile->file ) fclose( muttFile->file );
+       if( muttFile->file ) claws_fclose( muttFile->file );
 
        /* Free internal stuff */
        g_free( muttFile->path );
@@ -100,7 +101,7 @@ void mutt_free( MuttFile *muttFile ) {
 */
 static gint mutt_open_file( MuttFile* muttFile ) {
        if( muttFile->path ) {
-               muttFile->file = g_fopen( muttFile->path, "rb" );
+               muttFile->file = claws_fopen( muttFile->path, "rb" );
                if( ! muttFile->file ) {
                        muttFile->retVal = MGU_OPEN_FILE;
                        return muttFile->retVal;
@@ -122,7 +123,7 @@ static gint mutt_open_file( MuttFile* muttFile ) {
 */
 static void mutt_close_file( MuttFile *muttFile ) {
        cm_return_if_fail( muttFile != NULL );
-       if( muttFile->file ) fclose( muttFile->file );
+       if( muttFile->file ) claws_fclose( muttFile->file );
        muttFile->file = NULL;
 }
 
@@ -138,7 +139,7 @@ static gchar *mutt_get_line( MuttFile *muttFile, gboolean *flagCont ) {
        int i = 0, li = 0;
 
        *flagCont = FALSE;
-       if( feof( muttFile->file ) ) 
+       if( claws_feof( muttFile->file ) ) 
                return NULL;
 
        memset(buf, 0, MUTTBUFSIZE);
@@ -549,8 +550,8 @@ gchar *mutt_find_file( void ) {
        strncat( str, MUTT_HOME_FILE, WORK_BUFLEN - strlen(str) );
 
        /* Attempt to open */
-       if( ( fp = g_fopen( str, "rb" ) ) != NULL ) {
-               fclose( fp );
+       if( ( fp = claws_fopen( str, "rb" ) ) != NULL ) {
+               claws_fclose( fp );
        }
        else {
                /* Truncate filename */
index 296a4f6..c963ac1 100644 (file)
@@ -653,12 +653,12 @@ GSList *news_get_group_list(Folder *folder)
        filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
        g_free(path);
 
-       if ((fp = g_fopen(filename, "rb")) == NULL) {
+       if ((fp = claws_fopen(filename, "rb")) == NULL) {
                NewsSession *session;
                gint ok;
                clist *grouplist = NULL;
                clistiter *cur;
-               fp = g_fopen(filename, "wb");
+               fp = claws_fopen(filename, "wb");
                
                if (!fp) {
                        g_free(filename);
@@ -666,7 +666,7 @@ GSList *news_get_group_list(Folder *folder)
                }
                session = news_session_get(folder);
                if (!session) {
-                       fclose(fp);
+                       claws_fclose(fp);
                        g_free(filename);
                        return NULL;
                }
@@ -678,7 +678,7 @@ GSList *news_get_group_list(Folder *folder)
                                session_destroy(SESSION(session));
                                REMOTE_FOLDER(folder)->session = NULL;
                        }
-                       fclose(fp);
+                       claws_fclose(fp);
                        g_free(filename);
                        return NULL;
                }
@@ -695,7 +695,7 @@ GSList *news_get_group_list(Folder *folder)
                                        log_error(LOG_PROTOCOL, ("Can't write newsgroup list\n"));
                                        session_destroy(SESSION(session));
                                        REMOTE_FOLDER(folder)->session = NULL;
-                                       fclose(fp);
+                                       claws_fclose(fp);
                                        g_free(filename);
                                        newsnntp_list_free(grouplist);
                                        return NULL;
@@ -703,7 +703,7 @@ GSList *news_get_group_list(Folder *folder)
                        }
                        newsnntp_list_free(grouplist);
                }
-               if (safe_fclose(fp) == EOF) {
+               if (claws_safe_fclose(fp) == EOF) {
                        log_error(LOG_PROTOCOL, ("Can't write newsgroup list\n"));
                        session_destroy(SESSION(session));
                        REMOTE_FOLDER(folder)->session = NULL;
@@ -711,14 +711,14 @@ GSList *news_get_group_list(Folder *folder)
                        return NULL;
                }
 
-               if ((fp = g_fopen(filename, "rb")) == NULL) {
-                       FILE_OP_ERROR(filename, "fopen");
+               if ((fp = claws_fopen(filename, "rb")) == NULL) {
+                       FILE_OP_ERROR(filename, "claws_fopen");
                        g_free(filename);
                        return NULL;
                }
        }
 
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                gchar *p = buf;
                gchar *name;
                gint last_num;
@@ -745,7 +745,7 @@ GSList *news_get_group_list(Folder *folder)
                }
        }
 
-       fclose(fp);
+       claws_fclose(fp);
        g_free(filename);
 
        list = g_slist_sort(list, (GCompareFunc)news_group_info_compare);
@@ -949,8 +949,8 @@ gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
        if (tmp == NULL)
                return -1;
 
-       if ((tmpfp = g_fopen(tmp, "wb")) == NULL) {
-               FILE_OP_ERROR(tmp, "fopen");
+       if ((tmpfp = claws_fopen(tmp, "wb")) == NULL) {
+               FILE_OP_ERROR(tmp, "claws_fopen");
                return -1;
        }
        if (change_file_mode_rw(tmpfp, tmp) < 0) {
@@ -979,14 +979,14 @@ gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
                       msginfo->from,
                       date) < 0) {
                FILE_OP_ERROR(tmp, "fprintf");
-               fclose(tmpfp);
+               claws_fclose(tmpfp);
                claws_unlink(tmp);
                g_free(tmp);
                return -1;
        }
 
-       if (safe_fclose(tmpfp) == EOF) {
-               FILE_OP_ERROR(tmp, "fclose");
+       if (claws_safe_fclose(tmpfp) == EOF) {
+               FILE_OP_ERROR(tmp, "claws_fclose");
                claws_unlink(tmp);
                g_free(tmp);
                return -1;
index 9d3c7d2..76b25fc 100644 (file)
@@ -90,14 +90,14 @@ int partial_msg_in_uidl_list(MsgInfo *msginfo)
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                           "uidl", G_DIR_SEPARATOR_S, msginfo->extradata->account_server,
                           "-", msginfo->extradata->account_login, NULL);
-       if ((fp = g_fopen(path, "rb")) == NULL) {
-               if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
+       if ((fp = claws_fopen(path, "rb")) == NULL) {
+               if (ENOENT != errno) FILE_OP_ERROR(path, "claws_fopen");
                g_free(path);
                path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                   "uidl-", msginfo->extradata->account_server,
                                   "-", sanitized_uid, NULL);
-               if ((fp = g_fopen(path, "rb")) == NULL) {
-                       if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
+               if ((fp = claws_fopen(path, "rb")) == NULL) {
+                       if (ENOENT != errno) FILE_OP_ERROR(path, "claws_fopen");
                        g_free(sanitized_uid);
                        g_free(path);
                        return FALSE;
@@ -108,7 +108,7 @@ int partial_msg_in_uidl_list(MsgInfo *msginfo)
 
        now = time(NULL);
 
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                gchar tmp[POPBUFSIZE];
                strretchomp(buf);
                recv_time = RECV_TIME_NONE;
@@ -122,12 +122,12 @@ int partial_msg_in_uidl_list(MsgInfo *msginfo)
                        }
                }
                if (!strcmp(uidl, msginfo->extradata->partial_recv)) {
-                       fclose(fp);
+                       claws_fclose(fp);
                        return TRUE;
                }
        }
 
-       fclose(fp);     
+       claws_fclose(fp);       
        return FALSE;
 }
 
@@ -171,15 +171,14 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
                           "uidl", G_DIR_SEPARATOR_S, tinfo->extradata->account_server,
                           "-", sanitized_uid, NULL);
 
-       if ((fp = g_fopen(path, "rb")) == NULL) {
-               FILE_OP_ERROR(path, "fopen");
-               if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
+       if ((fp = claws_fopen(path, "rb")) == NULL) {
+               if (ENOENT != errno) FILE_OP_ERROR(path, "claws_fopen");
                g_free(path);
                path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                   "uidl-", tinfo->extradata->account_server,
                                   "-", tinfo->extradata->account_login, NULL);
-               if ((fp = g_fopen(path, "rb")) == NULL) {
-                       if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
+               if ((fp = claws_fopen(path, "rb")) == NULL) {
+                       if (ENOENT != errno) FILE_OP_ERROR(path, "claws_fopen");
                        g_free(path);
                        goto bail;
                }
@@ -191,16 +190,16 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
        
        g_free(sanitized_uid);
 
-       if ((fpnew = g_fopen(pathnew, "wb")) == NULL) {
-               FILE_OP_ERROR(pathnew, "fopen");
-               fclose(fp);
+       if ((fpnew = claws_fopen(pathnew, "wb")) == NULL) {
+               FILE_OP_ERROR(pathnew, "claws_fopen");
+               claws_fclose(fp);
                g_free(pathnew);
                goto bail;
        }
        
        now = time(NULL);
 
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                strretchomp(buf);
                recv_time = RECV_TIME_NONE;
                sprintf(partial_recv,"0");
@@ -217,8 +216,8 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
                        if (fprintf(fpnew, "%s\t%ld\t%s\n", 
                                uidl, (long int) recv_time, partial_recv) < 0) {
                                FILE_OP_ERROR(pathnew, "fprintf");
-                               fclose(fpnew);
-                               fclose(fp);
+                               claws_fclose(fpnew);
+                               claws_fclose(fp);
                                g_free(path);
                                g_free(pathnew);
                                goto bail;
@@ -240,8 +239,8 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
                        if (fprintf(fpnew, "%s\t%ld\t%s\n", 
                                uidl, (long int) recv_time, stat) < 0) {
                                FILE_OP_ERROR(pathnew, "fprintf");
-                               fclose(fpnew);
-                               fclose(fp);
+                               claws_fclose(fpnew);
+                               claws_fclose(fp);
                                g_free(path);
                                g_free(pathnew);
                                goto bail;
@@ -249,28 +248,28 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
                        g_free(stat);
                }
        }
-       if (safe_fclose(fpnew) == EOF) {
-               FILE_OP_ERROR(pathnew, "fclose");
-               fclose(fp);
+       if (claws_safe_fclose(fpnew) == EOF) {
+               FILE_OP_ERROR(pathnew, "claws_fclose");
+               claws_fclose(fp);
                g_free(path);
                g_free(pathnew);
                goto bail;
        }
-       fclose(fp);
+       claws_fclose(fp);
 
        move_file(pathnew, path, TRUE);
 
        g_free(path);
        g_free(pathnew);
        
-       if ((fp = g_fopen(filename,"rb")) == NULL) {
-               FILE_OP_ERROR(filename, "fopen");
+       if ((fp = claws_fopen(filename,"rb")) == NULL) {
+               FILE_OP_ERROR(filename, "claws_fopen");
                goto bail;
        }
        pathnew = g_strdup_printf("%s.new", filename);
-       if ((fpnew = g_fopen(pathnew, "wb")) == NULL) {
-               FILE_OP_ERROR(pathnew, "fopen");
-               fclose(fp);
+       if ((fpnew = claws_fopen(pathnew, "wb")) == NULL) {
+               FILE_OP_ERROR(pathnew, "claws_fopen");
+               claws_fclose(fp);
                g_free(pathnew);
                goto bail;
        }
@@ -278,20 +277,20 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
        if (fprintf(fpnew, "SC-Marked-For-Download: %d\n", 
                        download) < 0) {
                FILE_OP_ERROR(pathnew, "fprintf");
-               fclose(fpnew);
-               fclose(fp);
+               claws_fclose(fpnew);
+               claws_fclose(fp);
                g_free(pathnew);
                goto bail;
        }
-       while (fgets(buf, sizeof(buf)-1, fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf)-1, fp) != NULL) {
                if(strlen(buf) > strlen("SC-Marked-For-Download: x\n")
                && !strncmp(buf, "SC-Marked-For-Download:", 
                            strlen("SC-Marked-For-Download:"))) {
                        if (fprintf(fpnew, "%s", 
                         buf+strlen("SC-Marked-For-Download: x\n")) < 0) {
                                FILE_OP_ERROR(pathnew, "fprintf");
-                               fclose(fpnew);
-                               fclose(fp);
+                               claws_fclose(fpnew);
+                               claws_fclose(fp);
                                g_free(pathnew);
                                goto bail;
                        }
@@ -303,20 +302,20 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
                }
                if (fprintf(fpnew, "%s", buf) < 0) {
                        FILE_OP_ERROR(pathnew, "fprintf");
-                       fclose(fpnew);
-                       fclose(fp);
+                       claws_fclose(fpnew);
+                       claws_fclose(fp);
                        g_free(pathnew);
                        goto bail;
                }
        }
-       if (safe_fclose(fpnew) == EOF) {
-               FILE_OP_ERROR(pathnew, "fclose");
-               fclose(fp);
+       if (claws_safe_fclose(fpnew) == EOF) {
+               FILE_OP_ERROR(pathnew, "claws_fclose");
+               claws_fclose(fp);
                g_free(pathnew);
                goto bail;
        }
 
-       fclose(fp);
+       claws_fclose(fp);
        if (rename_force(pathnew, filename) != 0) {
                g_free(pathnew);
                goto bail;
@@ -395,14 +394,14 @@ 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 = g_fopen(path, "rb")) == NULL) {
-               if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
+       if ((fp = claws_fopen(path, "rb")) == NULL) {
+               if (ENOENT != errno) FILE_OP_ERROR(path, "claws_fopen");
                g_free(path);
                path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                   "uidl-", server,
                                   "-", sanitized_uid, NULL);
-               if ((fp = g_fopen(path, "rb")) == NULL) {
-                       if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
+               if ((fp = claws_fopen(path, "rb")) == NULL) {
+                       if (ENOENT != errno) FILE_OP_ERROR(path, "claws_fopen");
                        g_free(sanitized_uid);
                        g_free(path);
                        return result;
@@ -413,7 +412,7 @@ gchar *partial_get_filename(const gchar *server, const gchar *login,
 
        now = time(NULL);
 
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                gchar tmp[POPBUFSIZE];
                strretchomp(buf);
                recv_time = RECV_TIME_NONE;
@@ -432,7 +431,7 @@ gchar *partial_get_filename(const gchar *server, const gchar *login,
                }
        }
 
-       fclose(fp);
+       claws_fclose(fp);
        
        return result;
 }
index 97f44d3..ddf6f95 100644 (file)
@@ -37,6 +37,7 @@
 #include "prefs_common.h"
 #include "prefs_gtk.h"
 #include "prefs_migration.h"
+#include "claws_io.h"
 
 static GSList *_password_store;
 
@@ -348,16 +349,16 @@ static gint _write_to_file(FILE *fp)
 
        /* Write out the config_version */
        line = g_strdup_printf("[config_version:%d]\n", CLAWS_CONFIG_VERSION);
-       if (fputs(line, fp) == EOF) {
-               FILE_OP_ERROR("password store, config_version", "fputs");
+       if (claws_fputs(line, fp) == EOF) {
+               FILE_OP_ERROR("password store, config_version", "claws_fputs");
                g_free(line);
                return -1;
        }
        g_free(line);
 
        /* Add a newline if needed */
-       if (_password_store != NULL && fputs("\n", fp) == EOF) {
-               FILE_OP_ERROR("password store", "fputs");
+       if (_password_store != NULL && claws_fputs("\n", fp) == EOF) {
+               FILE_OP_ERROR("password store", "claws_fputs");
                return -1;
        }
 
@@ -382,8 +383,8 @@ static gint _write_to_file(FILE *fp)
                }
                line = g_strdup_printf("[%s:%s]\n", typestr, block->block_name);
 
-               if (fputs(line, fp) == EOF) {
-                       FILE_OP_ERROR("password store", "fputs");
+               if (claws_fputs(line, fp) == EOF) {
+                       FILE_OP_ERROR("password store", "claws_fputs");
                        g_free(line);
                        return -1;
                }
@@ -397,8 +398,8 @@ static gint _write_to_file(FILE *fp)
                                continue;
 
                        line = g_strdup_printf("%s %s\n", key, pwd);
-                       if (fputs(line, fp) == EOF) {
-                               FILE_OP_ERROR("password store", "fputs");
+                       if (claws_fputs(line, fp) == EOF) {
+                               FILE_OP_ERROR("password store", "claws_fputs");
                                g_free(line);
                                return -1;
                        }
@@ -407,8 +408,8 @@ static gint _write_to_file(FILE *fp)
                g_list_free(keys);
 
                /* Add a separating new line if there is another block remaining */
-               if (item->next != NULL && fputs("\n", fp) == EOF) {
-                       FILE_OP_ERROR("password store", "fputs");
+               if (item->next != NULL && claws_fputs("\n", fp) == EOF) {
+                       FILE_OP_ERROR("password store", "claws_fputs");
                        return -1;
                }
 
index 5d29ee5..d4b11d1 100644 (file)
@@ -30,6 +30,7 @@
 #include "pine.h"
 #include "addritem.h"
 #include "addrcache.h"
+#include "claws_io.h"
 
 #define PINE_HOME_FILE  ".addressbook"
 #define PINEBUFSIZE     2048
@@ -76,7 +77,7 @@ void pine_free( PineFile *pineFile ) {
        cm_return_if_fail( pineFile != NULL );
 
        /* Close file */
-       if( pineFile->file ) fclose( pineFile->file );
+       if( pineFile->file ) claws_fclose( pineFile->file );
 
        /* Free internal stuff */
        g_free( pineFile->path );
@@ -103,7 +104,7 @@ void pine_free( PineFile *pineFile ) {
  */
 static gint pine_open_file( PineFile* pineFile ) {
        if( pineFile->path ) {
-               pineFile->file = g_fopen( pineFile->path, "rb" );
+               pineFile->file = claws_fopen( pineFile->path, "rb" );
                if( ! pineFile->file ) {
                        pineFile->retVal = MGU_OPEN_FILE;
                        return pineFile->retVal;
@@ -126,7 +127,7 @@ static gint pine_open_file( PineFile* pineFile ) {
  */
 static void pine_close_file( PineFile *pineFile ) {
        cm_return_if_fail( pineFile != NULL );
-       if( pineFile->file ) fclose( pineFile->file );
+       if( pineFile->file ) claws_fclose( pineFile->file );
        pineFile->file = NULL;
 }
 
@@ -140,7 +141,7 @@ static gchar *pine_read_line( PineFile *pineFile ) {
        int c, i = 0;
        gchar ch;
 
-       if( feof( pineFile->file ) ) 
+       if( claws_feof( pineFile->file ) ) 
                return NULL;
 
        while( i < PINEBUFSIZE-1 ) {
@@ -651,8 +652,8 @@ gchar *pine_find_file( void ) {
        strncat( str, PINE_HOME_FILE, WORK_BUFLEN - strlen(str) );
 
        /* Attempt to open */
-       if( ( fp = g_fopen( str, "rb" ) ) != NULL ) {
-               fclose( fp );
+       if( ( fp = claws_fopen( str, "rb" ) ) != NULL ) {
+               claws_fclose( fp );
        }
        else {
                /* Truncate filename */
index 28e58c8..e32b65c 100644 (file)
@@ -668,16 +668,16 @@ static void acpi_set(gboolean on)
        }
 
        if (!is_program(acpiprefs.file_path)) {
-               fp = fopen(acpiprefs.file_path, "wb");
+               fp = claws_fopen(acpiprefs.file_path, "wb");
                if (fp == NULL)
                        return;
 
                if (on) {
-                       fwrite(acpiprefs.on_param, 1, strlen(acpiprefs.on_param), fp);
+                       claws_fwrite(acpiprefs.on_param, 1, strlen(acpiprefs.on_param), fp);
                } else {
-                       fwrite(acpiprefs.off_param, 1, strlen(acpiprefs.off_param), fp);
+                       claws_fwrite(acpiprefs.off_param, 1, strlen(acpiprefs.off_param), fp);
                }
-               safe_fclose(fp);
+               claws_safe_fclose(fp);
        } else {
                gchar *cmd = g_strdup_printf("%s %s", 
                                acpiprefs.file_path,
index c6a978d..590d392 100644 (file)
@@ -252,14 +252,14 @@ static void bogofilter_do_filter(BogoFilterData *data)
                                            FOLDER_TYPE(msginfo->folder->folder) == F_MH &&
                                            config.insert_header) {
                                                gchar *tmpfile = get_tmp_file();
-                                               FILE *input = g_fopen(file, "r");
-                                               FILE *output = g_fopen(tmpfile, "w");
+                                               FILE *input = claws_fopen(file, "r");
+                                               FILE *output = claws_fopen(tmpfile, "w");
                                                if (strstr(parts[2], "\n"))
                                                        *(strstr(parts[2], "\n")) = '\0';
                                                if (input && !output) 
-                                                       fclose (input);
+                                                       claws_fclose (input);
                                                else if (!input && output)
-                                                       fclose (output);
+                                                       claws_fclose (output);
                                                else if (input && output) {
                                                        gchar tmpbuf[BUFFSIZE];
                                                        gboolean err = FALSE;
@@ -269,18 +269,18 @@ static void bogofilter_do_filter(BogoFilterData *data)
                                                                        "X-Bogosity: %s, spamicity=%s%s\n",
                                                                        bogosity, parts[2],
                                                                        whitelisted?" [whitelisted]":"");
-                                                       if (fwrite(tmpstr, 1, strlen(tmpstr), output) < strlen(tmpstr)) {
+                                                       if (claws_fwrite(tmpstr, 1, strlen(tmpstr), output) < strlen(tmpstr)) {
                                                                err = TRUE;
                                                        } else {
-                                                               while (fgets(tmpbuf, sizeof(buf), input)) {
-                                                                       if (fputs(tmpbuf, output) == EOF) {
+                                                               while (claws_fgets(tmpbuf, sizeof(buf), input)) {
+                                                                       if (claws_fputs(tmpbuf, output) == EOF) {
                                                                                err = TRUE;
                                                                                break;
                                                                        }
                                                                }
                                                        }
-                                                       fclose(input);
-                                                       if (safe_fclose(output) == EOF)
+                                                       claws_fclose(input);
+                                                       if (claws_safe_fclose(output) == EOF)
                                                                err = TRUE;
                                                        if (!err)
                                                                move_file(tmpfile, file, TRUE);
index 15122bb..831e035 100644 (file)
@@ -55,6 +55,7 @@
 #include "statusbar.h"
 #include "alertpanel.h"
 #include "clamd-plugin.h"
+#include "claws_io.h"
 
 #ifndef UNIX_PATH_MAX
 #define UNIX_PATH_MAX 108
@@ -115,13 +116,13 @@ void clamd_create_config_automatic(const gchar* path) {
        config->ConfigType = AUTOMATIC;
        config->automatic.folder = g_strdup(path);
        debug_print("Opening %s to parse config file\n", path);
-       conf = fopen(path, "r");
+       conf = claws_fopen(path, "r");
        if (!conf) {
                /*g_error("%s: Unable to open", path);*/
                alertpanel_error(_("%s: Unable to open\nclamd will be disabled"), path);
                return;
        }
-       while (fgets(buf, sizeof(buf), conf)) {
+       while (claws_fgets(buf, sizeof(buf), conf)) {
                g_strstrip(buf);
                if (buf[0] == '#')
                        continue;
@@ -146,7 +147,7 @@ void clamd_create_config_automatic(const gchar* path) {
                                                Socket->socket.path = g_strdup(value);
                                                g_free(value);
                                                value = NULL;
-                                               fclose(conf);
+                                               claws_fclose(conf);
                                                debug_print("clamctl: %s\n", Socket->socket.path);
                                                return;
                                        }
@@ -210,7 +211,7 @@ void clamd_create_config_automatic(const gchar* path) {
                        }
                }
        }
-       fclose(conf);
+       claws_fclose(conf);
        if (! (Socket && (Socket->socket.port || Socket->socket.path))) {
                /*g_error("%s: Not able to find required information", path);*/
                alertpanel_error(_("%s: Not able to find required information\nclamd will be disabled"), path);
index a7fa4db..9a6ff50 100644 (file)
@@ -5,6 +5,10 @@ alertpanel
 alertpanel_error
 check_plugin_version
 claws_do_idle
+claws_fopen
+claws_fdopen
+claws_fclose
+claws_safe_fclose
 combobox_get_active_data
 combobox_select_by_data
 combobox_text_new
@@ -85,7 +89,6 @@ procmsg_msginfo_unset_flags
 procmsg_register_spam_learner
 procmsg_spam_set_folder
 procmsg_unregister_spam_learner
-safe_fclose
 settings
 start_address_completion
 statusbar_pop_all
index a1b434f..b4933c3 100644 (file)
@@ -645,11 +645,11 @@ static size_t download_file_curl_write_cb(void *buffer, size_t size,
 {
        FancyViewer *viewer = (FancyViewer *)data;
        if (!viewer->stream) {
-               viewer->stream = fopen(viewer->curlfile, "wb");
+               viewer->stream = claws_fopen(viewer->curlfile, "wb");
                if (!viewer->stream)
                        return -1;
        }
-       return fwrite(buffer, size, nmemb, viewer->stream);
+       return claws_fwrite(buffer, size, nmemb, viewer->stream);
 }
 static void *download_file_curl (void *data)
 {
@@ -671,7 +671,7 @@ static void *download_file_curl (void *data)
                if (CURLE_OK != res)
                        alertpanel_error(_("An error occurred: %d\n"), res);
                if (viewer->stream)
-                       safe_fclose(viewer->stream);
+                       claws_safe_fclose(viewer->stream);
                curl_global_cleanup();
        }
 #ifdef USE_PTHREAD
index 924b5d1..3fec5b6 100644 (file)
@@ -6,6 +6,10 @@ alertpanel_notice
 alertpanel_warning
 auto_configure_service_sync
 claws_unlink
+claws_fopen
+claws_fdopen
+claws_fclose
+claws_safe_fclose
 extract_address
 get_locale_dir
 check_plugin_version
@@ -36,6 +40,5 @@ prefs_write_param
 prefs_common_get_prefs
 procmsg_msginfo_add_avatar
 procmsg_msginfo_get_avatar
-safe_fclose
 slist_free_strings_full
 to_human_readable
index 1482ae1..20bc3b2 100644 (file)
@@ -36,7 +36,7 @@
 
 static size_t write_image_data_cb(void *ptr, size_t size, size_t nmemb, void *stream)
 {
-       size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
+       size_t written = claws_fwrite(ptr, size, nmemb, (FILE *)stream);
        debug_print("received %zu bytes from avatar server\n", written);
 
        return written;
@@ -74,7 +74,7 @@ static GdkPixbuf *pixbuf_from_url(const gchar *url, const gchar *md5, const gcha
        CURL *curl;
        long filesize;
 
-       file = fopen(filename, "wb");
+       file = claws_fopen(filename, "wb");
        if (file == NULL) {
                g_warning("could not open '%s' for writing", filename);
                return NULL;
@@ -82,7 +82,7 @@ static GdkPixbuf *pixbuf_from_url(const gchar *url, const gchar *md5, const gcha
        curl = curl_easy_init();
        if (curl == NULL) {
                g_warning("could not initialize curl to get image from URL");
-               fclose(file);
+               claws_fclose(file);
                return NULL;
        }
 
@@ -107,7 +107,7 @@ static GdkPixbuf *pixbuf_from_url(const gchar *url, const gchar *md5, const gcha
        debug_print("retrieving URL to file: %s -> %s\n", url, filename);
        curl_easy_perform(curl);
        filesize = ftell(file);
-       safe_fclose(file);
+       claws_safe_fclose(file);
        if (filesize < MIN_PNG_SIZE)
                debug_print("not enough data for an avatar image: %ld bytes\n", filesize);
        else
index a19de48..dc2d81f 100644 (file)
@@ -33,7 +33,7 @@
  */
 GHashTable *missing_load_from_file(const gchar *filename)
 {
-       FILE *file = fopen(filename, "r");
+       FILE *file = claws_fopen(filename, "r");
        time_t t;
        long long unsigned seen;
        gchar md5sum[33];
@@ -66,7 +66,7 @@ GHashTable *missing_load_from_file(const gchar *filename)
        }
 
 close_exit:
-       if (fclose(file) != 0)
+       if (claws_fclose(file) != 0)
                g_warning("error closing '%s'", filename);
 
        debug_print("Read %d missing avatar entries, %d obsolete entries discarded\n", a, d);
@@ -84,7 +84,7 @@ static void missing_save_item(gpointer key, gpointer value, gpointer data)
 {
        FILE *file = (FILE *)data;
        gchar *line = g_strdup_printf("%s %llu\n", (gchar *)key, *((long long unsigned *)value));
-       if (fputs(line, file) < 0)
+       if (claws_fputs(line, file) < 0)
                g_warning("error saving missing item");
        g_free(line);
 }
@@ -99,7 +99,7 @@ static void missing_save_item(gpointer key, gpointer value, gpointer data)
  */
 gint missing_save_to_file(GHashTable *table, const gchar *filename)
 {
-       FILE *file = fopen(filename, "w");
+       FILE *file = claws_fopen(filename, "w");
 
        if (file == NULL) {
                g_warning("cannot open '%s' for writing", filename);
@@ -109,7 +109,7 @@ gint missing_save_to_file(GHashTable *table, const gchar *filename)
        g_hash_table_foreach(table, missing_save_item, (gpointer)file);
        debug_print("Saved %u missing avatar entries\n", g_hash_table_size(table));
 
-       if (safe_fclose(file) != 0) {
+       if (claws_safe_fclose(file) != 0) {
                g_warning("error closing '%s'", filename);
                return -1;
        }
index 0f686d3..0efcc45 100644 (file)
@@ -3,6 +3,10 @@ EXPORTS
 get_locale_dir
 check_plugin_version
 alertpanel
+claws_fopen
+claws_fdopen
+claws_fclose
+claws_safe_fclose
 conv_codeset_strdup
 conv_get_locale_charset_str_no_utf8
 debug_print_real
@@ -28,4 +32,3 @@ prefs_set_default
 prefs_write_open
 prefs_write_param
 prefs_common_get_prefs
-safe_fclose
\ No newline at end of file
index af49ca4..e932ca7 100644 (file)
  * $Id$
  */
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
+
 #include "mailimf.h"
+#include "claws_io.h"
 
 /*
   RFC 2822
index c592e8f..27352b5 100644 (file)
  * $Id$
  */
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
+
 #include "mailimf_write.h"
 
 #include <time.h>
 #include <string.h>
 #include <ctype.h>
+#include "claws_io.h"
 
 #define MAX_MAIL_COL 72
 
@@ -128,23 +134,6 @@ mailimf_resent_msg_id_write(FILE * f, int * col,
 
 /* ************************ */
 
-#if 0
-int mailimf_string_write(FILE * f, int * col,
-                        char * str, size_t length)
-{
-  int r;
-
-  if (length != 0) {
-    r = fwrite(str, sizeof(char), length, f);
-    if (r < 0)
-      return MAILIMF_ERROR_FILE;
-    * col += length;
-  }
-
-  return MAILIMF_NO_ERROR;
-}
-#endif
-
 #define CRLF "\r\n"
 #define HEADER_FOLD "\r\n "
 
@@ -153,7 +142,7 @@ static inline int flush_buf(FILE * f, const char * str, size_t length)
   if (length != 0) {
     int r;
     
-    r = fwrite(str, 1, length, f);
+    r = claws_fwrite(str, 1, length, f);
     if (r == 0)
       return MAILIMF_ERROR_FILE;
   }
@@ -192,7 +181,7 @@ int mailimf_string_write(FILE * f, int * col,
       if (r != MAILIMF_NO_ERROR)
         return r;
       
-      r = fwrite(CRLF, 1, sizeof(CRLF) - 1, f);
+      r = claws_fwrite(CRLF, 1, sizeof(CRLF) - 1, f);
       if (r == 0)
         return MAILIMF_ERROR_FILE;
       
@@ -208,7 +197,7 @@ int mailimf_string_write(FILE * f, int * col,
       if (r != MAILIMF_NO_ERROR)
         return r;
       
-      r = fwrite(CRLF, 1, sizeof(CRLF) - 1, f);
+      r = claws_fwrite(CRLF, 1, sizeof(CRLF) - 1, f);
       if (r == 0)
         return MAILIMF_ERROR_FILE;
       
@@ -228,7 +217,7 @@ int mailimf_string_write(FILE * f, int * col,
           if (r != MAILIMF_NO_ERROR)
             return r;
           
-          r = fwrite(CRLF, 1, sizeof(CRLF) - 1, f);
+          r = claws_fwrite(CRLF, 1, sizeof(CRLF) - 1, f);
           if (r == 0)
             return MAILIMF_ERROR_FILE;
           
@@ -247,7 +236,7 @@ int mailimf_string_write(FILE * f, int * col,
         if (r != MAILIMF_NO_ERROR)
           return r;
         
-        r = fwrite(CRLF, 1, sizeof(CRLF) - 1, f);
+        r = claws_fwrite(CRLF, 1, sizeof(CRLF) - 1, f);
         if (r == 0)
           return MAILIMF_ERROR_FILE;
         
@@ -1385,29 +1374,29 @@ int mailimf_quoted_string_write(FILE * f, int * col,
   int r;
   size_t i;
 
-  fputc('\"', f);
+  claws_fputc('\"', f);
   for(i = 0 ; i < len ; i ++) {
     switch (string[i]) {
     case '\\':
     case '\"':
-      r = fputc('\\', f);
+      r = claws_fputc('\\', f);
       if (r < 0)
        return MAILIMF_ERROR_FILE;
-      r = fputc(string[i], f);
+      r = claws_fputc(string[i], f);
       if (r < 0)
        return MAILIMF_ERROR_FILE;
       (* col) += 2;
       break;
 
     default:
-      r = fputc(string[i], f);
+      r = claws_fputc(string[i], f);
       if (r < 0)
        return MAILIMF_ERROR_FILE;
       (* col) ++;
       break;
     }
   }
-  fputc('\"', f);
+  claws_fputc('\"', f);
 
   return MAILIMF_NO_ERROR;
 }
index feb2453..b32af40 100644 (file)
  * $Id$
  */
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
+
 #include "mailmbox.h"
 
 #include <sys/file.h>
@@ -54,6 +59,7 @@
 #include "mailmbox_parse.h"
 #include "maillock.h"
 #include "utils.h"
+#include "claws_io.h"
 
 /*
   http://www.qmail.org/qmail-manual-html/man5/mbox.html
index c8a77d8..569d9b7 100644 (file)
@@ -222,17 +222,17 @@ static void read_max_uid_value(FolderItem *item, guint * pmax_uid)
        file = g_strconcat(path, G_DIR_SEPARATOR_S, MAX_UID_FILE, NULL);
        g_free(path);
         
-        f = fopen(file, "r");
+        f = claws_fopen(file, "r");
         g_free(file);
         if (f == NULL)
                 return;
-        r = fread(&max_uid, sizeof(max_uid), 1, f);
+        r = claws_fread(&max_uid, sizeof(max_uid), 1, f);
         if (r == 0) {
-                fclose(f);
+                claws_fclose(f);
                 return;
         }
         
-        fclose(f);
+        claws_fclose(f);
         
         * pmax_uid = max_uid;
 }
@@ -248,17 +248,17 @@ static void write_max_uid_value(FolderItem *item, guint max_uid)
        file = g_strconcat(path, G_DIR_SEPARATOR_S, MAX_UID_FILE, NULL);
        g_free(path);
         
-        f = fopen(file, "w");
+        f = claws_fopen(file, "w");
         g_free(file);
         if (f == NULL)
                 return;
-        r = fwrite(&max_uid, sizeof(max_uid), 1, f);
+        r = claws_fwrite(&max_uid, sizeof(max_uid), 1, f);
         if (r == 0) {
-                fclose(f);
+                claws_fclose(f);
                 return;
         }
         
-        safe_fclose(f);
+        claws_safe_fclose(f);
 }
 
 static void claws_mailmbox_folder_item_destroy(Folder *folder, FolderItem *_item)
@@ -463,21 +463,21 @@ static gchar *s_claws_mailmbox_fetch_msg(Folder *folder, FolderItem *item, gint
                 goto free;
         
         old_mask = umask(0077);
-        f = fopen(file, "w");
+        f = claws_fopen(file, "w");
         umask(old_mask);
         if (f == NULL)
                 goto free;
         
-        r = fwrite(data, 1, len, f);
+        r = claws_fwrite(data, 1, len, f);
         if (r == 0)
                 goto close;
         
-        safe_fclose(f);
+        claws_safe_fclose(f);
         
        return file;
         
  close:
-        fclose(f);
+        claws_fclose(f);
         unlink(file);
  free:
         free(file);
index 46bc1bc..b8c483c 100644 (file)
@@ -31,6 +31,7 @@
 #include <inttypes.h>
 
 #include "plugin.h"
+#include "claws_io.h"
 
 #define LOG_NAME       "NewLog"
 #define DEFAULT_DIR    "Mail"
@@ -83,7 +84,7 @@ gboolean newmail_hook (gpointer source, gpointer data)
 gboolean plugin_done (void)
 {
        if (NewLog) {
-               (void)fclose (NewLog);
+               (void)claws_fclose (NewLog);
                NewLog  = NULL;
        }
        if (LogName) {
@@ -118,12 +119,12 @@ gint plugin_init (gchar **error)
                        LogName = g_strconcat(g_getenv ("HOME"), G_DIR_SEPARATOR_S, DEFAULT_DIR,
                                        G_DIR_SEPARATOR_S, LOG_NAME, NULL);
                }
-               if (!(NewLog = fopen (LogName, mode))) {
+               if (!(NewLog = claws_fopen (LogName, mode))) {
                        debug_print ("Failed to open default log %s\n", LogName);
                        /* try fallback location */
                        g_free(LogName);
                        LogName = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, LOG_NAME, NULL);
-                       if (!(NewLog = fopen (LogName, mode))) {
+                       if (!(NewLog = claws_fopen (LogName, mode))) {
                                debug_print ("Failed to open fallback log %s\n", LogName);
                                *error = g_strdup_printf(_("Could not open log file %s: %s\n"),
                                                LogName, g_strerror(errno));
index afeb83c..a4bdda0 100644 (file)
@@ -45,6 +45,7 @@
 #include "common/log.h"
 #include "common/plugin.h"
 #include "common/tags.h"
+#include "claws_io.h"
 
 #include <EXTERN.h>
 #include <perl.h>
@@ -661,8 +662,8 @@ static XS(XS_ClawsMail_open_mail_file)
   file = procmsg_get_message_file_path(msginfo);
   if(!file)
     XSRETURN_UNDEF;
-  if((message_file = fopen(file, "rb")) == NULL) {
-    FILE_OP_ERROR(file, "fopen");
+  if((message_file = claws_fopen(file, "rb")) == NULL) {
+    FILE_OP_ERROR(file, "claws_fopen");
     g_warning("Perl Plugin: File open error in ClawsMail::C::open_mail_file");
     g_free(file);
     XSRETURN_UNDEF;
@@ -679,7 +680,7 @@ static XS(XS_ClawsMail_close_mail_file)
     XSRETURN_UNDEF;
   }
   if(message_file != NULL)
-    fclose(message_file);
+    claws_fclose(message_file);
   XSRETURN_YES;
 }
 
@@ -731,7 +732,7 @@ static XS(XS_ClawsMail_get_next_body_line)
     g_warning("Perl Plugin: Message file not open. Use ClawsMail::C::open_message_file first.");
     XSRETURN_UNDEF;
   }
-  if(fgets(buf, sizeof(buf), message_file) != NULL)
+  if(claws_fgets(buf, sizeof(buf), message_file) != NULL)
     XSRETURN_PV(buf);
   else
     XSRETURN_UNDEF;
@@ -2310,7 +2311,7 @@ gint plugin_init(gchar **error)
 
   /* make sure we have at least an empty scriptfile */
   perlfilter = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, PERLFILTER, NULL);
-  if((fp = fopen(perlfilter, "a")) == NULL) {
+  if((fp = claws_fopen(perlfilter, "a")) == NULL) {
     *error = g_strdup("Failed to create blank scriptfile");
     g_free(perlfilter);
     hooks_unregister_hook(MAIL_FILTERING_HOOKLIST,
@@ -2324,7 +2325,7 @@ gint plugin_init(gchar **error)
     FILE_OP_ERROR(perlfilter, "chmod");
     g_warning("Perl Plugin: Can't change file mode");
   }
-  fclose(fp);
+  claws_fclose(fp);
   g_free(perlfilter);
 
   argc = 1;
index be6aaf1..87a931d 100644 (file)
@@ -9,6 +9,10 @@ alertpanel_notice
 check_plugin_version
 claws_do_idle
 claws_unlink
+claws_fopen
+claws_fdopen
+claws_fclose
+claws_safe_fclose
 conv_codeset_strdup
 conv_get_locale_charset_str_no_utf8
 codeconv_set_strict
index 66f8e9b..8d3e95c 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "pgp_utils.h"
 #include "codeconv.h"
+#include "claws_io.h"
 
 gchar *fp_read_noconv(FILE *fp)
 {
@@ -42,14 +43,14 @@ gchar *fp_read_noconv(FILE *fp)
                return NULL;
        array = g_byte_array_new();
 
-       while ((n_read = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
-               if (n_read < sizeof(buf) && ferror(fp))
+       while ((n_read = claws_fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
+               if (n_read < sizeof(buf) && claws_ferror(fp))
                        break;
                g_byte_array_append(array, buf, n_read);
        }
 
-       if (ferror(fp)) {
-               FILE_OP_ERROR("file stream", "fread");
+       if (claws_ferror(fp)) {
+               FILE_OP_ERROR("file stream", "claws_fread");
                g_byte_array_free(array, TRUE);
                return NULL;
        }
@@ -80,14 +81,14 @@ gchar *get_part_as_string(MimeInfo *mimeinfo)
                        g_free(filename);
                        return NULL;
                }
-               fp = g_fopen(filename,"rb");
+               fp = claws_fopen(filename,"rb");
                if (!fp) {
                        g_warning("error opening temporary file '%s'", filename);
                        g_free(filename);
                        return NULL;
                }
                textdata = fp_read_noconv(fp);
-               fclose(fp);
+               claws_fclose(fp);
                g_unlink(filename);
                g_free(filename);
        }
index f79c8b6..6586295 100644 (file)
@@ -59,6 +59,7 @@
 #include "account.h"
 #include "select-keys.h"
 #include "claws.h"
+#include "claws_io.h"
 
 static void sgpgme_disable_all(void)
 {
@@ -453,13 +454,13 @@ gpgme_data_t sgpgme_data_from_mimeinfo(MimeInfo *mimeinfo)
 {
        gpgme_data_t data = NULL;
        gpgme_error_t err;
-       FILE *fp = g_fopen(mimeinfo->data.filename, "rb");
+       FILE *fp = claws_fopen(mimeinfo->data.filename, "rb");
 
        if (!fp) 
                return NULL;
 
        err = gpgme_data_new_from_filepart(&data, NULL, fp, mimeinfo->offset, mimeinfo->length);
-       fclose(fp);
+       claws_fclose(fp);
 
        debug_print("data %p (%d %d)\n", (void *)&data, mimeinfo->offset, mimeinfo->length);
        if (err) {
index a07c65f..4162a99 100644 (file)
@@ -1,6 +1,10 @@
 LIBRARY CLAWS-MAIL.EXE
 EXPORTS
 claws_unlink
+claws_fopen
+claws_fdopen
+claws_fclose
+claws_safe_fclose
 check_plugin_version
 codeconv_set_strict
 conv_codeset_strdup
@@ -22,4 +26,3 @@ procmime_scan_file
 procmime_write_mimeinfo
 procmime_get_part
 procmime_get_tmp_file_name
-safe_fclose
\ No newline at end of file
index 4f8e789..d4bee07 100644 (file)
@@ -341,8 +341,8 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo)
        fname = g_strdup_printf("%s%cplaintext.%08x",
                get_mime_tmp_dir(), G_DIR_SEPARATOR, ++id);
 
-       if ((dstfp = g_fopen(fname, "wb")) == NULL) {
-               FILE_OP_ERROR(fname, "fopen");
+       if ((dstfp = claws_fopen(fname, "wb")) == NULL) {
+               FILE_OP_ERROR(fname, "claws_fopen");
                privacy_set_error(_("Couldn't open decrypted file %s"), fname);
                g_free(fname);
                gpgme_data_release(plain);
@@ -367,24 +367,24 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo)
        /* Store any part before encrypted text */
        pos = pgp_locate_armor_header(textdata, begin_indicator);
        if (pos != NULL && (pos - textdata) > 0) {
-           if (fwrite(textdata, 1, pos - textdata, dstfp) < pos - textdata) {
-               FILE_OP_ERROR(fname, "fwrite");