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 c6ef76f0f064eead50229cbe731f408e06478f6d..a5f1bc95d3e871a386b8fe6739e72a5e1238e084 100644 (file)
@@ -180,7 +180,7 @@ if test x"$_gcc_psign" = xyes ; then
        CFLAGS="$CFLAGS -Wno-pointer-sign"
 fi
 
        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"
 
 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)
 
               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 **
 
 dnl *****************
 dnl ** common code **
index e73a0127a1b4e999415351da9067843e9ddf737e..285257bc5110c849ce8a0fb6bb54567079cf3ae7 100644 (file)
@@ -55,6 +55,7 @@
 #include "prefs_actions.h"
 #include "hooks.h"
 #include "passwordstore.h"
 #include "prefs_actions.h"
 #include "hooks.h"
 #include "passwordstore.h"
+#include "claws_io.h"
 
 enum {
        ACCOUNT_IS_DEFAULT,
 
 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);
        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);
 
                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);
                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));
                }
        }
                                                       g_strdup(buf));
                }
        }
-       fclose(fp);
+       claws_fclose(fp);
 
        /* read config data from file */
        cur_account = NULL;
 
        /* read config data from file */
        cur_account = NULL;
index 0720c6bc4987b8852521bfbf1a3c104fb9a7ed9e..64a36457909c075f189fedfb4fa953e21a2e3ce9 100644 (file)
 
 /* General functions for accessing address book files */
 
 
 /* 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>
 #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++) 
 {
        gint i;
        for (i = 0; i < lvl; i++) 
-               if (fputs("  ", fp) == EOF)
+               if (claws_fputs("  ", fp) == EOF)
                        return -1;
                        return -1;
-       if (fputs("<", fp) == EOF)
+       if (claws_fputs("<", fp) == EOF)
                return -1;
                return -1;
-       if (fputs(name, fp) == EOF)
+       if (claws_fputs(name, fp) == EOF)
                return -1;
                
        return 0;
                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++)
 {
        gint i;
        for(i = 0; i < lvl; i++)
-               if (fputs("  ", fp) == EOF)
+               if (claws_fputs("  ", fp) == EOF)
                        return -1;
                        return -1;
-       if (fputs("</", fp) == EOF)
+       if (claws_fputs("</", fp) == EOF)
                return -1;
                return -1;
-       if (fputs(name, fp) == EOF)
+       if (claws_fputs(name, fp) == EOF)
                return -1;
                return -1;
-       if (fputs(">\n", fp) == EOF)
+       if (claws_fputs(">\n", fp) == EOF)
                return -1;
                
        return 0;
                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)
 {
  */
 static int addrbook_write_attr(FILE *fp, gchar *name, gchar *value)
 {
-       if (fputs(" ", fp) == EOF)
+       if (claws_fputs(" ", fp) == EOF)
                return -1;
                return -1;
-       if (fputs(name, fp) == EOF)
+       if (claws_fputs(name, fp) == EOF)
                return -1;
                return -1;
-       if (fputs("=\"", fp) == EOF)
+       if (claws_fputs("=\"", fp) == EOF)
                return -1;
        if (xml_file_put_escape_str(fp, value) < 0)
                return -1;
                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;
                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;
                                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;
                                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) {
                                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;
                                        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);
                        }
                                        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;
                        /* 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) {
                                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;
                                        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;
                                        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;
                                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;
                                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) {
                                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;
                                        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);
                        }
                                        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;
                                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;
                                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 */
                                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;
                                        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);
                        }
                                        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;
                                        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);
                        }
                                        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;
                                        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);
                        }
                                        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
 
        book->retVal = MGU_OPEN_FILE;
 #ifdef DEV_STANDALONE
-       fp = g_fopen(fileSpec, "wb");
+       fp = claws_fopen(fileSpec, "wb");
        g_free(fileSpec);
        if (fp) {
        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;
                }
                        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 (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 */
                        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
 
                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;
 #else
                if (prefs_file_close( pfile ) < 0)
                        book->retVal = MGU_ERROR_WRITE;
index 6d4bf3b6597b9f0714a5594a8de5d9c55cea6e75..1d94633ccb0f808dc2fab16cd00203051c7f1e93 100644 (file)
  * Functions for an E-Mail address harvester.
  */
 
  * 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>
 #include <sys/stat.h>
 #include <dirent.h>
 #include <glib.h>
@@ -35,6 +40,7 @@
 #ifdef USE_ALT_ADDRBOOK
        #include "addressbook-dbus.h"
 #endif
 #ifdef USE_ALT_ADDRBOOK
        #include "addressbook-dbus.h"
 #endif
+#include "claws_io.h"
 
 /* Mail header names of interest */
 static gchar *_headerFrom_     = HEADER_FROM;
 
 /* 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 */
        list = NULL;
 
        /* Read line */
-       if( fgets( buf, MSG_BUFFSIZE, fp ) == NULL ) {
+       if( claws_fgets( buf, MSG_BUFFSIZE, fp ) == NULL ) {
                *done = TRUE;
                return list;
        }
                *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 */
                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;
                        }
                }
                                break;
                        }
                }
@@ -708,7 +714,7 @@ static gint addrharvest_readfile(
        GSList *list;
        gboolean done;
 
        GSList *list;
        gboolean done;
 
-       msgFile = g_fopen( fileName, "rb" );
+       msgFile = claws_fopen( fileName, "rb" );
        if( ! msgFile ) {
                /* Cannot open file */
                retVal = MGU_OPEN_FILE;
        if( ! msgFile ) {
                /* Cannot open file */
                retVal = MGU_OPEN_FILE;
@@ -747,7 +753,7 @@ static gint addrharvest_readfile(
                g_free( buf );
        }
 
                g_free( buf );
        }
 
-       fclose( msgFile );
+       claws_fclose( msgFile );
        return MGU_SUCCESS;
 }
 
        return MGU_SUCCESS;
 }
 
index f1adf01be739f54cfbef2006b5290a30ea51311c..bad1fa5d72c5004d44bb40e505f83e202d02e89b 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++ ) 
 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;
                        return -1;
-       if (fputs( "<", fp ) == EOF)
+       if (claws_fputs( "<", fp ) == EOF)
                return -1;
                return -1;
-       if (fputs( name, fp ) == EOF)
+       if (claws_fputs( name, fp ) == EOF)
                return -1;
        return 0;
 }
                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++ ) 
 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;
                        return -1;
-       if (fputs( "</", fp ) == EOF)
+       if (claws_fputs( "</", fp ) == EOF)
                return -1;
                return -1;
-       if (fputs( name, fp ) == EOF)
+       if (claws_fputs( name, fp ) == EOF)
                return -1;
                return -1;
-       if (fputs( ">\n", fp ) == EOF)
+       if (claws_fputs( ">\n", fp ) == EOF)
                return -1;
        return 0;
 }
                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 ) {
  * \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;
                return -1;
-       if (fputs( name, fp ) == EOF)
+       if (claws_fputs( name, fp ) == EOF)
                return -1;
                return -1;
-       if (fputs( "=\"", fp ) == EOF)
+       if (claws_fputs( "=\"", fp ) == EOF)
                return -1;
        if (xml_file_put_escape_str( fp, value ) < 0)
                return -1;
                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;
 }
                return -1;
        return 0;
 }
@@ -1071,7 +1071,7 @@ static int addrindex_write_fragment(
                        node = g_list_next( node );
                }
                if( fragment->children ) {
                        node = g_list_next( node );
                }
                if( fragment->children ) {
-                       if (fputs(" >\n", fp) == EOF)
+                       if (claws_fputs(" >\n", fp) == EOF)
                                return -1;
 
                        /* Output children */
                                return -1;
 
                        /* Output children */
@@ -1088,7 +1088,7 @@ static int addrindex_write_fragment(
                                return -1;
                }
                else {
                                return -1;
                }
                else {
-                       if (fputs(" />\n", fp) == EOF)
+                       if (claws_fputs(" />\n", fp) == EOF)
                                return -1;
                }
        }
                                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;
                        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;
                        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;
                        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;
                        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 );
                }
                        ind++;
                        node = g_list_next( node );
                }
-               if (fputs( " />\n", fp ) == EOF)
+               if (claws_fputs( " />\n", fp ) == EOF)
                        return -1;
        }
        return 0;
                        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;
 
                        ATVAL_BOOLEAN_YES : ATVAL_BOOLEAN_NO ) < 0)
                return -1;
 
-       if (fputs(" >\n", fp) == EOF)
+       if (claws_fputs(" >\n", fp) == EOF)
                return -1;
 
        /* Output attributes */
                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;
                        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 );
        }
                        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;
                        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;
                                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
        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 ) {
        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 );
 #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;
 #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)
                        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
 
                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;
 #else
                if( prefs_file_close( pfile ) < 0 ) {
                        addrIndex->retVal = MGU_ERROR_WRITE;
index ccfad6c9c2531eb805658a27cf739a40b157456b..85dc3cc2d8ac245e3d5972b85b7a18e3a9338bee 100644 (file)
@@ -31,6 +31,7 @@
 #include "matcher_parser.h"
 #include "utils.h"
 #include "prefs_common.h"
 #include "matcher_parser.h"
 #include "utils.h"
 #include "prefs_common.h"
+#include "timing.h"
 
 struct _AdvancedSearch {
        struct {
 
 struct _AdvancedSearch {
        struct {
@@ -502,27 +503,33 @@ static gboolean search_impl(MsgInfoList **messages, AdvancedSearch* search,
                            FolderItem* folderItem, gboolean recursive)
 {
        if (recursive) {
                            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;
                        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 (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;
                                        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;
        } 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);
                if (!search_filter_folder(&msgnums, search, folderItem,
                                          can_search_on_server)) {
                        g_slist_free(msgnums);
+                       END_TIMING();
                        return FALSE;
                }
 
                        return FALSE;
                }
 
@@ -542,6 +549,7 @@ static gboolean search_impl(MsgInfoList **messages, AdvancedSearch* search,
                }
 
                g_slist_free(msgnums);
                }
 
                g_slist_free(msgnums);
+               END_TIMING();
        }
 
        return TRUE;
        }
 
        return TRUE;
index 6146f6580610f1e021e6a6ad2682b727d7b743d1..d12c9756c8c116f1cb2bb7f0b3782810d85bf4a7 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "utils.h"
 #include "autofaces.h"
 
 #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)
 {
 
 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';
        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;
        }
                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];
                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;
        g_free(xfile);
 
        return 0;
index 1de8bea856345c034f2e59767e45278683da26d2..62689780d153665a751b445d44e89e67aef16d4f 100644 (file)
 #include <unistd.h>
 
 #include "timing.h"
 #include <unistd.h>
 
 #include "timing.h"
+#include "claws_io.h"
 
 gboolean prefs_common_get_flush_metadata(void);
 
 
 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;
 int safe_fclose(FILE *fp)
 {
        int r;
@@ -45,3 +47,47 @@ int safe_fclose(FILE *fp)
 
        return r;
 }
 
        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 e3e0e0ce5b6808455ddcd90d21b80deb908a2918..35edae381be83abf95d2ea19c29fcaffcc0b496c 100644 (file)
 #ifndef __CLAWS_IO_H__
 #define __CLAWS_IO_H__
 
 #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
 int safe_fclose(FILE *fp);
 
 #endif
index 65f284e64717fc94e4080769dd8370f46d2a3897..15a852b79ac50c74cdc44027ed79c61b91cbea3b 100644 (file)
@@ -28,7 +28,6 @@
 #  include <w32lib.h>
 #endif
 
 #  include <w32lib.h>
 #endif
 
-#include <stdio.h>
 #include <glib.h>
 #include <glib/gi18n.h>
 
 #include <glib.h>
 #include <glib/gi18n.h>
 
 #include "hooks.h"
 #include "claws_io.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; \
                                }
                                        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) { \
                                        return; \
                                }
 #define FFLUSH(_f)             if (fflush(_f) != 0) { \
@@ -122,9 +121,9 @@ void set_log_file(LogInstance instance, const gchar *filename)
                g_free(backupname);
        }
 
                g_free(backupname);
        }
 
-       log_fp[instance] = g_fopen(fullname, "wb");
+       log_fp[instance] = claws_fopen(fullname, "wb");
        if (!log_fp[instance]) {
        if (!log_fp[instance]) {
-               FILE_OP_ERROR(fullname, "fopen");
+               FILE_OP_ERROR(fullname, "claws_fopen");
                log_filename[instance] = NULL;
                g_free(fullname);
                return;
                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]) {
 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]);
                log_fp[instance] = NULL;
                log_size[instance] = 0;
                g_free(log_filename[instance]);
index 64a6f017e5e460b3a722cdea6918096e542e4d0e..963b16d57573a941af5919f54a1db7dbda84a1c0 100644 (file)
@@ -41,6 +41,7 @@
 #include "prefs.h"
 #include "claws.h"
 #include "timing.h"
 #include "prefs.h"
 #include "claws.h"
 #include "timing.h"
+#include "claws_io.h"
 
 #ifdef G_OS_WIN32
 #define PLUGINS_BLOCK_PREFIX "PluginsWin32_"
 
 #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);
        
        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;
        
        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 */
                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);
                        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;
                                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));
                }
        }
                                        g_strdup(filename));
                }
        }
-       fclose(fp);
+       claws_fclose(fp);
        return 0;
 }
 
        return 0;
 }
 
@@ -605,7 +606,7 @@ void plugin_load_all(const gchar *type)
        }
        g_free(block);
 
        }
        g_free(block);
 
-       while (fgets(buf, sizeof(buf), pfile->fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), pfile->fp) != NULL) {
                if (buf[0] == '[')
                        break;
 
                if (buf[0] == '[')
                        break;
 
index 77b4213284e7a721dd0a92cc2c18b9f9c3d6584a..971193eeb58ce9ae191eee8cdd17bce75dc23a5a 100644 (file)
@@ -22,6 +22,8 @@
 #include "claws-features.h"
 #endif
 
 #include "claws-features.h"
 #endif
 
+#include <stdio.h>
+
 #include "defs.h"
 
 #include <glib.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);
 
 
        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;
        }
 
                return NULL;
        }
 
@@ -83,8 +85,8 @@ PrefFile *prefs_write_open(const gchar *path)
        }
 
        tmppath = g_strconcat(path, ".tmp", NULL);
        }
 
        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;
        }
                g_free(tmppath);
                return NULL;
        }
@@ -128,17 +130,17 @@ gint prefs_file_close(PrefFile *pfile)
        path = pfile->path;
 
        if (!pfile->writing) {
        path = pfile->path;
 
        if (!pfile->writing) {
-               fclose(fp);
+               claws_fclose(fp);
                g_free(pfile);
                g_free(path);
                return 0;
        }
 
        if (orig_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] == '[') {
                        /* 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);
                                
                                        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;
                        }
                                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);
 
        }
 
        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);
                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)
        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);
        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);
        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) {
 
        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));
                        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 {
                        }
                }
        } 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;
 
                        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));
                                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 {
                                        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);
                                                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) {
                        }
 
                        if (!block_matched) {
-                               fclose(pfile->orig_fp);
+                               claws_fclose(pfile->orig_fp);
                                pfile->orig_fp = NULL;
                        }
                }
 
                                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);
                        g_warning("failed to write configuration to file");
                        prefs_file_close_revert(pfile);
                        g_free(block_label);
index d098ac24be185d58be17debab4f0d4c1e4528dcb..8afe4da354a0609b21f7819b002dc0c66af77723 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);
        }
 
        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));
        }
 }
                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;
        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;
                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;
        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;
        }
                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;
        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);
                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);
        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");
        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);
        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);
        
        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);
        }
        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);
 
                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);
        }
 
                gnutls_x509_crt_deinit(tmp_x509);
        }
 
-       fclose(fp);
+       claws_fclose(fp);
        g_free(file);
        
        if (must_rename) {
        g_free(file);
        
        if (must_rename) {
@@ -531,7 +531,7 @@ static guint check_cert(SSLCertificate *cert)
        FILE *fp;
 
        if (claws_ssl_get_cert_file())
        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;
 
        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));
 
        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;
        }
                return (guint)-1;
        }
-       fclose(fp);
+       claws_fclose(fp);
        fp = NULL;
        
        buf = g_strdup_printf("%d", cert->port);
        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;
 
                size_t n = 128;
                char *fingerprint;
 
-               fp = g_fopen(chain_file, "r");
+               fp = claws_fopen(chain_file, "r");
                if (fp == NULL) {
                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));
                        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);
                        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);
                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);
 
 
                        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");
                        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)
 
        }
        if (fp)
-               safe_fclose(fp);
+               claws_safe_fclose(fp);
 }
 
 gboolean ssl_certificate_check (gnutls_x509_crt_t x509_cert, guint status, 
 }
 
 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()) {
        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);
                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)
                }
 
                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)) {
                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);
                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"),
                        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)) {
                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);
                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"),
                        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)) {
                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);
                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);
                        }
                        if (!p12) {
                                log_error(LOG_PROTOCOL, _("Failed to read P12 certificate file %s\n"), file);
                        }
index 264f1397bbc5303adac85aa0b4fa2d964fb91fc2..408632393e53d2f147324523b43ef603037b4f7f 100644 (file)
@@ -53,7 +53,7 @@ void tags_read_tags(void)
                        TAGS_RC, NULL);
        gchar tmp[255];
        gint id;
                        TAGS_RC, NULL);
        gchar tmp[255];
        gint id;
-       FILE *fp = g_fopen(file, "rb");
+       FILE *fp = claws_fopen(file, "rb");
        
        g_free(file);
 
        
        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) {
        if (!fp) 
                return;
        if (fscanf(fp, "max_id %d\n", &tag_max_id) != 1) {
-               fclose(fp);
+               claws_fclose(fp);
                return;
        }
                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;
                
                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
 }
 
 typedef struct _TagWriteData
@@ -121,10 +121,10 @@ void tags_write_tags(void)
                        TAGS_RC, NULL);
        TagWriteData data;
 
                        TAGS_RC, NULL);
        TagWriteData data;
 
-       FILE *fp = g_fopen(file, "wb");
+       FILE *fp = claws_fopen(file, "wb");
                        
        if (!fp) {
                        
        if (!fp) {
-               FILE_OP_ERROR(file, "g_fopen");
+               FILE_OP_ERROR(file, "claws_fopen");
                g_free(file);
                g_free(file_new);
                return;
                g_free(file);
                g_free(file_new);
                return;
@@ -141,14 +141,14 @@ void tags_write_tags(void)
        }
 
        if (data.error) {
        }
 
        if (data.error) {
-               fclose(fp);
+               claws_fclose(fp);
                g_free(file);
                g_free(file_new);
                return;
        }
        
                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;
                g_free(file);
                g_free(file_new);
                return;
index e8db301c37828b7a45d9ce7e605ebccf311ea1b8..8ae5fde42506fc4146f8109433b1641c05bf7d6b 100644 (file)
@@ -40,8 +40,8 @@ static Template *template_load(gchar *filename)
        gchar buf[BUFFSIZE];
        gint bytes_read;
 
        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;
        }
 
                return NULL;
        }
 
@@ -56,7 +56,7 @@ static Template *template_load(gchar *filename)
        tmpl->replyto = NULL;
        tmpl->value = NULL;
 
        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))
                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);
        if (!tmpl->name) {
                g_warning("wrong template format");
                template_free(tmpl);
-               fclose(fp);
+               claws_fclose(fp);
                return NULL;
        }
 
                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);
                        template_free(tmpl);
-                       fclose(fp);
+                       claws_fclose(fp);
                        return NULL;
                }
        }
                        return NULL;
                }
        }
-       fclose(fp);
+       claws_fclose(fp);
        tmpl->value = g_strndup(buf, bytes_read);
 
        return tmpl;
        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 (!(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); \
        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);
                }
 
                        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;
                        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);
 
                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') {
 
                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 {
                } 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) {
 
                if (new) {
                        if (rename_force(new, filename) < 0) {
index 977eda4bb8161527b7581c629196cd9e1ac1ce59..aaae7b22b00bcb170a4b8d8df755bd89e50348d0 100644 (file)
@@ -322,27 +322,27 @@ gint file_strip_crs(const gchar *file)
        if (file == NULL)
                goto freeout;
 
        if (file == NULL)
                goto freeout;
 
-       fp = g_fopen(file, "rb");
+       fp = claws_fopen(file, "rb");
        if (!fp)
                goto freeout;
 
        if (!fp)
                goto freeout;
 
-       outfp = g_fopen(out, "wb");
+       outfp = claws_fopen(out, "wb");
        if (!outfp) {
        if (!outfp) {
-               fclose(fp);
+               claws_fclose(fp);
                goto freeout;
        }
 
                goto freeout;
        }
 
-       while (fgets(buf, sizeof (buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof (buf), fp) != NULL) {
                strcrchomp(buf);
                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;
                }
        }
 
                        goto unlinkout;
                }
        }
 
-       fclose(fp);
-       if (safe_fclose(outfp) == EOF) {
+       claws_fclose(fp);
+       if (claws_safe_fclose(outfp) == EOF) {
                goto unlinkout;
        }
        
                goto unlinkout;
        }
        
@@ -2419,14 +2419,14 @@ gint append_file(const gchar *src, const gchar *dest, gboolean keep_backup)
 
        gboolean err = FALSE;
 
 
        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;
        }
 
                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;
        }
 
                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);
        }
 
                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;
                        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);
                        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;
                }
        }
 
                        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;
        }
                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;
        }
 
                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;
 
        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");
                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;
                }
        }
 
                        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");
                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);
        }
 
                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;
                        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);
                        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)
                        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;
        }
                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;
        }
 
                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));
 
        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;
                        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;
                        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));
        }
 
                to_read = MIN(bytes_left, sizeof(buf));
        }
 
-       if (ferror(fp)) {
-               perror("fread");
+       if (claws_ferror(fp)) {
+               perror("claws_fread");
                return -1;
        }
 
                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;
 
        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;
        }
 
                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 (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;
        }
 
                err = TRUE;
        }
 
@@ -2682,14 +2682,14 @@ gint canonicalize_file(const gchar *src, const gchar *dest)
        if (src == NULL || dest == NULL)
                return -1;
 
        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;
        }
 
                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;
        }
 
                return -1;
        }
 
@@ -2698,7 +2698,7 @@ gint canonicalize_file(const gchar *src, const gchar *dest)
                g_warning("can't change file mode: %s", 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);
                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;
 
                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') {
                } 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) {
                } 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)
                                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);
                }
 
                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) {
                        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;
        }
 
                        err = TRUE;
        }
 
-       if (ferror(src_fp)) {
-               FILE_OP_ERROR(src, "fgets");
+       if (claws_ferror(src_fp)) {
+               FILE_OP_ERROR(src, "claws_fgets");
                err = TRUE;
        }
                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;
        }
 
                err = TRUE;
        }
 
@@ -2802,7 +2802,7 @@ gchar *get_outgoing_rfc2822_str(FILE *fp)
        str = g_string_new(NULL);
 
        /* output header part */
        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;
                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;
                                }
                                        ungetc(next, fp);
                                        break;
                                }
-                               if (fgets(buf, sizeof(buf), fp) == NULL)
+                               if (claws_fgets(buf, sizeof(buf), fp) == NULL)
                                        break;
                        }
                } else {
                                        break;
                        }
                } else {
@@ -2827,7 +2827,7 @@ gchar *get_outgoing_rfc2822_str(FILE *fp)
        }
 
        /* output body part */
        }
 
        /* 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, '.');
                strretchomp(buf);
                if (buf[0] == '.')
                        g_string_append_c(str, '.');
@@ -2926,7 +2926,7 @@ FILE *my_tmpfile(void)
        
 #endif
 
        
 #endif
 
-       fp = fdopen(fd, "w+b");
+       fp = claws_fdopen(fd, "w+b");
        if (!fp)
                close(fd);
        else {
        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;
        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)
 }
 
 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;
 
        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;
        }
 
                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);
 
        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) {
                return -1;
        }
 
        len = strlen(str);
        if (len == 0) {
-               fclose(fp);
+               claws_fclose(fp);
                return 0;
        }
 
                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;
        }
 
                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;
        }
                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();
 
 
        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);
        }
 
                        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;
        }
                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
        }
 
 #ifdef G_OS_WIN32
-       fp = g_fopen (file, "rb");
+       fp = claws_fopen (file, "rb");
        if (fp == NULL) {
                FILE_OP_ERROR(file, "open");
                return NULL;
        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 */
        }
        
        /* get the FILE pointer */
-       fp = fdopen(fd, "rb");
+       fp = claws_fdopen(fd, "rb");
 
        if (fp == NULL) {
 
        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);
 
                return NULL;
        }
 #endif
 
        str = file_read_stream_to_str_full(fp, recode);
 
-       fclose(fp);
+       claws_fclose(fp);
 
        return str;
 }
 
        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)
 {
 
 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;
        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')
                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);
                                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);
                        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);
        }
                }
                g_strfreev(parts);
        }
-       fclose(fp);
+       claws_fclose(fp);
        return NULL;
 }
 gchar *mailcap_get_command_for_type(const gchar *type, const gchar *file_to_open)
        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);
        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) {
        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);
                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);
        if (!outfp) {
                g_warning("failed to create file %s", outpath);
                g_free(path);
                g_free(outpath);
-               fclose(fp);
+               claws_fclose(fp);
                return;
        }
                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] == ' ')
                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 {
                        continue;
                }
                else {
-                       if(fputs(buf, outfp) == EOF) {
+                       if(claws_fputs(buf, outfp) == EOF) {
                                err = TRUE;
                                break;
                        }
                                err = TRUE;
                                break;
                        }
@@ -4580,9 +4580,9 @@ void mailcap_update_default(const gchar *type, const gchar *command)
                err = TRUE;
 
        if (fp)
                err = TRUE;
 
        if (fp)
-               fclose(fp);
+               claws_fclose(fp);
 
 
-       if (safe_fclose(outfp) == EOF)
+       if (claws_safe_fclose(outfp) == EOF)
                err = TRUE;
                
        if (!err)
                err = TRUE;
                
        if (!err)
@@ -4655,10 +4655,10 @@ gboolean file_is_email (const gchar *filename)
        gint score = 0;
        if (filename == NULL)
                return FALSE;
        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
                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:")))
                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++;
        }
                        score++;
                i++;
        }
-       fclose(fp);
+       claws_fclose(fp);
        return (score >= 3);
 }
 
        return (score >= 3);
 }
 
index 45fcd3001db65ab786f6b5b20dd2efaca7aaedc7..50cc9a5e8935567f6ea3eaf61869a03bec49139b 100644 (file)
  * 
  */
 
  * 
  */
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
+
 #include <glib.h>
 #include <stdio.h>
 #include <string.h>
 #include <glib.h>
 #include <stdio.h>
 #include <string.h>
@@ -25,6 +30,7 @@
 #include "xml.h"
 #include "utils.h"
 #include "codeconv.h"
 #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
 
 #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 = g_new(XMLFile, 1);
 
-       newfile->fp = g_fopen(path, "rb");
+       newfile->fp = claws_fopen(path, "rb");
        if (!newfile->fp) {
                g_free(newfile);
                return NULL;
        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->level = 0;
        newfile->is_empty_element = FALSE;
 
+       newfile->path = g_strdup(path);
+
        return newfile;
 }
 
        return newfile;
 }
 
@@ -104,12 +112,13 @@ void xml_close_file(XMLFile *file)
 {
        cm_return_if_fail(file != NULL);
 
 {
        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_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);
 
        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) {
        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;
                }
 
                        break;
                }
 
@@ -191,7 +200,7 @@ gint xml_get_dtd(XMLFile *file)
                        file->need_codeconv = FALSE;
                }
        } else {
                        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;
        }
 
                return -1;
        }
 
@@ -214,7 +223,7 @@ next:
        }
 
        if (xml_get_parenthesis(file, buf, sizeof(buf)) < 0) {
        }
 
        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;
        }
 
                return -1;
        }
 
@@ -223,7 +232,7 @@ next:
        /* end-tag */
        if (buf[0] == '/') {
                if (strcmp(xml_get_current_tag(file)->tag, buf + 1) != 0) {
        /* 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);
                        return -1;
                }
                xml_pop_tag(file);
@@ -245,7 +254,7 @@ next:
        }
        
        if (strlen(buf) == 0) {
        }
        
        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;
        }
 
                return -1;
        }
 
@@ -287,7 +296,7 @@ next:
                while (g_ascii_isspace(*bufp)) bufp++;
                attr_name = bufp;
                if ((p = strchr(attr_name, '=')) == NULL) {
                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;
                        return -1;
                }
                bufp = p;
@@ -295,14 +304,14 @@ next:
                while (g_ascii_isspace(*bufp)) bufp++;
 
                if (*bufp != '"' && *bufp != '\'') {
                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) {
                        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;
                        return -1;
                }
                bufp = p;
@@ -414,7 +423,7 @@ static gint xml_read_line(XMLFile *file)
        gchar buf[XMLBUFSIZE];
        gint index;
 
        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;
                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 '<':
        for (p = str; *p != '\0'; p++) {
                switch (*p) {
                case '<':
-                       result = fputs("&lt;", fp);
+                       result = claws_fputs("&lt;", fp);
                        break;
                case '>':
                        break;
                case '>':
-                       result = fputs("&gt;", fp);
+                       result = claws_fputs("&gt;", fp);
                        break;
                case '&':
                        break;
                case '&':
-                       result = fputs("&amp;", fp);
+                       result = claws_fputs("&amp;", fp);
                        break;
                case '\'':
                        break;
                case '\'':
-                       result = fputs("&apos;", fp);
+                       result = claws_fputs("&apos;", fp);
                        break;
                case '\"':
                        break;
                case '\"':
-                       result = fputs("&quot;", fp);
+                       result = claws_fputs("&quot;", fp);
                        break;
                default:
                        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++)
 
        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;
 
 
        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(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;
                
        }
 
        if (node->children) {
                GNode *child;
-               TRY(fputs(">\n", fp) != EOF);
+               TRY(claws_fputs(">\n", fp) != EOF);
 
                child = node->children;
                while (child) {
 
                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++)
                }
 
                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(fprintf(fp, "</%s>\n", tag->tag) > 0);
        } else
-               TRY(fputs(" />\n", fp) != EOF);
+               TRY(claws_fputs(" />\n", fp) != EOF);
        
        return 0;
 }
        
        return 0;
 }
index 225a12e60ac00e188ce5749409efbeaeeb1f6377..6ca9059374af8cf4a2c2ab0a644e5196e0ae4067 100644 (file)
@@ -51,6 +51,7 @@ struct _XMLNode
 struct _XMLFile
 {
        FILE *fp;
 struct _XMLFile
 {
        FILE *fp;
+       gchar *path;
 
        GString *buf;
        gchar *bufp;
 
        GString *buf;
        gchar *bufp;
index 9aadc3bd5ac533817209a36aaa89e2837f02b18c..1fc1c28fcbca04938760b4b8c113d63b34c0a166 100644 (file)
  * ***********************************************************************
  */
 
  * ***********************************************************************
  */
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
 
 #include <glib.h>
 #include <stdio.h>
 
 #include <glib.h>
 #include <stdio.h>
@@ -41,6 +45,7 @@
 #include "mgutils.h"
 #include "xmlprops.h"
 #include "utils.h"
 #include "mgutils.h"
 #include "xmlprops.h"
 #include "utils.h"
+#include "claws_io.h"
 
 /* Element tag names */
 #define XMLS_ELTAG_PROP_LIST     "property-list"
 
 /* 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++ ) {
 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;
        }
                        return -1;
        }
-       if(fputs( "<", fp ) == EOF)
+       if(claws_fputs( "<", fp ) == EOF)
                return -1;
                return -1;
-       if(fputs( name, fp ) == EOF)
+       if(claws_fputs( name, fp ) == EOF)
                return -1;
        
        return 0;
                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++ ) {
 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;
        }
                        return -1;
        }
-       if(fputs( "</", fp ) == EOF)
+       if(claws_fputs( "</", fp ) == EOF)
                return -1;
                return -1;
-       if(fputs( name, fp ) == EOF)
+       if(claws_fputs( name, fp ) == EOF)
                return -1;
                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 ) {
                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;
                return -1;
-       if(fputs( name, fp ) == EOF)
+       if(claws_fputs( name, fp ) == EOF)
                return -1;
                return -1;
-       if(fputs( "=\"", fp ) == EOF)
+       if(claws_fputs( "=\"", fp ) == EOF)
                return -1;
        if(xml_file_put_escape_str( fp, value ) < 0)
                return -1;
                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;
                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;
                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;
 }
 
                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;
                        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 */
                        goto revert;
 
                /* Output all properties */
index ade8db94a1594df143364720d718e6a274620093..1344b2b77fa7936ea5451be4001f1feb140f008c 100644 (file)
@@ -2433,12 +2433,12 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
                gboolean prev_autowrap;
                GtkTextBuffer *buffer;
                BLOCK_WRAP();
                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();
                        strcrchomp(buf);
                        gtk_text_buffer_insert(textbuf, &iter, buf, -1);
                }
                UNBLOCK_WRAP();
-               fclose(fp);
+               claws_fclose(fp);
        }
        
        compose_attach_parts(compose, msginfo);
        }
        
        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);
 
        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') {
 
        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);
 
        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) {
 
        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;
        }
 
                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("");
        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)
                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);
        }
 
        g_string_free(file_contents, TRUE);
-       fclose(fp);
+       claws_fclose(fp);
 
        return result;
 }
 
        return result;
 }
@@ -3788,11 +3788,11 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file,
                        return FALSE;
                }
        }
                        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;
        }
                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
 
        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 */
                return -1;
 
        /* separator between header and body */
-       err |= (fputs("\n", fp) == EOF);
+       err |= (claws_fputs("\n", fp) == EOF);
 
        return (err ? -1:0);
 }
 
        return (err ? -1:0);
 }
@@ -5565,8 +5565,8 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
                };
        gint ret = 0;
 
                };
        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;
        }
 
                return -1;
        }
 
@@ -5584,7 +5584,7 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
                        buf = NULL;
                        continue;
                }
                        buf = NULL;
                        continue;
                }
-               if (fputs(buf, fdest) == -1) {
+               if (claws_fputs(buf, fdest) == -1) {
                        g_free(buf);
                        buf = NULL;
                        goto error;
                        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) {
                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];
                                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);
                                } else
                                        err |= (fprintf(fdest, "%s",
                                                compose->account->address) < 0);
-                               err |= (fputs(")", fdest) == EOF);
+                               err |= (claws_fputs(")", fdest) == EOF);
                        }
                }
 
                g_free(buf);
                buf = NULL;
                        }
                }
 
                g_free(buf);
                buf = NULL;
-               if (fputs("\n", fdest) == -1)
+               if (claws_fputs("\n", fdest) == -1)
                        goto error;
        }
 
                        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;
 
        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;
        }
 
                        goto error;
        }
 
-       fclose(fp);
+       claws_fclose(fp);
 
        return 0;
 
 error:
 
        return 0;
 
 error:
-       fclose(fp);
+       claws_fclose(fp);
 
        return -1;
 }
 
        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) {
                                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. */
 
                                        /* 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. */
                                        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);
                                                procmime_write_mimeinfo(mimemsg, tmpfp);
-                                               fclose(tmpfp);
+                                               claws_fclose(tmpfp);
 
                                                outbox = folder_find_item_from_identifier(compose_get_save_to(compose));
                                                if (!outbox)
 
                                                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;
 
        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;
        }
 
                return -1;
        }
 
@@ -5969,24 +5969,24 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file)
 
        g_free(tmp);
        if (!chars) {
 
        g_free(tmp);
        if (!chars) {
-               fclose(fp);
+               claws_fclose(fp);
                claws_unlink(file);
                return -1;
        }
        /* write body */
        len = strlen(chars);
                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);
                g_free(chars);
-               fclose(fp);
+               claws_fclose(fp);
                claws_unlink(file);
                return -1;
        }
 
        g_free(chars);
 
                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;
        }
                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);
        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;
        }
                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)) {
                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;
                                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");
                                 * 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;
                                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) {
 
        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;
                        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) {
        } 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;
                        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");
        }
        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;
        }
                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;
                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 (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;
                }
                        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';
                        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);
                        }
                }
                                        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 */
 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);
 {
        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);
        
        if (fp) {
                fprintf(fp, "%s\t%d\n", folder_item_get_identifier(info->folder), 
                                info->msgnum);
-               fclose(fp);
+               claws_fclose(fp);
        }
                
        g_free(filepath);       
        }
                
        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);
 
        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;
        }
 
                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) {
        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) {
                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;
        }
                goto warn_err;
        }
-       if (safe_fclose(fp) == EOF) {
+       if (claws_safe_fclose(fp) == EOF) {
                goto warn_err;
        }
        
                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);
 {
        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) {
        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;
                        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);
                }       
                        }
                        g_strfreev(parts);
                }       
-               fclose(fp);
+               claws_fclose(fp);
        }       
        g_free(filepath);
        compose_clear_exit_drafts();
        }       
        g_free(filepath);
        compose_clear_exit_drafts();
index e1490475589ca0cd448cb8163161ac567db3c09d..b8b0eb3e141046a33975af0f0c901dc8024a4fb7 100644 (file)
  * 
  */
 
  * 
  */
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
+
 #include <glib.h>
 #include <stdio.h>
 #include <string.h>
 #include <glib.h>
 #include <stdio.h>
 #include <string.h>
@@ -24,6 +29,7 @@
 
 #include "enriched.h"
 #include "utils.h"
 
 #include "enriched.h"
 #include "utils.h"
+#include "claws_io.h"
 
 #define ERTFBUFSIZE    8192
 
 
 #define ERTFBUFSIZE    8192
 
@@ -114,7 +120,7 @@ static ERTFState ertf_read_line(ERTFParser *parser)
        gchar buf2[ERTFBUFSIZE];
        gint index;
 
        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;
        }
                parser->state = ERTF_EOF;
                return ERTF_EOF;
        }
index 48823e12aa5d8e505657c274ad774141478bc201..4a11f4fadc469822dff16a94f286ad778a9f82b3 100644 (file)
@@ -2626,27 +2626,27 @@ static void fetch_content_run(struct etpan_thread_op * op)
                        goto free;
                }
                
                        goto free;
                }
                
-               f = fdopen(fd, "wb");
+               f = claws_fdopen(fd, "wb");
                if (f == NULL) {
                        result->error = MAILIMAP_ERROR_FETCH;
                        goto close;
                }
                
                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;
                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;
                
                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);
                goto unlink;
        close:
                close(fd);
index d0bfefd21ba92e2ed39b683dac151ce2018f1505..5dbec5b96a1d5ab6465681dd2a1f4128d884777f 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;
 
 static gint exporthtml_create_css_dfl( const gchar *fileSpec ) {
        FILE *cssFile;
 
-       cssFile = g_fopen( fileSpec, "rb" );
+       cssFile = claws_fopen( fileSpec, "rb" );
        if( cssFile ) {
        if( cssFile ) {
-               fclose( cssFile );
+               claws_fclose( cssFile );
                return MGU_SUCCESS;
        }
                return MGU_SUCCESS;
        }
-       cssFile = g_fopen( fileSpec, "wb" );
+       cssFile = claws_fopen( fileSpec, "wb" );
        if( ! cssFile ) {
                return MGU_OPEN_FILE;
        }
        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" );
 
        fprintf( cssFile, ".tab-attr {\n" );
        fprintf( cssFile, "}\n" );
 
-       safe_fclose( cssFile );
+       claws_safe_fclose( cssFile );
        return MGU_SUCCESS;
 }
 
        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;
 
 static gint exporthtml_create_css_full( const gchar *fileSpec ) {
        FILE *cssFile;
 
-       cssFile = g_fopen( fileSpec, "rb" );
+       cssFile = claws_fopen( fileSpec, "rb" );
        if( cssFile ) {
        if( cssFile ) {
-               fclose( cssFile );
+               claws_fclose( cssFile );
                return MGU_SUCCESS;
        }
                return MGU_SUCCESS;
        }
-       cssFile = g_fopen( fileSpec, "wb" );
+       cssFile = claws_fopen( fileSpec, "wb" );
        if( ! cssFile ) {
                return MGU_OPEN_FILE;
        }
        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" );
 
        fprintf( cssFile, ".tab-attr {\n" );
        fprintf( cssFile, "}\n" );
 
-       safe_fclose( cssFile );
+       claws_safe_fclose( cssFile );
        return MGU_SUCCESS;
 }
 
        return MGU_SUCCESS;
 }
 
@@ -964,7 +964,7 @@ void exporthtml_process(
        static gchar *title;
        gchar buf[512];
 
        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" );
        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" );
 
        fprintf( htmlFile, "</body>\n" );
        fprintf( htmlFile, "</html>\n" );
 
-       safe_fclose( htmlFile );
+       claws_safe_fclose( htmlFile );
        ctl->retVal = MGU_SUCCESS;
 
        /* Create stylesheet files */
        ctl->retVal = MGU_SUCCESS;
 
        /* Create stylesheet files */
index ded6a3e5dcb75d50fc27fced399531ab69812e5f..54e6bd02efa6155d6cb8c36a6ffd6d2254b4240c 100644 (file)
@@ -533,7 +533,7 @@ void exportldif_process( ExportLdifCtl *ctl, AddressCache *cache )
        ItemFolder *rootFolder;
        FILE *ldifFile;
 
        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;
        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 );
 
        rootFolder = cache->rootFolder;
        exportldif_fmt_folder( ctl, ldifFile, rootFolder );
-       safe_fclose( ldifFile );
+       claws_safe_fclose( ldifFile );
        ctl->retVal = MGU_SUCCESS;
 }
 
        ctl->retVal = MGU_SUCCESS;
 }
 
index 503a0492268a70201f8eeeb887158dccd35f4e70..97c5d01d55894b579d22aadae9a608cb23e9e19e 100644 (file)
@@ -63,6 +63,7 @@
 #include "privacy.h"
 #include "prefs_common.h"
 #include "prefs_migration.h"
 #include "privacy.h"
 #include "prefs_common.h"
 #include "prefs_migration.h"
+#include "claws_io.h"
 
 /* Dependecies to be removed ?! */
 #include "prefs_account.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];
 
        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)))
                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:"))) ||
                        /* 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;
        
        g_free(hentry[0].body);
        hentry[0].body = NULL;
-       fclose(fp);
+       claws_fclose(fp);
 
        return msgnum;
 }
 
        return msgnum;
 }
index f5893e1c1effea866188495ed6fc1aef447a1148..b86de3a80720976183254cf50741c19b0cc6c218 100644 (file)
@@ -43,6 +43,7 @@
 #include "menu.h"
 #include "textview.h"
 #include "main.h"
 #include "menu.h"
 #include "textview.h"
 #include "main.h"
+#include "claws_io.h"
 
 extern SessionStats session_stats;
 static GtkTextBuffer *stats_text_buffer;
 
 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);
        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);
 
                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;
                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);
        }
                gtk_text_buffer_insert(buffer, &iter, tmp, -1);
                g_free(tmp);
        }
-       fclose(fp);
+       claws_fclose(fp);
 
        return scrolledwin;
 }
 
        return scrolledwin;
 }
index da8625eeb98d156e56c9e91d2e671cc9c1248441..190b4678671c6449480d563ccddcffa9f83145e5 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
  * 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>
 #include <glib.h>
 #include <stdio.h>
 #include <string.h>
@@ -25,6 +30,7 @@
 #include "codeconv.h"
 #include "utils.h"
 #include "entity.h"
 #include "codeconv.h"
 #include "utils.h"
 #include "entity.h"
+#include "claws_io.h"
 
 #define SC_HTMLBUFSIZE 8192
 #define HR_STR         "────────────────────────────────────────────────"
 
 #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;
 
        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;
        if (n == 0) {
                parser->state = SC_HTML_EOF;
                return SC_HTML_EOF;
index 4982b61618f745825ad87734387f233df6cf6738..5871b79f3d5af68b558144097b1bf7e1f3c2fc7f 100644 (file)
@@ -71,6 +71,7 @@
 #include "tags.h"
 #include "main.h"
 #include "passwordstore.h"
 #include "tags.h"
 #include "main.h"
 #include "passwordstore.h"
+#include "claws_io.h"
 
 typedef struct _IMAPFolder     IMAPFolder;
 typedef struct _IMAPSession    IMAPSession;
 
 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;
        
        if (filename == NULL)
                return -1;
        
-       fp = g_fopen(filename, "rb");
+       fp = claws_fopen(filename, "rb");
        if (!fp)
                return -1;
        
        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++;
        }
        
                cnt += strlen(buf);
                if (!strstr(buf, "\r\n") && strstr(buf, "\n"))
                        cnt++;
        }
        
-       fclose(fp);
+       claws_fclose(fp);
        return cnt;
 }
 
        return cnt;
 }
 
index fc3927ced7d217c48fc24c2685af3db30398c5ac..a29b02b42fee0bd64d5416dfe89e2f6a142a06fa 100644 (file)
@@ -56,6 +56,7 @@
 #include "codeconv.h"
 #include "adbookbase.h"
 #include "utils.h"
 #include "codeconv.h"
 #include "adbookbase.h"
 #include "utils.h"
+#include "claws_io.h"
 
 #define JPILOT_DBHOME_DIR   ".jpilot"
 #define JPILOT_DBHOME_FILE  "AddressDB.pdb"
 
 #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);
        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 (r < 1)
                return MGU_ERROR_READ;
-       if (feof(in)) {
+       if (claws_feof(in)) {
                return MGU_EOF;
        }
 
                return MGU_EOF;
        }
 
@@ -560,7 +561,7 @@ static int jpilot_get_info_size( FILE *in, int *size ) {
                return MGU_SUCCESS;
        }
 
                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;
 
        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 ) {
        *buf_size=0;
 
        if( pilotFile->path ) {
-               in = g_fopen( pilotFile->path, "rb" );
+               in = claws_fopen( pilotFile->path, "rb" );
                if( !in ) {
                        return MGU_OPEN_FILE;
                }
                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;
        }
 
                return MGU_NO_FILE;
        }
 
-       num = fread( &rdbh, sizeof( RawDBHeader ), 1, in );
+       num = claws_fread( &rdbh, sizeof( RawDBHeader ), 1, in );
        if( num != 1 ) {
        if( num != 1 ) {
-               if( ferror(in) ) {
-                       fclose(in);
+               if( claws_ferror(in) ) {
+                       claws_fclose(in);
                        return MGU_ERROR_READ;
                }
        }
                        return MGU_ERROR_READ;
                }
        }
-       if (feof(in)) {
-               fclose(in);
+       if (claws_feof(in)) {
+               claws_fclose(in);
                return MGU_EOF;
        }
 
                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) {
 
        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) {
                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)) {
                return MGU_ERROR_READ;
        }
        *buf = ( char * ) malloc(rec_size);
        if (!(*buf)) {
-               fclose(in);
+               claws_fclose(in);
                return MGU_OO_MEMORY;
        }
                return MGU_OO_MEMORY;
        }
-       num = fread(*buf, rec_size, 1, in);
+       num = claws_fread(*buf, rec_size, 1, in);
        if (num != 1) {
        if (num != 1) {
-               if (ferror(in)) {
-                       fclose(in);
+               if (claws_ferror(in)) {
+                       claws_fclose(in);
                        free(*buf);
                        return MGU_ERROR_READ;
                }
        }
                        free(*buf);
                        return MGU_ERROR_READ;
                }
        }
-       fclose(in);
+       claws_fclose(in);
 
        *buf_size = rec_size;
 
 
        *buf_size = rec_size;
 
@@ -685,8 +686,8 @@ static int read_header(FILE *pc_in, PC3RecordHeader *header) {
 
        memset(header, 0, sizeof(PC3RecordHeader));
 
 
        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) {
                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;
        }
        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) {
                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;
 
        int rec_len, num;
        char *record;
 
-       if( feof( in ) ) {
+       if( claws_feof( in ) ) {
                return MGU_EOF;
        }
        num = read_header( in, &header );
        if( num < 1 ) {
                return MGU_EOF;
        }
        num = read_header( in, &header );
        if( num < 1 ) {
-               if( ferror( in ) )
+               if( claws_ferror( in ) )
                        return MGU_ERROR_READ;
                        return MGU_ERROR_READ;
-               else if( feof( in ) )
+               else if( claws_feof( in ) )
                        return MGU_EOF;
                else
                        return -1;
                        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;
        }
        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( num != 1 ) {
-               if( ferror( in ) ) {
+               if( claws_ferror( in ) ) {
                        free( record );
                        return MGU_ERROR_READ;
                }
                        free( record );
                        return MGU_ERROR_READ;
                }
@@ -789,20 +790,20 @@ static gint jpilot_read_db_files( JPilotFile *pilotFile, GList **records ) {
                return MGU_BAD_ARGS;
        }
 
                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 */
        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( num != 1 ) {
-               if( ferror( in ) ) {
-                       fclose( in );
+               if( claws_ferror( in ) ) {
+                       claws_fclose( in );
                        return MGU_ERROR_READ;
                }
                        return MGU_ERROR_READ;
                }
-               if( feof( in ) ) {
-                       fclose( in );
+               if( claws_feof( in ) ) {
+                       claws_fclose( in );
                        return MGU_EOF;
                }
        }
                        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++ ) {
        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( num != 1 ) {
-                       if( ferror( in ) ) {
+                       if( claws_ferror( in ) ) {
                                break;
                        }
                                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;
                                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 );
                }
                if (fseek( in, next_offset, SEEK_SET ) < 0) {
                        free_mem_rec_header( &mem_rh );
-                       fclose(in);
+                       claws_fclose(in);
                        return MGU_ERROR_READ;
                }
                        return MGU_ERROR_READ;
                }
-               while( ! feof( in ) ) {
+               while( ! claws_feof( in ) ) {
                        fpos = ftell( in );
                        if( out_of_order ) {
                                find_next_offset(
                        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;
                        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( ( num != 1 ) ) {
-                               if( ferror( in ) ) {
+                               if( claws_ferror( in ) ) {
                                        free( buf );
                                        break;
                                }
                                        free( buf );
                                        break;
                                }
@@ -919,20 +920,20 @@ static gint jpilot_read_db_files( JPilotFile *pilotFile, GList **records ) {
                        recs_returned++;
                }
        }
                        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;
        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;
        }
 
        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 ) );
                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 );
                }
        }
                        free( temp_br );
                }
        }
-       fclose( pc_in );
+       claws_fclose( pc_in );
 
        return MGU_SUCCESS;
 }
 
        return MGU_SUCCESS;
 }
@@ -1616,8 +1617,8 @@ gchar *jpilot_find_pilotdb( void ) {
        strncat( str, JPILOT_DBHOME_FILE, WORK_BUFLEN - strlen(str) );
 
        /* Attempt to open */
        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 */
        }
        else {
                /* Truncate filename */
index 5b0750aa01e18e3d686d0d29f9a1289bedd25ac0..16a20d7cfe30b5c5807e2af90f41c335003d15d3 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();
                                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) {
                                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);
                        }
                                }
                                list = g_slist_append( list, file);
                        }
index 93ce80000297fb1b1c67a85419d17f67cbbe3720..a632123dce70c89d182d18ed9fadeba3fa1ca423 100644 (file)
@@ -32,6 +32,7 @@
 #include "addrcache.h"
 
 #include "utils.h"
 #include "addrcache.h"
 
 #include "utils.h"
+#include "claws_io.h"
 
 #define        LDIF_SEP_TAG    ':'
 #define        LDIF_LANG_TAG   ';'
 
 #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 */
        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 );
 
        /* 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 ) {
 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;
                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 );
  */
 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;
 }
 
        ldifFile->file = NULL;
 }
 
@@ -246,14 +247,14 @@ static gchar *ldif_get_line( LdifFile *ldifFile ) {
        int i = 0;
        int cur_alloc = LDIFBUFSIZE;
 
        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 );
                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;
                        ldifFile->retVal = MGU_ERROR_READ;
                if( ch == '\0' || ch == EOF ) {
                        if( i == 0 ) return NULL;
index 0bfee71bf46e94950a218bfbb4f8bdbdf1cd842a..631e366f6a98b24bc99059f6a10ba179bf1dead2 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;
 
        gchar buf[BUFFSIZE];
        gboolean err = FALSE;
 
-       oldfp = g_fopen(old_rc, "r");
+       oldfp = claws_fopen(old_rc, "r");
        if (!oldfp)
                return -1;
        if (!oldfp)
                return -1;
-       newfp = g_fopen(new_rc, "w");
+       newfp = claws_fopen(new_rc, "w");
        if (!newfp) {
        if (!newfp) {
-               fclose(oldfp);
+               claws_fclose(oldfp);
                return -1;
        }
        
                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);
                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))) {
                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));
                } 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);
                }
        }
        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);
                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");
        }
                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)
        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);
                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;
        }
 }              
                win32_debug_fp=NULL;
        }
 }              
@@ -1788,12 +1788,12 @@ static GString * parse_cmd_compose_from_file(const gchar *fn)
        if (isstdin)
                fp = stdin;
        else {
        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"));
        }
 
                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')
                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=");
        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)
                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);
        /* 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;
                        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);
                }
        } 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;
                        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);
                }
        } 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;
                        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
                }
        } else {
 #ifndef G_OS_WIN32
index 5b67051c4c6e29f6c2854801842088bc410f57d3..c87c89747d0a1509b295b6af4378552beac21ce1 100644 (file)
@@ -49,6 +49,7 @@
 #include "tags.h"
 #include "folder_item_prefs.h"
 #include "procmsg.h"
 #include "tags.h"
 #include "folder_item_prefs.h"
 #include "procmsg.h"
+#include "claws_io.h"
 
 /*!
  *\brief       Keyword lookup element
 
 /*!
  *\brief       Keyword lookup element
@@ -1623,7 +1624,7 @@ static gboolean matcherlist_match_binary_content(MatcherList *matchers, MimeInfo
        if (!outfp)
                return FALSE;
 
        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)) {
                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) {
                         * no need to check the others. */
                        if (matcher->result && matcher->done) {
                                if (!matchers->bool_and) {
-                                       fclose(outfp);
+                                       claws_fclose(outfp);
                                        return TRUE;
                                }
                        }
                }
        }
 
                                        return TRUE;
                                }
                        }
                }
        }
 
-       fclose(outfp);
+       claws_fclose(outfp);
        return FALSE;
 }
 
        return FALSE;
 }
 
@@ -1823,8 +1824,8 @@ static gboolean matcherlist_match_file(MatcherList *matchers, MsgInfo *info,
        if (file == NULL)
                return FALSE;
 
        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;
        }
                g_free(file);
                return result;
        }
@@ -1866,7 +1867,7 @@ static gboolean matcherlist_match_file(MatcherList *matchers, MsgInfo *info,
 
        g_free(file);
 
 
        g_free(file);
 
-       fclose(fp);
+       claws_fclose(fp);
        
        return result;
 }
        
        return result;
 }
@@ -2429,42 +2430,42 @@ static int prefs_filtering_write(FILE *fp, GSList *prefs_filtering)
                        continue;
 
                if (prop->enabled) {
                        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 {
                                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;
                        }
                }
 
                                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 != '"') {
                        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 == '"') {
                                        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 ++;
                }
                                        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;
                }
                        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);
                        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);
                }
 
                                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;
                }
                        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;
                }
                        data->error = TRUE;
                        goto fail;
                }
-               if (fputc('\n', data->fp) == EOF) {
+               if (claws_fputc('\n', data->fp) == EOF) {
                        data->error = TRUE;
                        goto fail;
                }
                        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 ||
         /* 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 ||
                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 ||
                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;
                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);
 
 
        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);
        g_free(rcpath);
 
        if (f != NULL) {
                matcher_parser_start_parsing(f);
-               fclose(matcher_parserin);
+               claws_fclose(matcher_parserin);
        }
 }
        }
 }
index 68b3d015ad4a1311644370370dcdbc8836972c7d..2f7db0de12174cc728cbb8eff58c9d894e3fb29a 100644 (file)
@@ -23,7 +23,6 @@
 #endif
 
 
 #endif
 
 
-#define _GNU_SOURCE
 #include <stdio.h>
 
 #ifdef USE_PTHREAD
 #include <stdio.h>
 
 #ifdef USE_PTHREAD
 
 #define MESSAGEBUFSIZE 8192
 
 
 #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++; \
 #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"); \
                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; \
                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);
 
 
        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 {
                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.");
                        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);
                        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;
        }
 
                return -1;
        }
 
@@ -148,10 +137,10 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, gboolean apply_filter,
                        GTK_EVENTS_FLUSH();
                }
        
                        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");
                        g_warning("can't open temporary file");
-                       fclose(mbox_fp);
+                       claws_fclose(mbox_fp);
                        g_free(tmp_file);
                        return -1;
                }
                        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 */
                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 */
                        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 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);
 
                /* 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;
                }
 
                        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");
                        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;
                        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) {
 
                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;
                                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);
        folder_item_update_thaw();
        
        g_free(tmp_file);
-       fclose(mbox_fp);
+       claws_fclose(mbox_fp);
        debug_print("%d messages found.\n", msgs);
 
        return msgs;
        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());
                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;
                        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);
                if (fprintf(lockfp, "%d\n", getpid()) < 0) {
                        FILE_OP_ERROR(lockfile, "fprintf");
                        g_free(lockfile);
-                       fclose(lockfp);
+                       claws_fclose(lockfp);
                        return -1;
                }
 
                        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;
                }
                        g_free(lockfile);
                        return -1;
                }
@@ -485,8 +474,8 @@ gint copy_mbox(gint srcfd, const gchar *dest)
                return -1;
        }
 
                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;
        }
 
                return -1;
        }
 
@@ -496,9 +485,9 @@ gint copy_mbox(gint srcfd, const gchar *dest)
        }
 
        while ((n_read = read(srcfd, buf, sizeof(buf))) > 0) {
        }
 
        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);
                        g_warning("writing to %s failed.", dest);
-                       fclose(dest_fp);
+                       claws_fclose(dest_fp);
                        claws_unlink(dest);
                        return -1;
                }
                        claws_unlink(dest);
                        return -1;
                }
@@ -510,8 +499,8 @@ gint copy_mbox(gint srcfd, const gchar *dest)
                err = TRUE;
        }
 
                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;
        }
 
                err = TRUE;
        }
 
@@ -527,12 +516,12 @@ void empty_mbox(const gchar *mbox)
 {
        FILE *fp;
 
 {
        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;
        }
                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)
 }
 
 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;
        }
 
                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;
        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;
                }
 
                        continue;
                }
 
-#ifdef HAVE_FGETS_UNLOCKED
-               flockfile(msg_fp);
-#endif
                strncpy2(buf,
                         msginfo->from ? msginfo->from :
                         cur_account && cur_account->address ?
                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;
                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 */
                        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;
 
                        /* 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)) {
                                offset++;
                        }
                        if (!strncmp(buf+offset, "From ", 5)) {
-                               if (SC_FPUTC('>', mbox_fp) == EOF) {
+                               if (claws_fputc('>', mbox_fp) == EOF) {
                                        err = -1;
                                        err = -1;
-#ifdef HAVE_FGETS_UNLOCKED
-                                       funlockfile(msg_fp);
-#endif
-                                       fclose(msg_fp);
+                                       claws_fclose(msg_fp);
                                        goto out;
                                }
                        }
                                        goto out;
                                }
                        }
-                       if (SC_FPUTS(buf, mbox_fp) == EOF) {
+                       if (claws_fputs(buf, mbox_fp) == EOF) {
                                err = -1;
                                err = -1;
-#ifdef HAVE_FGETS_UNLOCKED
-                               funlockfile(msg_fp);
-#endif
-                               fclose(msg_fp);
+                               claws_fclose(msg_fp);
                                goto out;
                        }
                }
                                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 (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;
                                        err = -1;
-#ifdef HAVE_FGETS_UNLOCKED
-                                       funlockfile(msg_fp);
-#endif
-                                       fclose(msg_fp);
+                                       claws_fclose(msg_fp);
                                        goto out;
                                }
                        }
                }
 
                /* add a trailing empty line */
                                        goto out;
                                }
                        }
                }
 
                /* add a trailing empty line */
-               if (SC_FPUTC('\n', mbox_fp) == EOF) {
+               if (claws_fputc('\n', mbox_fp) == EOF) {
                        err = -1;
                        err = -1;
-#ifdef HAVE_FGETS_UNLOCKED
-                       funlockfile(msg_fp);
-#endif
-                       fclose(msg_fp);
+                       claws_fclose(msg_fp);
                        goto out;
                }
 
                        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();
                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();
 
        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;
 }
 
        return err;
 }
index 0f54089d201843317a7374e63091d1b0851cb76c..409e8647c330e2238ffa0026bd580412d2ba46b0 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);
 
        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;
        }
 
                return -1;
        }
 
@@ -1062,8 +1062,8 @@ static gint disposition_notification_send(MsgInfo *msginfo)
        if (ok < 0)
                goto FILE_ERROR;        
 
        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;
        }
                claws_unlink(tmp);
                return -1;
        }
@@ -1100,7 +1100,7 @@ static gint disposition_notification_send(MsgInfo *msginfo)
        return ok;
 
 FILE_ERROR:
        return ok;
 
 FILE_ERROR:
-       fclose(fp);
+       claws_fclose(fp);
        claws_unlink(tmp);
        return -1;
 }
        claws_unlink(tmp);
        return -1;
 }
index 69d0ecae37ff91fcca62a58b8da46cf8dfbf6876..b0967a8a947cd3d8a1ff0f9795c26ff7756d9560 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);
        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);
        }
        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);
                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) {
                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 == ' ')
                                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;
                                }
                        }
                                        break;
                                }
                        }
-                       fclose(fp);
+                       claws_fclose(fp);
                }
                if (!seq_name)
                        seq_name = g_strdup("unseen");
                }
                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);
                                            ".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;
                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 */
                                        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;
                                        }
                        }
                                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) {
                        err = TRUE;
 
                if (!err) {
index 614bcd75aba935e213f2404355c96ca1f950d532..f6eac4c8a65b8675a7169b0946c5106e3a40cfdf 100644 (file)
@@ -55,6 +55,7 @@
 #include "timing.h"
 #include "manage_window.h"
 #include "privacy.h"
 #include "timing.h"
 #include "manage_window.h"
 #include "privacy.h"
+#include "claws_io.h"
 
 typedef enum
 {
 
 typedef enum
 {
@@ -792,21 +793,21 @@ static void mimeview_show_message_part(MimeView *mimeview, MimeInfo *partinfo)
        fname = mimeview->file;
        if (!fname) return;
 
        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");
                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);
 
                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)
 }
 
 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;
 
                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) {
                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)
                        }
                }
                if (fp != NULL)
-                       fclose(fp);
+                       claws_fclose(fp);
                if (name)
                        filename = g_path_get_basename(name);
                g_free(name);
                if (name)
                        filename = g_path_get_basename(name);
                g_free(name);
index 8909ea7044928d2f78c0c0d355f86c437457212a..ca9d9653879eda16d3173e34d8742dc51d2556f8 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "defs.h"
 
 
 #include "defs.h"
 
-#define _GNU_SOURCE
 #include <stdio.h>
 
 #include <glib.h>
 #include <stdio.h>
 
 #include <glib.h>
 #include "prefs_common.h"
 #include "claws_io.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) | \
 #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; \
  \
        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); \
                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);                   \
        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;                                     \
 }
                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) {                    \
                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;                           \
        } \
                        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 (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)
                        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");
                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 */
                        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);
                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);
                         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);
                        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 */
 
        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 */
        } 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) {
 
        *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),
                    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 {
                        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),
                    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;
        }
 
                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));
                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) {
        }
 
        if (msgcache_read_cache_data_str(fp, &srccharset, NULL) < 0) {
-               fclose(fp);
+               claws_fclose(fp);
                return NULL;
        }
        dstcharset = CS_UTF_8;
                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 {
                                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);
 
                        if (swapping)
                                num = bswap_32(num);
 
@@ -776,7 +769,7 @@ bail_err:
                munmap(cache_data, map_len);
 #endif
        }
                munmap(cache_data, map_len);
 #endif
        }
-       fclose(fp);
+       claws_fclose(fp);
        if (conv != NULL) {
                if (conv->free != NULL)
                        conv->free(conv);
        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 {
                        }
                }
        } 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 (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;
                        }
                                error = TRUE;
                                break;
                        }
@@ -886,7 +879,7 @@ bail_err:
                munmap(cache_data, map_len);
 #endif
        }
                munmap(cache_data, map_len);
 #endif
        }
-       fclose(fp);
+       claws_fclose(fp);
        if (error) {
                debug_print("error reading cache mark from %s\n", mark_file);
        }
        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 {
                        }
                }
        } 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);
                        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 {
                                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);
                                                id = -1;
                                        if (swapping)
                                                id = bswap_32(id);
@@ -998,7 +991,7 @@ bail_err:
                munmap(cache_data, map_len);
 #endif
        }
                munmap(cache_data, map_len);
 #endif
        }
-       fclose(fp);
+       claws_fclose(fp);
        if (error) {
                debug_print("error reading cache tags from %s\n", tags_file);
        }
        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)
        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);
                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)
                        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);
                        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)
                        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)
                        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);
                        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);
 
        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);
        /* 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)
 
        /* 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)
        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)
        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) {
 
 
        if (write_fps.error != 0) {
index 4564347cc59f8a10f061441b97bc41742ed11a1c..8ae8508e8d8e396d1bb586e528dacf5ba3a63c2d 100644 (file)
@@ -31,6 +31,7 @@
 #include "mutt.h"
 #include "addritem.h"
 #include "addrcache.h"
 #include "mutt.h"
 #include "addritem.h"
 #include "addrcache.h"
+#include "claws_io.h"
 
 #define MUTT_HOME_FILE  ".muttrc"
 #define MUTTBUFSIZE     2048
 
 #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 */
        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 );
 
        /* 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 ) {
 */
 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;
                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 );
 */
 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;
 }
 
        muttFile->file = NULL;
 }
 
@@ -138,7 +139,7 @@ static gchar *mutt_get_line( MuttFile *muttFile, gboolean *flagCont ) {
        int i = 0, li = 0;
 
        *flagCont = FALSE;
        int i = 0, li = 0;
 
        *flagCont = FALSE;
-       if( feof( muttFile->file ) ) 
+       if( claws_feof( muttFile->file ) ) 
                return NULL;
 
        memset(buf, 0, MUTTBUFSIZE);
                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 */
        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 */
        }
        else {
                /* Truncate filename */
index 296a4f688d8acaae23a872c2d43f8a0a4e503e80..c963ac113fd16b1a81261263e175aa7724dd770d 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);
 
        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;
                NewsSession *session;
                gint ok;
                clist *grouplist = NULL;
                clistiter *cur;
-               fp = g_fopen(filename, "wb");
+               fp = claws_fopen(filename, "wb");
                
                if (!fp) {
                        g_free(filename);
                
                if (!fp) {
                        g_free(filename);
@@ -666,7 +666,7 @@ GSList *news_get_group_list(Folder *folder)
                }
                session = news_session_get(folder);
                if (!session) {
                }
                session = news_session_get(folder);
                if (!session) {
-                       fclose(fp);
+                       claws_fclose(fp);
                        g_free(filename);
                        return NULL;
                }
                        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;
                        }
                                session_destroy(SESSION(session));
                                REMOTE_FOLDER(folder)->session = NULL;
                        }
-                       fclose(fp);
+                       claws_fclose(fp);
                        g_free(filename);
                        return NULL;
                }
                        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;
                                        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;
                                        g_free(filename);
                                        newsnntp_list_free(grouplist);
                                        return NULL;
@@ -703,7 +703,7 @@ GSList *news_get_group_list(Folder *folder)
                        }
                        newsnntp_list_free(grouplist);
                }
                        }
                        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;
                        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;
                }
 
                        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;
                }
        }
 
                        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;
                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);
        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 (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) {
                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");
                       msginfo->from,
                       date) < 0) {
                FILE_OP_ERROR(tmp, "fprintf");
-               fclose(tmpfp);
+               claws_fclose(tmpfp);
                claws_unlink(tmp);
                g_free(tmp);
                return -1;
        }
 
                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;
                claws_unlink(tmp);
                g_free(tmp);
                return -1;
index 9d3c7d2b0b0651bfbcb725969239f479386b10e8..76b25fc59e0430c37cde3a6f62064e1427e53f76 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);
        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);
                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;
                        g_free(sanitized_uid);
                        g_free(path);
                        return FALSE;
@@ -108,7 +108,7 @@ int partial_msg_in_uidl_list(MsgInfo *msginfo)
 
        now = time(NULL);
 
 
        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;
                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)) {
                        }
                }
                if (!strcmp(uidl, msginfo->extradata->partial_recv)) {
-                       fclose(fp);
+                       claws_fclose(fp);
                        return TRUE;
                }
        }
 
                        return TRUE;
                }
        }
 
-       fclose(fp);     
+       claws_fclose(fp);       
        return FALSE;
 }
 
        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);
 
                           "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);
                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;
                }
                        g_free(path);
                        goto bail;
                }
@@ -191,16 +190,16 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
        
        g_free(sanitized_uid);
 
        
        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);
 
                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");
                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");
                        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;
                                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");
                        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;
                                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);
                }
        }
                        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;
        }
                g_free(path);
                g_free(pathnew);
                goto bail;
        }
-       fclose(fp);
+       claws_fclose(fp);
 
        move_file(pathnew, path, TRUE);
 
        g_free(path);
        g_free(pathnew);
        
 
        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);
                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;
        }
                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");
        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;
        }
                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");
                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;
                        }
                                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");
                }
                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;
                }
        }
                        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;
        }
 
                g_free(pathnew);
                goto bail;
        }
 
-       fclose(fp);
+       claws_fclose(fp);
        if (rename_force(pathnew, filename) != 0) {
                g_free(pathnew);
                goto bail;
        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);
        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);
                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;
                        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);
 
 
        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;
                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;
 }
        
        return result;
 }
index 97f44d3f57da4fbf25d8c8bcbfcc9a8d01218a28..ddf6f9595d267e348c10a8281601d4800b8bc743 100644 (file)
@@ -37,6 +37,7 @@
 #include "prefs_common.h"
 #include "prefs_gtk.h"
 #include "prefs_migration.h"
 #include "prefs_common.h"
 #include "prefs_gtk.h"
 #include "prefs_migration.h"
+#include "claws_io.h"
 
 static GSList *_password_store;
 
 
 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);
 
        /* 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 */
                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;
        }
 
                return -1;
        }
 
@@ -382,8 +383,8 @@ static gint _write_to_file(FILE *fp)
                }
                line = g_strdup_printf("[%s:%s]\n", typestr, block->block_name);
 
                }
                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;
                }
                        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);
                                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;
                        }
                                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 */
                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;
                }
 
                        return -1;
                }
 
index 5d29ee51e9869a502e82d24ed8d2b743be239dba..d4b11d15ea39647abf7f9a8d353d5ed4585e7a38 100644 (file)
@@ -30,6 +30,7 @@
 #include "pine.h"
 #include "addritem.h"
 #include "addrcache.h"
 #include "pine.h"
 #include "addritem.h"
 #include "addrcache.h"
+#include "claws_io.h"
 
 #define PINE_HOME_FILE  ".addressbook"
 #define PINEBUFSIZE     2048
 
 #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 */
        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 );
 
        /* 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 ) {
  */
 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;
                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 );
  */
 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;
 }
 
        pineFile->file = NULL;
 }
 
@@ -140,7 +141,7 @@ static gchar *pine_read_line( PineFile *pineFile ) {
        int c, i = 0;
        gchar ch;
 
        int c, i = 0;
        gchar ch;
 
-       if( feof( pineFile->file ) ) 
+       if( claws_feof( pineFile->file ) ) 
                return NULL;
 
        while( i < PINEBUFSIZE-1 ) {
                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 */
        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 */
        }
        else {
                /* Truncate filename */
index 28e58c8c4ecb7b5ffb4bbdec3694145031bab78c..e32b65ca09410fdbcfce18311e1eb2e10dd2de22 100644 (file)
@@ -668,16 +668,16 @@ static void acpi_set(gboolean on)
        }
 
        if (!is_program(acpiprefs.file_path)) {
        }
 
        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) {
                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 {
                } 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,
        } else {
                gchar *cmd = g_strdup_printf("%s %s", 
                                acpiprefs.file_path,
index c6a978d4f982d793287ffa18d5c712361bc92088..590d39284fb33f935597b56be8226efd80aff323 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();
                                            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) 
                                                if (strstr(parts[2], "\n"))
                                                        *(strstr(parts[2], "\n")) = '\0';
                                                if (input && !output) 
-                                                       fclose (input);
+                                                       claws_fclose (input);
                                                else if (!input && output)
                                                else if (!input && output)
-                                                       fclose (output);
+                                                       claws_fclose (output);
                                                else if (input && output) {
                                                        gchar tmpbuf[BUFFSIZE];
                                                        gboolean err = FALSE;
                                                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]":"");
                                                                        "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 {
                                                                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;
                                                                        }
                                                                }
                                                        }
                                                                                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);
                                                                err = TRUE;
                                                        if (!err)
                                                                move_file(tmpfile, file, TRUE);
index 15122bb53c714afc68e68348325e0f16b70bfd56..831e0355e8745c2575d91e3f89a516085512f820 100644 (file)
@@ -55,6 +55,7 @@
 #include "statusbar.h"
 #include "alertpanel.h"
 #include "clamd-plugin.h"
 #include "statusbar.h"
 #include "alertpanel.h"
 #include "clamd-plugin.h"
+#include "claws_io.h"
 
 #ifndef UNIX_PATH_MAX
 #define UNIX_PATH_MAX 108
 
 #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);
        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;
        }
        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;
                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;
                                                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;
                                        }
                                                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);
        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 a7fa4db5dbccb07ab58c9df385153727b13b8cc7..9a6ff503a13fb7fc75ddbc01ea48e4597541cacd 100644 (file)
@@ -5,6 +5,10 @@ alertpanel
 alertpanel_error
 check_plugin_version
 claws_do_idle
 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
 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
 procmsg_register_spam_learner
 procmsg_spam_set_folder
 procmsg_unregister_spam_learner
-safe_fclose
 settings
 start_address_completion
 statusbar_pop_all
 settings
 start_address_completion
 statusbar_pop_all
index a1b434fbb0bafaf1213299eebb4e0df932847996..b4933c360d381afbc63bddf522108f42e5f6a2ea 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) {
 {
        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;
        }
                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)
 {
 }
 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)
                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
                curl_global_cleanup();
        }
 #ifdef USE_PTHREAD
index 924b5d1d88e9c0f4fcfa77dfc7a8e6d9d71d6d41..3fec5b6352d6bb1b8fd628d209e8d1f1d59e149e 100644 (file)
@@ -6,6 +6,10 @@ alertpanel_notice
 alertpanel_warning
 auto_configure_service_sync
 claws_unlink
 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
 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
 prefs_common_get_prefs
 procmsg_msginfo_add_avatar
 procmsg_msginfo_get_avatar
-safe_fclose
 slist_free_strings_full
 to_human_readable
 slist_free_strings_full
 to_human_readable
index 1482ae13c5cd477eb4e93dbd8ecc7d44b85c8c28..20bc3b2e0c714a55d0d61f6e56dacb0066897f01 100644 (file)
@@ -36,7 +36,7 @@
 
 static size_t write_image_data_cb(void *ptr, size_t size, size_t nmemb, void *stream)
 {
 
 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;
        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;
 
        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;
        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");
        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;
        }
 
                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);
        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
        if (filesize < MIN_PNG_SIZE)
                debug_print("not enough data for an avatar image: %ld bytes\n", filesize);
        else
index a19de486a5e4341526eb2f96008dbe37ebf6d45d..dc2d81fe53beb91284bdbeed622709816f39d7fe 100644 (file)
@@ -33,7 +33,7 @@
  */
 GHashTable *missing_load_from_file(const gchar *filename)
 {
  */
 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];
        time_t t;
        long long unsigned seen;
        gchar md5sum[33];
@@ -66,7 +66,7 @@ GHashTable *missing_load_from_file(const gchar *filename)
        }
 
 close_exit:
        }
 
 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);
                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));
 {
        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);
 }
                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)
 {
  */
 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);
 
        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));
 
        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;
        }
                g_warning("error closing '%s'", filename);
                return -1;
        }
index 0f686d31dc7eeb33f6b4a27da59a12d242228500..0efcc45e61073943aa75fad7da6df44e9f3d72fc 100644 (file)
@@ -3,6 +3,10 @@ EXPORTS
 get_locale_dir
 check_plugin_version
 alertpanel
 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
 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
 prefs_write_open
 prefs_write_param
 prefs_common_get_prefs
-safe_fclose
\ No newline at end of file
index af49ca4c444dcf53283b7bd66279dcfac0c11702..e932ca7ac5bcfa286c6c066d4dfb55fa7b75ec61 100644 (file)
  * $Id$
  */
 
  * $Id$
  */
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
+
 #include "mailimf.h"
 #include "mailimf.h"
+#include "claws_io.h"
 
 /*
   RFC 2822
 
 /*
   RFC 2822
index c592e8f3482b58e40c7b254a0b20316611e2f1cf..27352b5b39ed70904af073a51e9a7b5de55f06ef 100644 (file)
  * $Id$
  */
 
  * $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 "mailimf_write.h"
 
 #include <time.h>
 #include <string.h>
 #include <ctype.h>
+#include "claws_io.h"
 
 #define MAX_MAIL_COL 72
 
 
 #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 "
 
 #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;
     
   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;
   }
     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;
       
       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;
       
       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;
       
       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;
       
       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;
           
           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;
           
           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;
         
         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;
         
         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;
 
   int r;
   size_t i;
 
-  fputc('\"', f);
+  claws_fputc('\"', f);
   for(i = 0 ; i < len ; i ++) {
     switch (string[i]) {
     case '\\':
     case '\"':
   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;
       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:
       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;
     }
   }
       if (r < 0)
        return MAILIMF_ERROR_FILE;
       (* col) ++;
       break;
     }
   }
-  fputc('\"', f);
+  claws_fputc('\"', f);
 
   return MAILIMF_NO_ERROR;
 }
 
   return MAILIMF_NO_ERROR;
 }
index feb2453aec7d1ba34a4d12cace43e92d94520d80..b32af406cf1b8923440d1cda05642f2119203391 100644 (file)
  * $Id$
  */
 
  * $Id$
  */
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
+
 #include "mailmbox.h"
 
 #include <sys/file.h>
 #include "mailmbox.h"
 
 #include <sys/file.h>
@@ -54,6 +59,7 @@
 #include "mailmbox_parse.h"
 #include "maillock.h"
 #include "utils.h"
 #include "mailmbox_parse.h"
 #include "maillock.h"
 #include "utils.h"
+#include "claws_io.h"
 
 /*
   http://www.qmail.org/qmail-manual-html/man5/mbox.html
 
 /*
   http://www.qmail.org/qmail-manual-html/man5/mbox.html
index c8a77d898468778149818f642eb2bfe00010a456..569d9b70e9f9cf4d6f21d52247a9bb8d0b73d1f7 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);
         
        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;
         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) {
         if (r == 0) {
-                fclose(f);
+                claws_fclose(f);
                 return;
         }
         
                 return;
         }
         
-        fclose(f);
+        claws_fclose(f);
         
         * pmax_uid = max_uid;
 }
         
         * 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);
         
        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;
         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) {
         if (r == 0) {
-                fclose(f);
+                claws_fclose(f);
                 return;
         }
         
                 return;
         }
         
-        safe_fclose(f);
+        claws_safe_fclose(f);
 }
 
 static void claws_mailmbox_folder_item_destroy(Folder *folder, FolderItem *_item)
 }
 
 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);
                 goto free;
         
         old_mask = umask(0077);
-        f = fopen(file, "w");
+        f = claws_fopen(file, "w");
         umask(old_mask);
         if (f == NULL)
                 goto free;
         
         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;
         
         if (r == 0)
                 goto close;
         
-        safe_fclose(f);
+        claws_safe_fclose(f);
         
        return file;
         
  close:
         
        return file;
         
  close:
-        fclose(f);
+        claws_fclose(f);
         unlink(file);
  free:
         free(file);
         unlink(file);
  free:
         free(file);
index 46bc1bcb51912d4359787199a2664c46815948ce..b8c483cd5318e9e6fa82c2180a1d9af93db7fc8d 100644 (file)
@@ -31,6 +31,7 @@
 #include <inttypes.h>
 
 #include "plugin.h"
 #include <inttypes.h>
 
 #include "plugin.h"
+#include "claws_io.h"
 
 #define LOG_NAME       "NewLog"
 #define DEFAULT_DIR    "Mail"
 
 #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) {
 gboolean plugin_done (void)
 {
        if (NewLog) {
-               (void)fclose (NewLog);
+               (void)claws_fclose (NewLog);
                NewLog  = NULL;
        }
        if (LogName) {
                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);
                }
                        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);
                        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));
                                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 afeb83cdef38b519fc09bf6595f836ba590bba9b..a4bdda058c07915f734d2dd3fd46b6b90cc53efc 100644 (file)
@@ -45,6 +45,7 @@
 #include "common/log.h"
 #include "common/plugin.h"
 #include "common/tags.h"
 #include "common/log.h"
 #include "common/plugin.h"
 #include "common/tags.h"
+#include "claws_io.h"
 
 #include <EXTERN.h>
 #include <perl.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;
   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;
     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)
     XSRETURN_UNDEF;
   }
   if(message_file != NULL)
-    fclose(message_file);
+    claws_fclose(message_file);
   XSRETURN_YES;
 }
 
   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;
   }
     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;
     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);
 
   /* 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,
     *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");
   }
     FILE_OP_ERROR(perlfilter, "chmod");
     g_warning("Perl Plugin: Can't change file mode");
   }
-  fclose(fp);
+  claws_fclose(fp);
   g_free(perlfilter);
 
   argc = 1;
   g_free(perlfilter);
 
   argc = 1;
index be6aaf14d363ed05d7679ef53817333198c80cfd..87a931d4cdc40d711f99b4f33c998a2ef4a82735 100644 (file)
@@ -9,6 +9,10 @@ alertpanel_notice
 check_plugin_version
 claws_do_idle
 claws_unlink
 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
 conv_codeset_strdup
 conv_get_locale_charset_str_no_utf8
 codeconv_set_strict
index 66f8e9ba3602a3b24cd92b260762fbdf9249b08a..8d3e95cd209f0214906b5ff3caebad4d6ad5b10a 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "pgp_utils.h"
 #include "codeconv.h"
 
 #include "pgp_utils.h"
 #include "codeconv.h"
+#include "claws_io.h"
 
 gchar *fp_read_noconv(FILE *fp)
 {
 
 gchar *fp_read_noconv(FILE *fp)
 {
@@ -42,14 +43,14 @@ gchar *fp_read_noconv(FILE *fp)
                return NULL;
        array = g_byte_array_new();
 
                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);
        }
 
                        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;
        }
                g_byte_array_free(array, TRUE);
                return NULL;
        }
@@ -80,14 +81,14 @@ gchar *get_part_as_string(MimeInfo *mimeinfo)
                        g_free(filename);
                        return NULL;
                }
                        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);
                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);
        }
                g_unlink(filename);
                g_free(filename);
        }
index f79c8b6304a0fbf7315bf4026fb0af50942d55fb..6586295a60b392cf5f4eccf96f661d55a1fbcd4a 100644 (file)
@@ -59,6 +59,7 @@
 #include "account.h"
 #include "select-keys.h"
 #include "claws.h"
 #include "account.h"
 #include "select-keys.h"
 #include "claws.h"
+#include "claws_io.h"
 
 static void sgpgme_disable_all(void)
 {
 
 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;
 {
        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);
 
        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) {
 
        debug_print("data %p (%d %d)\n", (void *)&data, mimeinfo->offset, mimeinfo->length);
        if (err) {
index a07c65f892b4032a71c6833498b4cd5fd66664ea..4162a99709305100b7118dd8229207682a76b8ec 100644 (file)
@@ -1,6 +1,10 @@
 LIBRARY CLAWS-MAIL.EXE
 EXPORTS
 claws_unlink
 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
 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
 procmime_write_mimeinfo
 procmime_get_part
 procmime_get_tmp_file_name
-safe_fclose
\ No newline at end of file
index 4f8e789f23cd798871970ca21f1c47284f89b92d..d4bee071b348f8ea33bd468fec56e8cc0d6a7b95 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);
 
        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);
                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) {
        /* 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");
+           if (claws_fwrite(textdata, 1, pos - textdata, dstfp) < pos - textdata) {
+               FILE_OP_ERROR(fname, "claws_fwrite");
                privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                goto FILE_ERROR;
            }
        }
        
                privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                goto FILE_ERROR;
            }
        }
        
-       if (fwrite(_("\n--- Start of PGP/Inline encrypted data ---\n"), 1,
+       if (claws_fwrite(_("\n--- Start of PGP/Inline encrypted data ---\n"), 1,
                strlen(_("\n--- Start of PGP/Inline encrypted data ---\n")), 
                dstfp) < strlen(_("\n--- Start of PGP/Inline encrypted data ---\n"))) {
                strlen(_("\n--- Start of PGP/Inline encrypted data ---\n")), 
                dstfp) < strlen(_("\n--- Start of PGP/Inline encrypted data ---\n"))) {
-               FILE_OP_ERROR(fname, "fwrite");
+               FILE_OP_ERROR(fname, "claws_fwrite");
                privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                goto FILE_ERROR;
        }
        chars = sgpgme_data_release_and_get_mem(plain, &len);
        if (len > 0) {
                privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                goto FILE_ERROR;
        }
        chars = sgpgme_data_release_and_get_mem(plain, &len);
        if (len > 0) {
-               if (fwrite(chars, 1, len, dstfp) < len) {
-                       FILE_OP_ERROR(fname, "fwrite");
+               if (claws_fwrite(chars, 1, len, dstfp) < len) {
+                       FILE_OP_ERROR(fname, "claws_fwrite");
                        g_free(chars);
                        privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                        goto FILE_ERROR;
                        g_free(chars);
                        privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                        goto FILE_ERROR;
@@ -392,10 +392,10 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo)
        }
        g_free(chars);
        /* Store any part after encrypted text */
        }
        g_free(chars);
        /* Store any part after encrypted text */
-       if (fwrite(_("--- End of PGP/Inline encrypted data ---\n"), 1,
+       if (claws_fwrite(_("--- End of PGP/Inline encrypted data ---\n"), 1,
                strlen(_("--- End of PGP/Inline encrypted data ---\n")), 
                dstfp) < strlen(_("--- End of PGP/Inline encrypted data ---\n"))) {
                strlen(_("--- End of PGP/Inline encrypted data ---\n")), 
                dstfp) < strlen(_("--- End of PGP/Inline encrypted data ---\n"))) {
-                       FILE_OP_ERROR(fname, "fwrite");
+                       FILE_OP_ERROR(fname, "claws_fwrite");
                        privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                        goto FILE_ERROR;
        }
                        privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                        goto FILE_ERROR;
        }
@@ -403,16 +403,16 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo)
            pos = pgp_locate_armor_header(pos, end_indicator);
            if (pos != NULL && *pos != '\0') {
                pos += strlen(end_indicator);
            pos = pgp_locate_armor_header(pos, end_indicator);
            if (pos != NULL && *pos != '\0') {
                pos += strlen(end_indicator);
-               if (fwrite(pos, 1, strlen(pos), dstfp) < strlen(pos)) {
-                       FILE_OP_ERROR(fname, "fwrite");
+               if (claws_fwrite(pos, 1, strlen(pos), dstfp) < strlen(pos)) {
+                       FILE_OP_ERROR(fname, "claws_fwrite");
                        privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                        goto FILE_ERROR;
                }
            }
        }
 
                        privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                        goto FILE_ERROR;
                }
            }
        }
 
-       if (safe_fclose(dstfp) == EOF) {
-               FILE_OP_ERROR(fname, "fclose");
+       if (claws_safe_fclose(dstfp) == EOF) {
+               FILE_OP_ERROR(fname, "claws_fclose");
                privacy_set_error(_("Couldn't close decrypted file %s"), fname);
                g_free(fname);
                gpgme_data_release(plain);
                privacy_set_error(_("Couldn't close decrypted file %s"), fname);
                g_free(fname);
                gpgme_data_release(plain);
@@ -463,7 +463,7 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo)
        return decinfo;
 
 FILE_ERROR:
        return decinfo;
 
 FILE_ERROR:
-       fclose(dstfp);
+       claws_fclose(dstfp);
        g_free(fname);
        gpgme_data_release(plain);
        gpgme_release(ctx);
        g_free(fname);
        gpgme_data_release(plain);
        gpgme_release(ctx);
@@ -510,7 +510,7 @@ static gboolean pgpinline_sign(MimeInfo *mimeinfo, PrefsAccount *account, const
        /* read temporary file into memory */
        textstr = fp_read_noconv(fp);
        
        /* read temporary file into memory */
        textstr = fp_read_noconv(fp);
        
-       fclose(fp);
+       claws_fclose(fp);
                
        gpgme_data_new_from_mem(&gpgtext, textstr, (size_t)strlen(textstr), 0);
        gpgme_data_new(&gpgsig);
                
        gpgme_data_new_from_mem(&gpgtext, textstr, (size_t)strlen(textstr), 0);
        gpgme_data_new(&gpgsig);
@@ -704,7 +704,7 @@ static gboolean pgpinline_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        /* read temporary file into memory */
        textstr = fp_read_noconv(fp);
        
        /* read temporary file into memory */
        textstr = fp_read_noconv(fp);
        
-       fclose(fp);
+       claws_fclose(fp);
 
        /* encrypt data */
        gpgme_data_new_from_mem(&gpgtext, textstr, (size_t)strlen(textstr), 0);
 
        /* encrypt data */
        gpgme_data_new_from_mem(&gpgtext, textstr, (size_t)strlen(textstr), 0);
index 0d01d49e9fa17e8bbb9ccd4f330dba91021a7b2b..3855a69bda4b783b5c9a823c304b90093fc1bcdd 100644 (file)
@@ -1,6 +1,10 @@
 LIBRARY CLAWS-MAIL.EXE
 EXPORTS
 canonicalize_str
 LIBRARY CLAWS-MAIL.EXE
 EXPORTS
 canonicalize_str
+claws_fopen
+claws_fdopen
+claws_fclose
+claws_safe_fclose
 check_plugin_version
 debug_print_real
 debug_srcname
 check_plugin_version
 debug_print_real
 debug_srcname
@@ -18,4 +22,3 @@ procmime_mimeinfo_new
 procmime_mimeinfo_parent
 procmime_scan_file
 procmime_write_mimeinfo
 procmime_mimeinfo_parent
 procmime_scan_file
 procmime_write_mimeinfo
-safe_fclose
\ No newline at end of file
index 382748787c6bed29c2ff8e4929b70d5d6b27baf8..d768de4009a14a9bc89767981f52ca108a6eee2a 100644 (file)
@@ -144,12 +144,12 @@ static gchar *get_canonical_content(FILE *fp, const gchar *boundary)
        gchar buf[BUFFSIZE];
 
        boundary_len = strlen(boundary);
        gchar buf[BUFFSIZE];
 
        boundary_len = strlen(boundary);
-       while (fgets(buf, sizeof(buf), fp) != NULL)
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL)
                if (IS_BOUNDARY(buf, boundary, boundary_len))
                        break;
 
        textbuffer = g_string_new("");
                if (IS_BOUNDARY(buf, boundary, boundary_len))
                        break;
 
        textbuffer = g_string_new("");
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                gchar *buf2;
 
                if (IS_BOUNDARY(buf, boundary, boundary_len))
                gchar *buf2;
 
                if (IS_BOUNDARY(buf, boundary, boundary_len))
@@ -196,13 +196,13 @@ static gint pgpmime_check_signature(MimeInfo *mimeinfo)
        }
        parent = procmime_mimeinfo_parent(mimeinfo);
 
        }
        parent = procmime_mimeinfo_parent(mimeinfo);
 
-       fp = g_fopen(parent->data.filename, "rb");
+       fp = claws_fopen(parent->data.filename, "rb");
        cm_return_val_if_fail(fp != NULL, SIGNATURE_INVALID);
        
        boundary = g_hash_table_lookup(parent->typeparameters, "boundary");
        if (!boundary) {
                privacy_set_error(_("Signature boundary not found."));
        cm_return_val_if_fail(fp != NULL, SIGNATURE_INVALID);
        
        boundary = g_hash_table_lookup(parent->typeparameters, "boundary");
        if (!boundary) {
                privacy_set_error(_("Signature boundary not found."));
-               fclose(fp);
+               claws_fclose(fp);
                return 0;
        }
        textstr = get_canonical_content(fp, boundary);
                return 0;
        }
        textstr = get_canonical_content(fp, boundary);
@@ -231,7 +231,7 @@ static gint pgpmime_check_signature(MimeInfo *mimeinfo)
        gpgme_data_release(sigdata);
        gpgme_data_release(textdata);
        g_free(textstr);
        gpgme_data_release(sigdata);
        gpgme_data_release(textdata);
        g_free(textstr);
-       fclose(fp);
+       claws_fclose(fp);
        
        return 0;
 }
        
        return 0;
 }
@@ -348,8 +348,8 @@ static MimeInfo *pgpmime_decrypt(MimeInfo *mimeinfo)
        fname = g_strdup_printf("%s%cplaintext.%08x",
                get_mime_tmp_dir(), G_DIR_SEPARATOR, ++id);
 
        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);
                privacy_set_error(_("Couldn't open decrypted file %s"), fname);
                g_free(fname);
                gpgme_data_release(plain);
@@ -360,7 +360,7 @@ static MimeInfo *pgpmime_decrypt(MimeInfo *mimeinfo)
 
        if (fprintf(dstfp, "MIME-Version: 1.0\n") < 0) {
                FILE_OP_ERROR(fname, "fprintf");
 
        if (fprintf(dstfp, "MIME-Version: 1.0\n") < 0) {
                FILE_OP_ERROR(fname, "fprintf");
-               fclose(dstfp);
+               claws_fclose(dstfp);
                privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                g_free(fname);
                gpgme_data_release(plain);
                privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                g_free(fname);
                gpgme_data_release(plain);
@@ -371,10 +371,10 @@ static MimeInfo *pgpmime_decrypt(MimeInfo *mimeinfo)
 
        chars = sgpgme_data_release_and_get_mem(plain, &len);
        if (len > 0) {
 
        chars = sgpgme_data_release_and_get_mem(plain, &len);
        if (len > 0) {
-               if (fwrite(chars, 1, len, dstfp) < len) {
-                       FILE_OP_ERROR(fname, "fwrite");
+               if (claws_fwrite(chars, 1, len, dstfp) < len) {
+                       FILE_OP_ERROR(fname, "claws_fwrite");
                        g_free(chars);
                        g_free(chars);
-                       fclose(dstfp);
+                       claws_fclose(dstfp);
                        privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                        g_free(fname);
                        gpgme_data_release(plain);
                        privacy_set_error(_("Couldn't write to decrypted file %s"), fname);
                        g_free(fname);
                        gpgme_data_release(plain);
@@ -385,8 +385,8 @@ static MimeInfo *pgpmime_decrypt(MimeInfo *mimeinfo)
        }
        g_free(chars);
 
        }
        g_free(chars);
 
-       if (safe_fclose(dstfp) == EOF) {
-               FILE_OP_ERROR(fname, "fclose");
+       if (claws_safe_fclose(dstfp) == EOF) {
+               FILE_OP_ERROR(fname, "claws_fclose");
                privacy_set_error(_("Couldn't close decrypted file %s"), fname);
                g_free(fname);
                gpgme_data_release(plain);
                privacy_set_error(_("Couldn't close decrypted file %s"), fname);
                g_free(fname);
                gpgme_data_release(plain);
@@ -462,7 +462,7 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *fr
 
        /* read temporary file into memory */
        test_msg = file_read_stream_to_str(fp);
 
        /* read temporary file into memory */
        test_msg = file_read_stream_to_str(fp);
-       fclose(fp);
+       claws_fclose(fp);
        
        memset (&info, 0, sizeof info);
 
        
        memset (&info, 0, sizeof info);
 
@@ -503,7 +503,7 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *fr
        textstr = get_canonical_content(fp, boundary);
 
        g_free(boundary);
        textstr = get_canonical_content(fp, boundary);
 
        g_free(boundary);
-       fclose(fp);
+       claws_fclose(fp);
 
        gpgme_data_new_from_mem(&gpgtext, textstr, (size_t)strlen(textstr), 0);
        gpgme_data_new(&gpgsig);
 
        gpgme_data_new_from_mem(&gpgtext, textstr, (size_t)strlen(textstr), 0);
        gpgme_data_new(&gpgsig);
@@ -703,7 +703,7 @@ gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        textstr = get_canonical_content(fp, boundary);
 
        g_free(boundary);
        textstr = get_canonical_content(fp, boundary);
 
        g_free(boundary);
-       fclose(fp);
+       claws_fclose(fp);
 
        /* encrypt data */
        gpgme_data_new_from_mem(&gpgtext, textstr, (size_t)strlen(textstr), 0);
 
        /* encrypt data */
        gpgme_data_new_from_mem(&gpgtext, textstr, (size_t)strlen(textstr), 0);
index db4ff8f94ecf22079b34369452f1fd26962e08e9..69c4e06efa0edbc51a7196ae5e0be98cb24667d2 100644 (file)
@@ -39,6 +39,7 @@
 #include "python-shell.h"
 #include "python-hooks.h"
 #include "clawsmailmodule.h"
 #include "python-shell.h"
 #include "python-hooks.h"
 #include "clawsmailmodule.h"
+#include "claws_io.h"
 
 #define PYTHON_SCRIPTS_BASE_DIR "python-scripts"
 #define PYTHON_SCRIPTS_MAIN_DIR "main"
 
 #define PYTHON_SCRIPTS_BASE_DIR "python-scripts"
 #define PYTHON_SCRIPTS_MAIN_DIR "main"
@@ -158,7 +159,7 @@ static gchar* extract_filename(const gchar *str)
 static void run_script_file(const gchar *filename, Compose *compose)
 {
   FILE *fp;
 static void run_script_file(const gchar *filename, Compose *compose)
 {
   FILE *fp;
-  fp = fopen(filename, "r");
+  fp = claws_fopen(filename, "r");
   if(!fp) {
     debug_print("Error: Could not open file '%s'\n", filename);
     return;
   if(!fp) {
     debug_print("Error: Could not open file '%s'\n", filename);
     return;
@@ -166,7 +167,7 @@ static void run_script_file(const gchar *filename, Compose *compose)
   put_composewindow_into_module(compose);
   if(PyRun_SimpleFile(fp, filename) == 0)
     debug_print("Problem running script file '%s'\n", filename);
   put_composewindow_into_module(compose);
   if(PyRun_SimpleFile(fp, filename) == 0)
     debug_print("Problem running script file '%s'\n", filename);
-  fclose(fp);
+  claws_fclose(fp);
 }
 
 static void run_auto_script_file_if_it_exists(const gchar *autofilename, Compose *compose)
 }
 
 static void run_auto_script_file_if_it_exists(const gchar *autofilename, Compose *compose)
index 6fc560f824bbef73728bd8d019551ee970b6dcc1..85de45e36d73cc948a12e9f86162afa8a07978d2 100644 (file)
@@ -9,6 +9,10 @@ claws_is_exiting
 claws_is_starting
 claws_ssl_get_cert_file
 claws_unlink
 claws_is_starting
 claws_ssl_get_cert_file
 claws_unlink
+claws_fopen
+claws_fdopen
+claws_fclose
+claws_safe_fclose
 cm_menu_set_sensitive_full
 conv_encode_header_full
 conv_unmime_header
 cm_menu_set_sensitive_full
 conv_encode_header_full
 conv_unmime_header
@@ -116,7 +120,6 @@ procheader_parse_file
 procmsg_get_message_file
 procmsg_msginfo_unset_flags
 remove_dir_recursive
 procmsg_get_message_file
 procmsg_msginfo_unset_flags
 remove_dir_recursive
-safe_fclose
 slist_free_strings_full
 strtailchomp
 subst_for_shellsafe_filename
 slist_free_strings_full
 strtailchomp
 subst_for_shellsafe_filename
index 20649dbeb12657825ff37ac0010d5da45116daa2..d87169bcf1e30c22b40f38caf2cb0f61840d18a3 100644 (file)
@@ -137,7 +137,7 @@ void rssyl_opml_export(void)
                }
        }
        
                }
        }
        
-       if( (f = g_fopen(opmlfile, "w")) == NULL ) {
+       if( (f = claws_fopen(opmlfile, "w")) == NULL ) {
                log_warning(LOG_PROTOCOL,
                                _("RSSyl: Couldn't open file '%s' for feed list exporting: %s\n"),
                                opmlfile, g_strerror(errno));
                log_warning(LOG_PROTOCOL,
                                _("RSSyl: Couldn't open file '%s' for feed list exporting: %s\n"),
                                opmlfile, g_strerror(errno));
@@ -186,7 +186,7 @@ void rssyl_opml_export(void)
 
        debug_print("RSSyl: Feed export finished.\n");
 
 
        debug_print("RSSyl: Feed export finished.\n");
 
-       safe_fclose(f);
+       claws_safe_fclose(f);
        g_free(opmlfile);
        g_free(ctx);
 }
        g_free(opmlfile);
        g_free(ctx);
 }
index a7906fd3b8c222000aa35fc624f7ee27de045116..cc9d8dd3a3ad9c92445cbd610db5dac1e30ce8ac 100644 (file)
@@ -408,7 +408,7 @@ void rssyl_add_item(RFolderItem *ritem, FeedItem *feed_item)
                return;
        }
 
                return;
        }
 
-       f = fdopen(fd, "w");
+       f = claws_fdopen(fd, "w");
        if (f == NULL) {
                g_warning("Couldn't open file '%s', not adding message!", template);
                g_free(dirname);
        if (f == NULL) {
                g_warning("Couldn't open file '%s', not adding message!", template);
                g_free(dirname);
@@ -547,7 +547,7 @@ void rssyl_add_item(RFolderItem *ritem, FeedItem *feed_item)
                                feed_item_enclosure_get_size(enc) );
 
        fprintf(f, "</body></html>\n");
                                feed_item_enclosure_get_size(enc) );
 
        fprintf(f, "</body></html>\n");
-       safe_fclose(f);
+       claws_safe_fclose(f);
 
        g_return_if_fail(template != NULL);
 
 
        g_return_if_fail(template != NULL);
 
index 11e2ed1f9749c159298706c7fc2bbfdb110dc7a5..c8c6395fd0a5226fd4ba43970e18d9937a6cf6a0 100644 (file)
@@ -181,7 +181,7 @@ static void rssyl_deleted_store_internal(GSList *deleted_items, const gchar *del
        if (g_slist_length(deleted_items) == 0)
                return;
 
        if (g_slist_length(deleted_items) == 0)
                return;
 
-       if ((f = g_fopen(deleted_file, "w")) == NULL) {
+       if ((f = claws_fopen(deleted_file, "w")) == NULL) {
                debug_print("RSSyl: Couldn't open '%s', bailing out.\n", deleted_file);
                return;
        }
                debug_print("RSSyl: Couldn't open '%s', bailing out.\n", deleted_file);
                return;
        }
@@ -189,7 +189,7 @@ static void rssyl_deleted_store_internal(GSList *deleted_items, const gchar *del
        g_slist_foreach(deleted_items, (GFunc)_store_one_deleted_item,
                        (gpointer)f);
 
        g_slist_foreach(deleted_items, (GFunc)_store_one_deleted_item,
                        (gpointer)f);
 
-       safe_fclose(f);
+       claws_safe_fclose(f);
        debug_print("RSSyl: written and closed deletion file\n");
 }
 
        debug_print("RSSyl: written and closed deletion file\n");
 }
 
index 09f67d1488892ae8dba8ba05162994e9fb2b9588..a3eeed5ef09a17c4974564f9f7f7ec9efc53a326 100644 (file)
@@ -3,6 +3,10 @@ EXPORTS
 alertpanel_error
 canonicalize_file_replace
 canonicalize_str
 alertpanel_error
 canonicalize_file_replace
 canonicalize_str
+claws_fopen
+claws_fdopen
+claws_fclose
+claws_safe_fclose
 check_plugin_version
 claws_unlink
 debug_print_real
 check_plugin_version
 claws_unlink
 debug_print_real
@@ -26,5 +30,4 @@ procmime_mimeinfo_parent
 procmime_scan_file
 procmime_write_mime_header
 procmime_write_mimeinfo
 procmime_scan_file
 procmime_write_mime_header
 procmime_write_mimeinfo
-safe_fclose
 str_write_to_file
 str_write_to_file
index abc49c8f04df6ce9a9b04f637cff940ec6d055ca..82edd929a8d27e9130dc1c9a5d3e0800cd51bc50 100644 (file)
@@ -171,13 +171,13 @@ static gchar *get_canonical_content(FILE *fp, const gchar *boundary)
 
        if (boundary) {
                boundary_len = strlen(boundary);
 
        if (boundary) {
                boundary_len = strlen(boundary);
-               while (fgets(buf, sizeof(buf), fp) != NULL)
+               while (claws_fgets(buf, sizeof(buf), fp) != NULL)
                        if (IS_BOUNDARY(buf, boundary, boundary_len))
                                break;
        }
        
        textbuffer = g_string_new("");
                        if (IS_BOUNDARY(buf, boundary, boundary_len))
                                break;
        }
        
        textbuffer = g_string_new("");
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                gchar *buf2;
 
                if (boundary && IS_BOUNDARY(buf, boundary, boundary_len))
                gchar *buf2;
 
                if (boundary && IS_BOUNDARY(buf, boundary, boundary_len))
@@ -230,7 +230,7 @@ static gint smime_check_signature(MimeInfo *mimeinfo)
        }
        parent = procmime_mimeinfo_parent(mimeinfo);
 
        }
        parent = procmime_mimeinfo_parent(mimeinfo);
 
-       fp = g_fopen(parent->data.filename, "rb");
+       fp = claws_fopen(parent->data.filename, "rb");
        cm_return_val_if_fail(fp != NULL, SIGNATURE_INVALID);
        
        boundary = g_hash_table_lookup(parent->typeparameters, "boundary");
        cm_return_val_if_fail(fp != NULL, SIGNATURE_INVALID);
        
        boundary = g_hash_table_lookup(parent->typeparameters, "boundary");
@@ -278,7 +278,7 @@ static gint smime_check_signature(MimeInfo *mimeinfo)
                        g_free(textstr);
                        cm_gpgme_data_rewind(cipher);
                        textstr = sgpgme_data_release_and_get_mem(cipher, &len);
                        g_free(textstr);
                        cm_gpgme_data_rewind(cipher);
                        textstr = sgpgme_data_release_and_get_mem(cipher, &len);
-                       fclose(fp);
+                       claws_fclose(fp);
                        if (textstr && len > 0)
                                textstr[len-1]='\0';
 
                        if (textstr && len > 0)
                                textstr[len-1]='\0';
 
@@ -343,7 +343,7 @@ static gint smime_check_signature(MimeInfo *mimeinfo)
        gpgme_data_release(sigdata);
        gpgme_data_release(textdata);
        g_free(textstr);
        gpgme_data_release(sigdata);
        gpgme_data_release(textdata);
        g_free(textstr);
-       fclose(fp);
+       claws_fclose(fp);
        
        return 0;
 }
        
        return 0;
 }
@@ -445,8 +445,8 @@ static MimeInfo *smime_decrypt(MimeInfo *mimeinfo)
        fname = g_strdup_printf("%s%cplaintext.%08x",
                get_mime_tmp_dir(), G_DIR_SEPARATOR, ++id);
 
        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, "g_fopen");
+       if ((dstfp = claws_fopen(fname, "wb")) == NULL) {
+               FILE_OP_ERROR(fname, "claws_fopen");
                g_free(fname);
                gpgme_data_release(plain);
                gpgme_release(ctx);
                g_free(fname);
                gpgme_data_release(plain);
                gpgme_release(ctx);
@@ -458,7 +458,7 @@ static MimeInfo *smime_decrypt(MimeInfo *mimeinfo)
        if (fprintf(dstfp, "MIME-Version: 1.0\n") < 0) {
                FILE_OP_ERROR(fname, "fprintf");
                g_free(fname);
        if (fprintf(dstfp, "MIME-Version: 1.0\n") < 0) {
                FILE_OP_ERROR(fname, "fprintf");
                g_free(fname);
-               fclose(dstfp);
+               claws_fclose(dstfp);
                gpgme_data_release(plain);
                gpgme_release(ctx);
                debug_print("can't close!\n");
                gpgme_data_release(plain);
                gpgme_release(ctx);
                debug_print("can't close!\n");
@@ -469,9 +469,9 @@ static MimeInfo *smime_decrypt(MimeInfo *mimeinfo)
        chars = sgpgme_data_release_and_get_mem(plain, &len);
 
        if (len > 0) {
        chars = sgpgme_data_release_and_get_mem(plain, &len);
 
        if (len > 0) {
-               if (fwrite(chars, 1, len, dstfp) < len) {
-                       FILE_OP_ERROR(fname, "fwrite");
-                       fclose(dstfp);
+               if (claws_fwrite(chars, 1, len, dstfp) < len) {
+                       FILE_OP_ERROR(fname, "claws_fwrite");
+                       claws_fclose(dstfp);
                        g_free(fname);
                        g_free(chars);
                        gpgme_data_release(plain);
                        g_free(fname);
                        g_free(chars);
                        gpgme_data_release(plain);
@@ -481,8 +481,8 @@ static MimeInfo *smime_decrypt(MimeInfo *mimeinfo)
                        return NULL;
                }
        }
                        return NULL;
                }
        }
-       if (safe_fclose(dstfp) == EOF) {
-               FILE_OP_ERROR(fname, "fclose");
+       if (claws_safe_fclose(dstfp) == EOF) {
+               FILE_OP_ERROR(fname, "claws_fclose");
                g_free(fname);
                        g_free(chars);
                gpgme_data_release(plain);
                g_free(fname);
                        g_free(chars);
                gpgme_data_release(plain);
@@ -564,7 +564,7 @@ gboolean smime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *from
 
        /* read temporary file into memory */
        test_msg = file_read_stream_to_str(fp);
 
        /* read temporary file into memory */
        test_msg = file_read_stream_to_str(fp);
-       fclose(fp);
+       claws_fclose(fp);
        
        memset (&info, 0, sizeof info);
 
        
        memset (&info, 0, sizeof info);
 
@@ -606,7 +606,7 @@ gboolean smime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *from
 
        g_free(boundary);
 
 
        g_free(boundary);
 
-       fclose(fp);
+       claws_fclose(fp);
 
        gpgme_data_new_from_mem(&gpgtext, textstr, textstr?strlen(textstr):0, 0);
        gpgme_data_new(&gpgsig);
 
        gpgme_data_new_from_mem(&gpgtext, textstr, textstr?strlen(textstr):0, 0);
        gpgme_data_new(&gpgsig);
@@ -796,7 +796,7 @@ gboolean smime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
 
        /* write message content to temporary file */
        tmpfile = get_tmp_file();
 
        /* write message content to temporary file */
        tmpfile = get_tmp_file();
-       fp = g_fopen(tmpfile, "wb");
+       fp = claws_fopen(tmpfile, "wb");
        if (fp == NULL) {
                FILE_OP_ERROR(tmpfile, "create");
                g_free(kset);
        if (fp == NULL) {
                FILE_OP_ERROR(tmpfile, "create");
                g_free(kset);
@@ -805,9 +805,9 @@ gboolean smime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        procmime_decode_content(msgcontent);
        procmime_write_mime_header(msgcontent, fp);
        procmime_write_mimeinfo(msgcontent, fp);
        procmime_decode_content(msgcontent);
        procmime_write_mime_header(msgcontent, fp);
        procmime_write_mimeinfo(msgcontent, fp);
-       safe_fclose(fp);
+       claws_safe_fclose(fp);
        canonicalize_file_replace(tmpfile);
        canonicalize_file_replace(tmpfile);
-       fp = g_fopen(tmpfile, "rb");
+       fp = claws_fopen(tmpfile, "rb");
        if (fp == NULL) {
                FILE_OP_ERROR(tmpfile, "open");
                g_free(kset);
        if (fp == NULL) {
                FILE_OP_ERROR(tmpfile, "open");
                g_free(kset);
@@ -818,7 +818,7 @@ gboolean smime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        /* read temporary file into memory */
        textstr = fp_read_noconv(fp);
 
        /* read temporary file into memory */
        textstr = fp_read_noconv(fp);
 
-       fclose(fp);
+       claws_fclose(fp);
 
        /* encrypt data */
        gpgme_data_new_from_mem(&gpgtext, textstr, textstr?strlen(textstr):0, 0);
 
        /* encrypt data */
        gpgme_data_new_from_mem(&gpgtext, textstr, textstr?strlen(textstr):0, 0);
@@ -837,18 +837,18 @@ gboolean smime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        }
 
        tmpfile = get_tmp_file();
        }
 
        tmpfile = get_tmp_file();
-       fp = g_fopen(tmpfile, "wb");
+       fp = claws_fopen(tmpfile, "wb");
        if (fp) {
        if (fp) {
-               if (fwrite(enccontent, 1, len, fp) < len) {
-                       FILE_OP_ERROR(tmpfile, "fwrite");
-                       fclose(fp);
+               if (claws_fwrite(enccontent, 1, len, fp) < len) {
+                       FILE_OP_ERROR(tmpfile, "claws_fwrite");
+                       claws_fclose(fp);
                        claws_unlink(tmpfile);
                        g_free(tmpfile);
                        g_free(enccontent);
                        return FALSE;
                }
                        claws_unlink(tmpfile);
                        g_free(tmpfile);
                        g_free(enccontent);
                        return FALSE;
                }
-               if (safe_fclose(fp) == EOF) {
-                       FILE_OP_ERROR(tmpfile, "fclose");
+               if (claws_safe_fclose(fp) == EOF) {
+                       FILE_OP_ERROR(tmpfile, "claws_fclose");
                        claws_unlink(tmpfile);
                        g_free(tmpfile);
                        g_free(enccontent);
                        claws_unlink(tmpfile);
                        g_free(tmpfile);
                        g_free(enccontent);
index e664adb9011a162ca863310dcd441137cb1224da..5c0632c4ac2b5bccc6a3f7f715a4432ab8008bcd 100644 (file)
@@ -51,6 +51,7 @@
 #include "prefs_common.h"
 #include "alertpanel.h"
 #include "addr_compl.h"
 #include "prefs_common.h"
 #include "alertpanel.h"
 #include "addr_compl.h"
+#include "claws_io.h"
 
 #ifdef HAVE_SYSEXITS_H
 #include <sysexits.h>
 
 #ifdef HAVE_SYSEXITS_H
 #include <sysexits.h>
@@ -253,7 +254,7 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data)
                
                if (whitelisted) {
                        debug_print("message is ham (whitelisted)\n");
                
                if (whitelisted) {
                        debug_print("message is ham (whitelisted)\n");
-                       fclose(fp);
+                       claws_fclose(fp);
                        return FALSE;
                }
        }
                        return FALSE;
                }
        }
@@ -291,7 +292,7 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data)
                        g_main_context_iteration(NULL, TRUE);
        }
 
                        g_main_context_iteration(NULL, TRUE);
        }
 
-       fclose(fp);
+       claws_fclose(fp);
 
        if (is_spam) {
                debug_print("message is spam\n");
 
        if (is_spam) {
                debug_print("message is spam\n");
index 28eadc10dad8131e27d0e100891f2a7339dadb3c..b55dd9cd88fec80636e005925518f4b9044f8f2b 100644 (file)
@@ -1,5 +1,9 @@
 LIBRARY CLAWS-MAIL.EXE
 EXPORTS
 LIBRARY CLAWS-MAIL.EXE
 EXPORTS
+claws_fopen
+claws_fdopen
+claws_fclose
+claws_safe_fclose
 get_locale_dir
 check_plugin_version
 claws_unlink
 get_locale_dir
 check_plugin_version
 claws_unlink
index 6f0f86fd0716574e40994c26030663d9da596d2a..93ef6328307af870fe21f643cee3d1cee4503a68 100644 (file)
@@ -48,6 +48,7 @@
 #include "plugin.h"
 #include "procmime.h"
 #include "utils.h"
 #include "plugin.h"
 #include "procmime.h"
 #include "utils.h"
+#include "claws_io.h"
 
 #include "tnef_dump.h"
 
 
 #include "tnef_dump.h"
 
@@ -74,7 +75,7 @@ static MimeInfo *tnef_broken_mimeinfo(const gchar *reason)
                        "Claws Mail TNEF parser:\n\n"
                        "%s\n"), reason?reason:_("Unknown error"));
 
                        "Claws Mail TNEF parser:\n\n"
                        "%s\n"), reason?reason:_("Unknown error"));
 
-       fclose(fp);
+       claws_fclose(fp);
        if (g_stat(tmpfilename, &statbuf) < 0) {
                claws_unlink(tmpfilename);
                procmime_mimeinfo_free_all(&sub_info);
        if (g_stat(tmpfilename, &statbuf) < 0) {
                claws_unlink(tmpfilename);
                procmime_mimeinfo_free_all(&sub_info);
@@ -122,14 +123,14 @@ static MimeInfo *tnef_dump_file(const gchar *filename, char *data, size_t size)
                }
        } 
 
                }
        } 
 
-       if (fwrite(data, 1, size, fp) < size) {
-               FILE_OP_ERROR(tmpfilename, "fwrite");
-               fclose(fp);
+       if (claws_fwrite(data, 1, size, fp) < size) {
+               FILE_OP_ERROR(tmpfilename, "claws_fwrite");
+               claws_fclose(fp);
                claws_unlink(tmpfilename);
                procmime_mimeinfo_free_all(&sub_info);
                return tnef_broken_mimeinfo(_("Failed to write the part data."));
        }
                claws_unlink(tmpfilename);
                procmime_mimeinfo_free_all(&sub_info);
                return tnef_broken_mimeinfo(_("Failed to write the part data."));
        }
-       fclose(fp);
+       claws_fclose(fp);
 
        if (g_stat(tmpfilename, &statbuf) < 0) {
                claws_unlink(tmpfilename);
 
        if (g_stat(tmpfilename, &statbuf) < 0) {
                claws_unlink(tmpfilename);
@@ -166,7 +167,7 @@ MimeInfo *tnef_parse_vcal(TNEFStruct *tnef)
 
        result = SaveVCalendar(fp, tnef);
 
 
        result = SaveVCalendar(fp, tnef);
 
-       fclose(fp);
+       claws_fclose(fp);
 
        if (g_stat(tmpfilename, &statbuf) < 0) {
                result = FALSE;
 
        if (g_stat(tmpfilename, &statbuf) < 0) {
                result = FALSE;
@@ -206,7 +207,7 @@ MimeInfo *tnef_parse_vtask(TNEFStruct *tnef)
 
        result = SaveVTask(fp, tnef);
 
 
        result = SaveVTask(fp, tnef);
 
-       fclose(fp);
+       claws_fclose(fp);
 
        if (g_stat(tmpfilename, &statbuf) < 0) {
                result = FALSE;
 
        if (g_stat(tmpfilename, &statbuf) < 0) {
                result = FALSE;
@@ -260,7 +261,7 @@ MimeInfo *tnef_parse_vcard(TNEFStruct *tnef)
        
        result = SaveVCard(fp, tnef);
        
        
        result = SaveVCard(fp, tnef);
        
-       fclose(fp);
+       claws_fclose(fp);
 
        ret = g_stat(tmpfilename, &statbuf);
        if (ret == -1) {
 
        ret = g_stat(tmpfilename, &statbuf);
        if (ret == -1) {
index f6d4208976cdbcc0a9824ade4fe56500c360859d..6bfa5239ff698e3650cf37c8e22ca980189b4e97 100644 (file)
@@ -17,6 +17,10 @@ alertpanel_full
 alertpanel_notice
 claws_do_idle
 claws_unlink
 alertpanel_notice
 claws_do_idle
 claws_unlink
+claws_fopen
+claws_fdopen
+claws_fclose
+claws_safe_fclose
 cm_menu_create_action_group_full
 cm_menu_set_sensitive_full
 cm_toggle_menu_set_active_full
 cm_menu_create_action_group_full
 cm_menu_set_sensitive_full
 cm_toggle_menu_set_active_full
@@ -144,7 +148,6 @@ procmsg_msginfo_get_full_info
 procmsg_send_message_queue_with_lock
 qp_encode_line
 remove_dir_recursive
 procmsg_send_message_queue_with_lock
 qp_encode_line
 remove_dir_recursive
-safe_fclose
 slist_free_strings
 slist_free_strings_full
 statusbar_progress_all
 slist_free_strings
 slist_free_strings_full
 statusbar_progress_all
index 49a29176ad67dbbe6ad6f8a36251d7bdece42d39..befe163db4f6a0906aeacf336edf520efb3ec11c 100644 (file)
@@ -1850,7 +1850,7 @@ void multisync_export(void)
        g_slist_free(list);
        
        file = g_strconcat(path, G_DIR_SEPARATOR_S, "backup_entries", NULL);
        g_slist_free(list);
        
        file = g_strconcat(path, G_DIR_SEPARATOR_S, "backup_entries", NULL);
-       fp = g_fopen(file, "wb");
+       fp = claws_fopen(file, "wb");
        g_free(file);
        if (fp) {
                for (cur = files; cur; cur = cur->next) {
        g_free(file);
        if (fp) {
                for (cur = files; cur; cur = cur->next) {
@@ -1859,10 +1859,10 @@ void multisync_export(void)
                                FILE_OP_ERROR(file, "fprintf");
                        g_free(file);
                }
                                FILE_OP_ERROR(file, "fprintf");
                        g_free(file);
                }
-               if (safe_fclose(fp) == EOF)
-                       FILE_OP_ERROR(file, "fclose");
+               if (claws_safe_fclose(fp) == EOF)
+                       FILE_OP_ERROR(file, "claws_fclose");
        } else {
        } else {
-               FILE_OP_ERROR(file, "fopen");
+               FILE_OP_ERROR(file, "claws_fopen");
        }
        g_free(path);
        g_slist_free(files);
        }
        g_free(path);
        g_slist_free(files);
@@ -1982,7 +1982,7 @@ putfile:
                g_free(afile);
                g_free(file);
        } else if (file) {
                g_free(afile);
                g_free(file);
        } else if (file) {
-               FILE *fp = g_fopen(tmpfile, "rb");
+               FILE *fp = claws_fopen(tmpfile, "rb");
                if (!strncmp(file, "webcal", 6)) {
                        gchar *tmp = g_strdup_printf("http%s", file+6);
                        g_free(file);
                if (!strncmp(file, "webcal", 6)) {
                        gchar *tmp = g_strdup_printf("http%s", file+6);
                        g_free(file);
@@ -1990,7 +1990,7 @@ putfile:
                }
                if (fp) {
                        res = vcal_curl_put(file, fp, filesize, user, (pass != NULL ? pass : ""));
                }
                if (fp) {
                        res = vcal_curl_put(file, fp, filesize, user, (pass != NULL ? pass : ""));
-                       fclose(fp);
+                       claws_fclose(fp);
                }
                g_free(file);
        }
                }
                g_free(file);
        }
@@ -2130,7 +2130,7 @@ gboolean vcal_meeting_export_freebusy(const gchar *path, const gchar *user,
                g_free(afile);
                g_free(file);
        } else if (file) {
                g_free(afile);
                g_free(file);
        } else if (file) {
-               FILE *fp = g_fopen(tmpfile, "rb");
+               FILE *fp = claws_fopen(tmpfile, "rb");
                if (!strncmp(file, "webcal", 6)) {
                        gchar *tmp = g_strdup_printf("http%s", file+6);
                        g_free(file);
                if (!strncmp(file, "webcal", 6)) {
                        gchar *tmp = g_strdup_printf("http%s", file+6);
                        g_free(file);
@@ -2138,7 +2138,7 @@ gboolean vcal_meeting_export_freebusy(const gchar *path, const gchar *user,
                }
                if (fp) {
                        res = vcal_curl_put(file, fp, filesize, user, (pass != NULL ? pass : ""));
                }
                if (fp) {
                        res = vcal_curl_put(file, fp, filesize, user, (pass != NULL ? pass : ""));
-                       fclose(fp);
+                       claws_fclose(fp);
                }
                g_free(file);
        }
                }
                g_free(file);
        }
index 9fd68dfee019ec65412727c7dcffcadd58576c17..386a48acb9b58c1009a268c17b060338b549dfeb 100644 (file)
@@ -54,6 +54,7 @@
 #include "statusbar.h"
 #include "timing.h"
 #include "inc.h"
 #include "statusbar.h"
 #include "timing.h"
 #include "inc.h"
+#include "claws_io.h"
 
 MimeViewerFactory vcal_viewer_factory;
 
 
 MimeViewerFactory vcal_viewer_factory;
 
@@ -166,7 +167,7 @@ static void create_meeting_from_message_cb_ui(GtkAction *action, gpointer data)
                        gint sequence = 1;
                        PrefsAccount *account = NULL;
                        
                        gint sequence = 1;
                        PrefsAccount *account = NULL;
                        
-                       fclose(fp);
+                       claws_fclose(fp);
 
                        if (item && item->prefs && item->prefs->enable_default_account)
                                account = account_find_from_id(item->prefs->default_account);
 
                        if (item && item->prefs && item->prefs->enable_default_account)
                                account = account_find_from_id(item->prefs->default_account);
@@ -276,23 +277,23 @@ static VCalEvent *vcalviewer_get_component(const gchar *file, const gchar *chars
 
        g_return_val_if_fail(file != NULL, NULL);
 
 
        g_return_val_if_fail(file != NULL, NULL);
 
-       if ((fp = g_fopen(file, "rb")) == NULL) {
-               FILE_OP_ERROR(file, "g_fopen");
+       if ((fp = claws_fopen(file, "rb")) == NULL) {
+               FILE_OP_ERROR(file, "claws_fopen");
                return NULL;
        }
 
        array = g_byte_array_new();
 
                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, (guchar *)buf, n_read);
        }
 
                        break;
                g_byte_array_append(array, (guchar *)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);
                g_byte_array_free(array, TRUE);
-               fclose(fp);
+               claws_fclose(fp);
                return NULL;
        }
 
                return NULL;
        }
 
@@ -301,7 +302,7 @@ static VCalEvent *vcalviewer_get_component(const gchar *file, const gchar *chars
        compstr = (gchar *)array->data;
        g_byte_array_free(array, FALSE);
 
        compstr = (gchar *)array->data;
        g_byte_array_free(array, FALSE);
 
-       fclose(fp);     
+       claws_fclose(fp);       
 
        if (compstr) {
                event = vcal_get_event_from_ical(compstr, charset);
 
        if (compstr) {
                event = vcal_get_event_from_ical(compstr, charset);
index 9a60c950b8d22cc9610a132b299561c14115af34..4c5f521a613bc280cb89522d16b41eabf8d671c7 100644 (file)
--- a/src/pop.c
+++ b/src/pop.c
@@ -603,14 +603,14 @@ static void pop3_get_uidl_table(PrefsAccount *ac_prefs, Pop3Session *session)
                           "-", sanitized_uid, NULL);
                           
        g_free(sanitized_uid);
                           "-", sanitized_uid, NULL);
                           
        g_free(sanitized_uid);
-       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-", ac_prefs->recv_server,
                                   "-", ac_prefs->userid, NULL);
                g_free(path);
                path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                   "uidl-", ac_prefs->recv_server,
                                   "-", ac_prefs->userid, 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);
                        session->uidl_table = table;
                        session->partial_recv_table = partial_recv_table;
                        g_free(path);
                        session->uidl_table = table;
                        session->partial_recv_table = partial_recv_table;
@@ -621,7 +621,7 @@ static void pop3_get_uidl_table(PrefsAccount *ac_prefs, Pop3Session *session)
 
        now = time(NULL);
 
 
        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;
                gchar tmp[POPBUFSIZE];
                strretchomp(buf);
                recv_time = RECV_TIME_NONE;
@@ -653,7 +653,7 @@ static void pop3_get_uidl_table(PrefsAccount *ac_prefs, Pop3Session *session)
                                    GINT_TO_POINTER(partial_recv));
        }
 
                                    GINT_TO_POINTER(partial_recv));
        }
 
-       fclose(fp);
+       claws_fclose(fp);
        session->uidl_table = table;
        session->partial_recv_table = partial_recv_table;
        
        session->uidl_table = table;
        session->partial_recv_table = partial_recv_table;
        
@@ -690,8 +690,8 @@ gint pop3_write_uidl_list(Pop3Session *session)
 
        g_free(sanitized_uid);
 
 
        g_free(sanitized_uid);
 
-       if ((fp = g_fopen(tmp_path, "wb")) == NULL) {
-               FILE_OP_ERROR(tmp_path, "fopen");
+       if ((fp = claws_fopen(tmp_path, "wb")) == NULL) {
+               FILE_OP_ERROR(tmp_path, "claws_fopen");
                goto err_write;
        }
 
                goto err_write;
        }
 
@@ -706,8 +706,8 @@ gint pop3_write_uidl_list(Pop3Session *session)
                            > 0);
        }
 
                            > 0);
        }
 
-       if (safe_fclose(fp) == EOF) {
-               FILE_OP_ERROR(tmp_path, "fclose");
+       if (claws_safe_fclose(fp) == EOF) {
+               FILE_OP_ERROR(tmp_path, "claws_fclose");
                fp = NULL;
                goto err_write;
        }
                fp = NULL;
                goto err_write;
        }
@@ -724,7 +724,7 @@ gint pop3_write_uidl_list(Pop3Session *session)
        return 0;
 err_write:
        if (fp)
        return 0;
 err_write:
        if (fp)
-               fclose(fp);
+               claws_fclose(fp);
        g_free(path);
        g_free(tmp_path);
        return -1;
        g_free(path);
        g_free(tmp_path);
        return -1;
@@ -740,8 +740,8 @@ static gint pop3_write_msg_to_file(const gchar *file, const gchar *data,
 
        cm_return_val_if_fail(file != NULL, -1);
 
 
        cm_return_val_if_fail(file != NULL, -1);
 
-       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;
        }
 
                return -1;
        }
 
@@ -751,7 +751,7 @@ static gint pop3_write_msg_to_file(const gchar *file, const gchar *data,
        if (prefix != NULL) {
                if (fprintf(fp, "%s\n", prefix) < 0) {
                        FILE_OP_ERROR(file, "fprintf");
        if (prefix != NULL) {
                if (fprintf(fp, "%s\n", prefix) < 0) {
                        FILE_OP_ERROR(file, "fprintf");
-                       fclose(fp);
+                       claws_fclose(fp);
                        claws_unlink(file);
                        return -1;
                }
                        claws_unlink(file);
                        return -1;
                }
@@ -763,11 +763,11 @@ static gint pop3_write_msg_to_file(const gchar *file, const gchar *data,
        prev = data;
        while ((cur = (gchar *)my_memmem(prev, len - (prev - data), "\r\n", 2))
               != NULL) {
        prev = data;
        while ((cur = (gchar *)my_memmem(prev, len - (prev - data), "\r\n", 2))
               != NULL) {
-               if ((cur > prev && fwrite(prev, 1, cur - prev, fp) < 1) ||
-                   fputc('\n', fp) == EOF) {
-                       FILE_OP_ERROR(file, "fwrite");
+               if ((cur > prev && claws_fwrite(prev, 1, cur - prev, fp) < 1) ||
+                   claws_fputc('\n', fp) == EOF) {
+                       FILE_OP_ERROR(file, "claws_fwrite");
                        g_warning("can't write to file: %s", file);
                        g_warning("can't write to file: %s", file);
-                       fclose(fp);
+                       claws_fclose(fp);
                        claws_unlink(file);
                        return -1;
                }
                        claws_unlink(file);
                        return -1;
                }
@@ -790,25 +790,25 @@ static gint pop3_write_msg_to_file(const gchar *file, const gchar *data,
        }
 
        if (prev - data < len &&
        }
 
        if (prev - data < len &&
-           fwrite(prev, 1, len - (prev - data), fp) < 1) {
-               FILE_OP_ERROR(file, "fwrite");
+           claws_fwrite(prev, 1, len - (prev - data), fp) < 1) {
+               FILE_OP_ERROR(file, "claws_fwrite");
                g_warning("can't write to file: %s", file);
                g_warning("can't write to file: %s", file);
-               fclose(fp);
+               claws_fclose(fp);
                claws_unlink(file);
                return -1;
        }
        if (data[len - 1] != '\r' && data[len - 1] != '\n') {
                claws_unlink(file);
                return -1;
        }
        if (data[len - 1] != '\r' && data[len - 1] != '\n') {
-               if (fputc('\n', fp) == EOF) {
-                       FILE_OP_ERROR(file, "fputc");
+               if (claws_fputc('\n', fp) == EOF) {
+                       FILE_OP_ERROR(file, "claws_fputc");
                        g_warning("can't write to file: %s", file);
                        g_warning("can't write to file: %s", file);
-                       fclose(fp);
+                       claws_fclose(fp);
                        claws_unlink(file);
                        return -1;
                }
        }
 
                        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;
        }
                claws_unlink(file);
                return -1;
        }
index efac2ce0a9090b0560a71cc59d6dc7f5180fc2d5..1821ef35480092890a8d42f168d337982978578d 100644 (file)
@@ -65,6 +65,7 @@
 #include "inputdialog.h"
 #include "ssl_certificate.h"
 #include "passwordstore.h"
 #include "inputdialog.h"
 #include "ssl_certificate.h"
 #include "passwordstore.h"
+#include "claws_io.h"
 
 static gboolean cancelled;
 static gboolean new_account;
 
 static gboolean cancelled;
 static gboolean new_account;
@@ -4176,8 +4177,8 @@ void prefs_account_write_config_all(GList *account_list)
                privacy_prefs = NULL;
 
                if (cur->next) {
                privacy_prefs = NULL;
 
                if (cur->next) {
-                       if (fputc('\n', pfile->fp) == EOF) {
-                               FILE_OP_ERROR(rcpath, "fputc");
+                       if (claws_fputc('\n', pfile->fp) == EOF) {
+                               FILE_OP_ERROR(rcpath, "claws_fputc");
                                prefs_file_close_revert(pfile);
                                return;
                        }
                                prefs_file_close_revert(pfile);
                                return;
                        }
index 83c2eafea76fa7e26cdfc8525caf752bdb48c38a..9db536ec4bba1fef53b2079540bc9fdbda42d2d5 100644 (file)
@@ -51,6 +51,7 @@
 #include "prefs_filtering_action.h"
 #include "matcher_parser.h"
 #include "prefs_toolbar.h"
 #include "prefs_filtering_action.h"
 #include "matcher_parser.h"
 #include "prefs_toolbar.h"
+#include "claws_io.h"
 
 enum {
        PREFS_ACTIONS_STRING,   /*!< string pointer managed by list store, 
 
 enum {
        PREFS_ACTIONS_STRING,   /*!< string pointer managed by list store, 
@@ -443,8 +444,8 @@ void prefs_actions_read_config(void)
        debug_print("Reading actions configurations...\n");
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACTIONS_RC, NULL);
        debug_print("Reading actions configurations...\n");
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACTIONS_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);
                return;
        }
@@ -457,7 +458,7 @@ void prefs_actions_read_config(void)
                g_free(act);
        }
 
                g_free(act);
        }
 
-       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;
                const gchar *src_codeset = conv_get_locale_charset_str();
                const gchar *dest_codeset = CS_UTF_8;
                gchar *tmp;
@@ -478,7 +479,7 @@ void prefs_actions_read_config(void)
                else
                        g_free(tmp);
        }
                else
                        g_free(tmp);
        }
-       fclose(fp);
+       claws_fclose(fp);
 }
 
 void prefs_actions_write_config(void)
 }
 
 void prefs_actions_write_config(void)
@@ -508,9 +509,9 @@ void prefs_actions_write_config(void)
                        act = g_strdup(act);
                }
 
                        act = g_strdup(act);
                }
 
-               if (fputs(act, pfile->fp) == EOF ||
-                   fputc('\n', pfile->fp) == EOF) {
-                       FILE_OP_ERROR(rcpath, "fputs || fputc");
+               if (claws_fputs(act, pfile->fp) == EOF ||
+                   claws_fputc('\n', pfile->fp) == EOF) {
+                       FILE_OP_ERROR(rcpath, "claws_fputs || claws_fputc");
                        prefs_file_close_revert(pfile);
                        g_free(act);
                        g_free(rcpath);
                        prefs_file_close_revert(pfile);
                        g_free(act);
                        g_free(rcpath);
index 0775a66722eeefbd363da10aad6a92880461fa4f..30fbb7a8c8c5e2eb99262e41300db329ba721615 100644 (file)
@@ -1289,19 +1289,19 @@ GList *prefs_common_read_history_from_dir_with_defaults(const gchar *dirname, co
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, history,
                           NULL);
        }
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, history,
                           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);
                /* returns default list if set, otherwise NULL */
                return default_list;
        }
        g_free(path);
                g_free(path);
                /* returns default list if set, otherwise NULL */
                return default_list;
        }
        g_free(path);
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                g_strstrip(buf);
                if (buf[0] == '\0') continue;
                tmp = add_history(tmp, buf);
        }
                g_strstrip(buf);
                if (buf[0] == '\0') continue;
                tmp = add_history(tmp, buf);
        }
-       fclose(fp);
+       claws_fclose(fp);
 
        tmp = g_list_reverse(tmp);
 
 
        tmp = g_list_reverse(tmp);
 
@@ -1391,18 +1391,18 @@ static void prefs_common_save_history_to_dir(const gchar *dirname, const gchar *
        }
        tmp_path = g_strconcat(path, ".tmp", NULL);
 
        }
        tmp_path = g_strconcat(path, ".tmp", NULL);
 
-       if ((fp = g_fopen(tmp_path, "wb")) == NULL) {
-               FILE_OP_ERROR(tmp_path, "fopen");
+       if ((fp = claws_fopen(tmp_path, "wb")) == NULL) {
+               FILE_OP_ERROR(tmp_path, "claws_fopen");
                goto out;
        }
 
        for (cur = list; cur != NULL; cur = cur->next) {
                goto out;
        }
 
        for (cur = list; cur != NULL; cur = cur->next) {
-               TRY(fputs((gchar *)cur->data, fp) != EOF &&
-                   fputc('\n', fp) != EOF);
+               TRY(claws_fputs((gchar *)cur->data, fp) != EOF &&
+                   claws_fputc('\n', fp) != EOF);
        }
 
        }
 
-       if (safe_fclose(fp) == EOF) {
-               FILE_OP_ERROR(tmp_path, "fclose");
+       if (claws_safe_fclose(fp) == EOF) {
+               FILE_OP_ERROR(tmp_path, "claws_fclose");
                fp = NULL;
                goto out;
        }
                fp = NULL;
                goto out;
        }
@@ -1417,7 +1417,7 @@ static void prefs_common_save_history_to_dir(const gchar *dirname, const gchar *
 
 out:
        if (fp)
 
 out:
        if (fp)
-               safe_fclose(fp);
+               claws_safe_fclose(fp);
        g_free(tmp_path);
        g_free(path);
 }
        g_free(tmp_path);
        g_free(path);
 }
index ce3dd674fdaf9ccb4f18387ae67b921fd1d3f073..04b09e78c7eac285ee84fdcdd3aecc402750d5da 100644 (file)
@@ -48,6 +48,7 @@
 #include "alertpanel.h"
 #include "filesel.h"
 #include "combobox.h"
 #include "alertpanel.h"
 #include "filesel.h"
 #include "combobox.h"
+#include "claws_io.h"
 
 enum {
        CUSTHDR_STRING,         /*!< display string managed by list store */
 
 enum {
        CUSTHDR_STRING,         /*!< display string managed by list store */
@@ -329,8 +330,8 @@ void prefs_custom_header_read_config(PrefsAccount *ac)
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                             CUSTOM_HEADER_RC, NULL);
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                             CUSTOM_HEADER_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);
                ac->customhdr_list = NULL;
                return;
                g_free(rcpath);
                ac->customhdr_list = NULL;
                return;
@@ -344,7 +345,7 @@ void prefs_custom_header_read_config(PrefsAccount *ac)
                custom_header_free(ch);
        }
 
                custom_header_free(ch);
        }
 
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                ch = custom_header_read_str(buf);
                if (ch) {
                        if (ch->account_id == ac->account_id) {
                ch = custom_header_read_str(buf);
                if (ch) {
                        if (ch->account_id == ac->account_id) {
@@ -355,7 +356,7 @@ void prefs_custom_header_read_config(PrefsAccount *ac)
                }
        }
 
                }
        }
 
-       fclose(fp);
+       claws_fclose(fp);
 }
 
 static void prefs_custom_header_write_config(PrefsAccount *ac)
 }
 
 static void prefs_custom_header_write_config(PrefsAccount *ac)
@@ -374,12 +375,12 @@ static void prefs_custom_header_write_config(PrefsAccount *ac)
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                             CUSTOM_HEADER_RC, NULL);
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                             CUSTOM_HEADER_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");
        } else {
                all_hdrs = NULL;
 
        } else {
                all_hdrs = NULL;
 
-               while (fgets(buf, sizeof(buf), fp) != NULL) {
+               while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                        ch = custom_header_read_str(buf);
                        if (ch) {
                                if (ch->account_id != ac->account_id)
                        ch = custom_header_read_str(buf);
                        if (ch) {
                                if (ch->account_id != ac->account_id)
@@ -390,7 +391,7 @@ static void prefs_custom_header_write_config(PrefsAccount *ac)
                        }
                }
 
                        }
                }
 
-               fclose(fp);
+               claws_fclose(fp);
        }
 
        if ((pfile = prefs_write_open(rcpath)) == NULL) {
        }
 
        if ((pfile = prefs_write_open(rcpath)) == NULL) {
@@ -404,9 +405,9 @@ static void prefs_custom_header_write_config(PrefsAccount *ac)
                gchar *chstr;
 
                chstr = custom_header_get_str(hdr);
                gchar *chstr;
 
                chstr = custom_header_get_str(hdr);
-               if (fputs(chstr, pfile->fp) == EOF ||
-                   fputc('\n', pfile->fp) == EOF) {
-                       FILE_OP_ERROR(rcpath, "fputs || fputc");
+               if (claws_fputs(chstr, pfile->fp) == EOF ||
+                   claws_fputc('\n', pfile->fp) == EOF) {
+                       FILE_OP_ERROR(rcpath, "claws_fputs || claws_fputc");
                        prefs_file_close_revert(pfile);
                        g_free(rcpath);
                        g_free(chstr);
                        prefs_file_close_revert(pfile);
                        g_free(rcpath);
                        g_free(chstr);
@@ -420,9 +421,9 @@ static void prefs_custom_header_write_config(PrefsAccount *ac)
                gchar *chstr;
 
                chstr = custom_header_get_str(hdr);
                gchar *chstr;
 
                chstr = custom_header_get_str(hdr);
-               if (fputs(chstr, pfile->fp) == EOF ||
-                   fputc('\n', pfile->fp) == EOF) {
-                       FILE_OP_ERROR(rcpath, "fputs || fputc");
+               if (claws_fputs(chstr, pfile->fp) == EOF ||
+                   claws_fputc('\n', pfile->fp) == EOF) {
+                       FILE_OP_ERROR(rcpath, "claws_fputs || claws_fputc");
                        prefs_file_close_revert(pfile);
                        g_free(rcpath);
                        g_free(chstr);
                        prefs_file_close_revert(pfile);
                        g_free(rcpath);
                        g_free(chstr);
@@ -635,13 +636,13 @@ static void prefs_custom_header_val_from_file_cb(void)
                                goto settext;
                        }
 
                                goto settext;
                        }
 
-                       fp = g_fopen(filename, "rb");
+                       fp = claws_fopen(filename, "rb");
                        if (!fp) {
                                g_free(filename);
                                return; 
                        }
 
                        if (!fp) {
                                g_free(filename);
                                return; 
                        }
 
-                       while ((len = fread(inbuf, sizeof(gchar),
+                       while ((len = claws_fread(inbuf, sizeof(gchar),
                                            B64_LINE_SIZE, fp))
                               == B64_LINE_SIZE) {
                                outbuf = g_base64_encode(inbuf, B64_LINE_SIZE);
                                            B64_LINE_SIZE, fp))
                               == B64_LINE_SIZE) {
                                outbuf = g_base64_encode(inbuf, B64_LINE_SIZE);
@@ -651,14 +652,14 @@ static void prefs_custom_header_val_from_file_cb(void)
                                g_free(outbuf);
                                g_free(tmp);
                        }
                                g_free(outbuf);
                                g_free(tmp);
                        }
-                       if (len > 0 && feof(fp)) {
+                       if (len > 0 && claws_feof(fp)) {
                                tmp = contents;
                                outbuf = g_base64_encode(inbuf, len);
                                contents = g_strconcat(tmp?tmp:"",outbuf, NULL);
                                g_free(outbuf);
                                g_free(tmp);
                        }
                                tmp = contents;
                                outbuf = g_base64_encode(inbuf, len);
                                contents = g_strconcat(tmp?tmp:"",outbuf, NULL);
                                g_free(outbuf);
                                g_free(tmp);
                        }
-                       fclose(fp);
+                       claws_fclose(fp);
                }
        } else {
                if (!filename)
                }
        } else {
                if (!filename)
index ab1ec1975cead77d2026d1ffea1ac8799cf82e92..bd70f4f028e9bf9e5221c9a6fbf0c50df4eb5328 100644 (file)
@@ -41,6 +41,7 @@
 #include "displayheader.h"
 #include "utils.h"
 #include "gtkutils.h"
 #include "displayheader.h"
 #include "utils.h"
 #include "gtkutils.h"
+#include "claws_io.h"
 
 enum {
        PREFS_HDR_HEADER,
 
 enum {
        PREFS_HDR_HEADER,
@@ -424,8 +425,8 @@ void prefs_display_header_read_config(void)
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                             DISPLAY_HEADER_RC, NULL);
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                             DISPLAY_HEADER_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);
                prefs_common.disphdr_list = NULL;
                prefs_display_header_set_default();
                g_free(rcpath);
                prefs_common.disphdr_list = NULL;
                prefs_display_header_set_default();
@@ -441,7 +442,7 @@ void prefs_display_header_read_config(void)
                        g_slist_remove(prefs_common.disphdr_list, dp);
        }
 
                        g_slist_remove(prefs_common.disphdr_list, dp);
        }
 
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                g_strdelimit(buf, "\r\n", '\0');
                dp = display_header_prop_read_str(buf);
                if (dp)
                g_strdelimit(buf, "\r\n", '\0');
                dp = display_header_prop_read_str(buf);
                if (dp)
@@ -449,7 +450,7 @@ void prefs_display_header_read_config(void)
                                g_slist_append(prefs_common.disphdr_list, dp);
        }
 
                                g_slist_append(prefs_common.disphdr_list, dp);
        }
 
-       fclose(fp);
+       claws_fclose(fp);
 }
 
 static void prefs_display_header_write_config(void)
 }
 
 static void prefs_display_header_write_config(void)
@@ -475,9 +476,9 @@ static void prefs_display_header_write_config(void)
                gchar *dpstr;
 
                dpstr = display_header_prop_get_str(dp);
                gchar *dpstr;
 
                dpstr = display_header_prop_get_str(dp);
-               if (fputs(dpstr, pfile->fp) == EOF ||
-                   fputc('\n', pfile->fp) == EOF) {
-                       FILE_OP_ERROR(rcpath, "fputs || fputc");
+               if (claws_fputs(dpstr, pfile->fp) == EOF ||
+                   claws_fputc('\n', pfile->fp) == EOF) {
+                       FILE_OP_ERROR(rcpath, "claws_fputs || claws_fputc");
                        prefs_file_close_revert(pfile);
                        g_free(rcpath);
                        g_free(dpstr);
                        prefs_file_close_revert(pfile);
                        g_free(rcpath);
                        g_free(dpstr);
index 8b00dc1d8201d34c3b47438820c8d0b862d7eaba..fedffcc90d2b6dae4e634f0ce883322f0bca50d6 100644 (file)
@@ -22,7 +22,6 @@
 #include "claws-features.h"
 #endif
 
 #include "claws-features.h"
 #endif
 
-#define _GNU_SOURCE
 #include <stdio.h>
 
 #include <glib.h>
 #include <stdio.h>
 
 #include <glib.h>
@@ -42,6 +41,7 @@
 #include "gtkutils.h"
 #include "password.h"
 #include "codeconv.h"
 #include "gtkutils.h"
 #include "password.h"
 #include "codeconv.h"
+#include "claws_io.h"
 
 #define CL(x)  (((gulong) (x) >> (gulong) 8) & 0xFFUL)
 #define RGB_FROM_GDK_COLOR(c) \
 
 #define CL(x)  (((gulong) (x) >> (gulong) 8) & 0xFFUL)
 #define RGB_FROM_GDK_COLOR(c) \
         (CL(c.green) << (gulong)  8) | \
         (CL(c.blue)))
 
         (CL(c.green) << (gulong)  8) | \
         (CL(c.blue)))
 
-#ifdef HAVE_FGETS_UNLOCKED
-#define SC_FGETS fgets_unlocked
-#else
-#define SC_FGETS fgets
-#endif
-
 typedef enum
 {
        DUMMY_PARAM
 typedef enum
 {
        DUMMY_PARAM
@@ -91,19 +85,15 @@ void prefs_read_config(PrefParam *param, const gchar *label,
                        return;
        }
 
                        return;
        }
 
-       if ((fp = g_fopen(rcfile, "rb")) == NULL) {
-               if (ENOENT != errno) FILE_OP_ERROR(rcfile, "fopen");
+       if ((fp = claws_fopen(rcfile, "rb")) == NULL) {
+               if (ENOENT != errno) FILE_OP_ERROR(rcfile, "claws_fopen");
                return;
        }
 
        block_label = g_strdup_printf("[%s]", label);
 
                return;
        }
 
        block_label = g_strdup_printf("[%s]", label);
 
-#ifdef HAVE_FGETS_UNLOCKED
-       flockfile(fp);
-#endif
-
        /* search aiming block */
        /* search aiming block */
-       while (SC_FGETS(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                gint val;
 
                if (encoding) {
                gint val;
 
                if (encoding) {
@@ -125,7 +115,7 @@ void prefs_read_config(PrefParam *param, const gchar *label,
        }
        g_free(block_label);
 
        }
        g_free(block_label);
 
-       while (SC_FGETS(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                strretchomp(buf);
                /* reached next block */
                if (buf[0] == '[') break;
                strretchomp(buf);
                /* reached next block */
                if (buf[0] == '[') break;
@@ -145,10 +135,7 @@ void prefs_read_config(PrefParam *param, const gchar *label,
        }
 
        debug_print("Finished reading configuration.\n");
        }
 
        debug_print("Finished reading configuration.\n");
-#ifdef HAVE_FGETS_UNLOCKED
-       funlockfile(fp);
-#endif
-       fclose(fp);
+       claws_fclose(fp);
 }
 
 static void prefs_config_parse_one_line(PrefParam *param, const gchar *buf)
 }
 
 static void prefs_config_parse_one_line(PrefParam *param, const gchar *buf)
@@ -227,7 +214,7 @@ static void prefs_config_parse_one_line(PrefParam *param, const gchar *buf)
 if (!(func)) \
 { \
        g_warning("Failed to write configuration to file"); \
 if (!(func)) \
 { \
        g_warning("Failed to write configuration to file"); \
-       if (orig_fp) fclose(orig_fp); \
+       if (orig_fp) claws_fclose(orig_fp); \
        prefs_file_close_revert(pfile); \
        g_free(rcpath); \
        g_free(block_label); \
        prefs_file_close_revert(pfile); \
        g_free(rcpath); \
        g_free(block_label); \
@@ -249,13 +236,13 @@ void prefs_write_config(PrefParam *param, const gchar *label,
        cm_return_if_fail(rcfile != NULL);
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, rcfile, NULL);
        cm_return_if_fail(rcfile != NULL);
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, rcfile, NULL);
-       if ((orig_fp = g_fopen(rcpath, "rb")) == NULL) {
-               if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
+       if ((orig_fp = claws_fopen(rcpath, "rb")) == NULL) {
+               if (ENOENT != errno) FILE_OP_ERROR(rcpath, "claws_fopen");
        }
 
        if ((pfile = prefs_write_open(rcpath)) == NULL) {
                g_warning("Failed to write configuration to file");
        }
 
        if ((pfile = prefs_write_open(rcpath)) == NULL) {
                g_warning("Failed to write configuration to file");
-               if (orig_fp) fclose(orig_fp);
+               if (orig_fp) claws_fclose(orig_fp);
                g_free(rcpath);
                return;
        }
                g_free(rcpath);
                return;
        }
@@ -264,7 +251,7 @@ void prefs_write_config(PrefParam *param, const gchar *label,
 
        /* search aiming block */
        if (orig_fp) {
 
        /* search aiming block */
        if (orig_fp) {
-               while (fgets(buf, sizeof(buf), orig_fp) != NULL) {
+               while (claws_fgets(buf, sizeof(buf), orig_fp) != NULL) {
                        gint val;
 
                        val = strncmp(buf, block_label, strlen(block_label));
                        gint val;
 
                        val = strncmp(buf, block_label, strlen(block_label));
@@ -273,7 +260,7 @@ void prefs_write_config(PrefParam *param, const gchar *label,
                                block_matched = TRUE;
                                break;
                        } else
                                block_matched = TRUE;
                                break;
                        } else
-                               TRY(fputs(buf, pfile->fp) != EOF);
+                               TRY(claws_fputs(buf, pfile->fp) != EOF);
                }
        }
 
                }
        }
 
@@ -284,15 +271,15 @@ void prefs_write_config(PrefParam *param, const gchar *label,
 
        if (block_matched) {
                gboolean in_dup_block = FALSE;
 
        if (block_matched) {
                gboolean in_dup_block = FALSE;
-               while (fgets(buf, sizeof(buf), orig_fp) != NULL) {
+               while (claws_fgets(buf, sizeof(buf), orig_fp) != NULL) {
                        /* next block */
                        if (buf[0] == '[') {
                        /* next block */
                        if (buf[0] == '[') {
-                               TRY(fputc('\n', pfile->fp) != EOF &&
-                                   fputs(buf, pfile->fp)  != EOF);
+                               TRY(claws_fputc('\n', pfile->fp) != EOF &&
+                                   claws_fputs(buf, pfile->fp)  != EOF);
                                break;
                        }
                }
                                break;
                        }
                }
-               while (fgets(buf, sizeof(buf), orig_fp) != NULL) {
+               while (claws_fgets(buf, sizeof(buf), orig_fp) != NULL) {
                        if (buf[0] == '[') {
                                if (!strncmp(buf, block_label,
                                                strlen(block_label)))
                        if (buf[0] == '[') {
                                if (!strncmp(buf, block_label,
                                                strlen(block_label)))
@@ -301,14 +288,14 @@ void prefs_write_config(PrefParam *param, const gchar *label,
                                        in_dup_block = FALSE;
                        }
                        if (!in_dup_block)
                                        in_dup_block = FALSE;
                        }
                        if (!in_dup_block)
-                               TRY(fputs(buf, pfile->fp) != EOF);
+                               TRY(claws_fputs(buf, pfile->fp) != EOF);
                }
        }
 
        g_free(block_label);
        block_label = NULL;
 
                }
        }
 
        g_free(block_label);
        block_label = NULL;
 
-       if (orig_fp) fclose(orig_fp);
+       if (orig_fp) claws_fclose(orig_fp);
        if (prefs_file_close(pfile) < 0)
                g_warning("Failed to write configuration to file");
        g_free(rcpath);
        if (prefs_file_close(pfile) < 0)
                g_warning("Failed to write configuration to file");
        g_free(rcpath);
@@ -375,8 +362,8 @@ gint prefs_write_param(PrefParam *param, FILE *fp)
                }
 
                if (buf[0] != '\0') {
                }
 
                if (buf[0] != '\0') {
-                       if (fputs(buf, fp) == EOF) {
-                               perror("fputs");
+                       if (claws_fputs(buf, fp) == EOF) {
+                               perror("claws_fputs");
                                return -1;
                        }
                }
                                return -1;
                        }
                }
@@ -939,17 +926,13 @@ static int prefs_cache_sections(GHashTable *file_cache, const gchar *rcfile)
        GHashTable *section_cache = NULL;
 
        if (rcfile)
        GHashTable *section_cache = NULL;
 
        if (rcfile)
-               fp = g_fopen(rcfile, "rb");
+               fp = claws_fopen(rcfile, "rb");
        if (!fp) {
                debug_print("cache: %s: %s\n", rcfile?rcfile:"(null)", g_strerror(errno));
                return -1;
        }
        if (!fp) {
                debug_print("cache: %s: %s\n", rcfile?rcfile:"(null)", g_strerror(errno));
                return -1;
        }
-       
-#ifdef HAVE_FGETS_UNLOCKED
-       flockfile(fp);
-#endif
-       
-       while (SC_FGETS(buf, sizeof(buf), fp) != NULL) {
+               
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                strretchomp(buf);
                if (buf[0] == '\0')
                        continue;
                strretchomp(buf);
                if (buf[0] == '\0')
                        continue;
@@ -991,10 +974,7 @@ static int prefs_cache_sections(GHashTable *file_cache, const gchar *rcfile)
                        }
                }
        }
                        }
                }
        }
-#ifdef HAVE_FGETS_UNLOCKED
-       funlockfile(fp);
-#endif
-       fclose(fp);
+       claws_fclose(fp);
        return 0;
 }
 
        return 0;
 }
 
index 31f940d000269a6f8d86c1bb5b816a37626570e1..b6f7336b73c6ace45faa9558d7c288cc71515cc7 100644 (file)
@@ -48,6 +48,7 @@
 #include "compose.h"
 #include "alertpanel.h"
 #include "addr_compl.h"
 #include "compose.h"
 #include "alertpanel.h"
 #include "addr_compl.h"
+#include "claws_io.h"
 
 #define IS_CURRENT_THEME(path)  (strcmp(prefs_common.pixmap_theme_path, path) == 0)
 #define IS_INTERNAL_THEME(path) (strcmp(DEFAULT_PIXMAP_THEME, path) == 0)
 
 #define IS_CURRENT_THEME(path)  (strcmp(prefs_common.pixmap_theme_path, path) == 0)
 #define IS_INTERNAL_THEME(path) (strcmp(DEFAULT_PIXMAP_THEME, path) == 0)
@@ -811,7 +812,7 @@ static void prefs_themes_display_global_stats(const ThemesData *tdata)
 
 #define FGETS_INFOFILE_LINE() \
        line[0] = '\0'; \
 
 #define FGETS_INFOFILE_LINE() \
        line[0] = '\0'; \
-       if (fgets(line, INFOFILE_LINE_LEN, finfo) != NULL && (len = strlen(line)) > 0) { \
+       if (claws_fgets(line, INFOFILE_LINE_LEN, finfo) != NULL && (len = strlen(line)) > 0) { \
                if (line[len - 1] == '\n') line[len - 1] = '\0'; \
        } \
        else { \
                if (line[len - 1] == '\n') line[len - 1] = '\0'; \
        } \
        else { \
@@ -844,7 +845,7 @@ static void prefs_themes_get_theme_info(ThemesData *tdata)
        }
        else {
                sinfo = g_strconcat(path, G_DIR_SEPARATOR_S, THEMEINFO_FILE, NULL);
        }
        else {
                sinfo = g_strconcat(path, G_DIR_SEPARATOR_S, THEMEINFO_FILE, NULL);
-               finfo = g_fopen(sinfo, "r");
+               finfo = claws_fopen(sinfo, "r");
                if (finfo == NULL) {
                        info->name = g_strdup(_("No info file available for this theme"));
                        info->author = g_strdup(_("Unknown"));
                if (finfo == NULL) {
                        info->name = g_strdup(_("No info file available for this theme"));
                        info->author = g_strdup(_("Unknown"));
@@ -858,7 +859,7 @@ static void prefs_themes_get_theme_info(ThemesData *tdata)
                        FGETS_INFOFILE_LINE()
                        info->url = g_strdup(line);
                
                        FGETS_INFOFILE_LINE()
                        info->url = g_strdup(line);
                
-                       fclose(finfo);
+                       claws_fclose(finfo);
                }
                g_free(sinfo);
 
                }
                g_free(sinfo);
 
index 6a98f129cf1632ccc46412a6e614b46aa621aefc..9431841223c3fd980d7e15428386eb4694176778 100644 (file)
@@ -41,6 +41,7 @@
 #include "hooks.h"
 #include "utils.h"
 #include "defs.h"
 #include "hooks.h"
 #include "utils.h"
 #include "defs.h"
+#include "claws_io.h"
 
 #define BUFFSIZE       8192
 
 
 #define BUFFSIZE       8192
 
@@ -459,13 +460,13 @@ MsgInfo *procheader_parse_file(const gchar *file, MsgFlags flags,
                return NULL;
 #endif
 
                return NULL;
 #endif
 
-       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 NULL;
        }
 
        msginfo = procheader_parse_stream(fp, flags, full, decrypted);
                return NULL;
        }
 
        msginfo = procheader_parse_stream(fp, flags, full, decrypted);
-       fclose(fp);
+       claws_fclose(fp);
 
        if (msginfo) {
 #ifdef G_OS_WIN32
 
        if (msginfo) {
 #ifdef G_OS_WIN32
@@ -1209,8 +1210,8 @@ gint procheader_get_header_from_msginfo(MsgInfo *msginfo, gchar **buf, gchar *he
        hentry[0].name = header;
 
        file = procmsg_get_message_file_path(msginfo);
        hentry[0].name = header;
 
        file = procmsg_get_message_file_path(msginfo);
-       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);
                g_free(*buf);
                *buf = NULL;
                g_free(file);
                g_free(*buf);
                *buf = NULL;
@@ -1218,8 +1219,8 @@ gint procheader_get_header_from_msginfo(MsgInfo *msginfo, gchar **buf, gchar *he
        }
        val = procheader_get_one_field(buf, fp, hentry);
 
        }
        val = procheader_get_one_field(buf, fp, hentry);
 
-       if (fclose(fp) == EOF) {
-               FILE_OP_ERROR(file, "fclose");
+       if (claws_fclose(fp) == EOF) {
+               FILE_OP_ERROR(file, "claws_fclose");
                claws_unlink(file);
                g_free(file);
                g_free(*buf);
                claws_unlink(file);
                g_free(file);
                g_free(*buf);
index c47c7b68b3cc6ab1e277e54195b16563fbbb4401..a9f28a5df01781ab798559ecc968284843d0db1b 100644 (file)
@@ -21,7 +21,6 @@
 #include "claws-features.h"
 #endif
 
 #include "claws-features.h"
 #endif
 
-#define _GNU_SOURCE
 #include <stdio.h>
 
 #include "defs.h"
 #include <stdio.h>
 
 #include "defs.h"
@@ -53,6 +52,7 @@
 #include "timing.h"
 #include "privacy.h"
 #include "account.h"
 #include "timing.h"
 #include "privacy.h"
 #include "account.h"
+#include "claws_io.h"
 
 static GHashTable *procmime_get_mime_type_table        (void);
 static MimeInfo *procmime_scan_file_short(const gchar *filename);
 
 static GHashTable *procmime_get_mime_type_table        (void);
 static MimeInfo *procmime_scan_file_short(const gchar *filename);
@@ -257,40 +257,6 @@ const gchar *procmime_mimeinfo_get_parameter(MimeInfo *mimeinfo, const gchar *na
        return value;
 }
 
        return value;
 }
 
-#ifdef HAVE_FGETS_UNLOCKED
-#define SC_FGETS fgets_unlocked
-#define SC_FPUTS fputs_unlocked
-#define SC_FPUTC fputc_unlocked
-#define SC_FREAD fread_unlocked
-#define SC_FWRITE fwrite_unlocked
-#define SC_FEOF feof_unlocked
-#define SC_FERROR ferror_unlocked
-
-static FILE *procmime_fopen(const gchar *file, const gchar *mode)
-{
-       FILE *fp = g_fopen(file, mode);
-       if (!fp)
-               return NULL;
-       flockfile(fp);
-       return fp;
-}
-static int procmime_fclose(FILE *fp)
-{
-       funlockfile(fp);
-       return fclose(fp);
-}
-#else
-#define SC_FGETS fgets
-#define SC_FPUTS fputs
-#define SC_FPUTC fputc
-#define SC_FREAD fread
-#define SC_FWRITE fwrite
-#define SC_FEOF feof
-#define SC_FERROR ferror
-#define procmime_fopen g_fopen
-#define procmime_fclose fclose
-#endif
-
 #define FLUSH_LASTLINE() {                                                     \
        if (*lastline != '\0') {                                                \
                gint llen = 0;                                                  \
 #define FLUSH_LASTLINE() {                                                     \
        if (*lastline != '\0') {                                                \
                gint llen = 0;                                                  \
@@ -301,12 +267,12 @@ static int procmime_fclose(FILE *fp)
                        /* this is flowed */                                    \
                        if (delsp)                                              \
                                lastline[llen-1] = '\0';                        \
                        /* this is flowed */                                    \
                        if (delsp)                                              \
                                lastline[llen-1] = '\0';                        \
-                       if (SC_FPUTS(lastline, outfp) == EOF)                   \
+                       if (claws_fputs(lastline, outfp) == EOF)                        \
                                err = TRUE;                                     \
                } else {                                                        \
                                err = TRUE;                                     \
                } else {                                                        \
-                       if (SC_FPUTS(lastline, outfp) == EOF)                   \
+                       if (claws_fputs(lastline, outfp) == EOF)                        \
                                err = TRUE;                                     \
                                err = TRUE;                                     \
-                       if (SC_FPUTS("\n", outfp) == EOF)                               \
+                       if (claws_fputs("\n", outfp) == EOF)                            \
                                err = TRUE;                                     \
                }                                                               \
        }                                                                       \
                                err = TRUE;                                     \
                }                                                               \
        }                                                                       \
@@ -361,26 +327,24 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
        if (mimeinfo->data.filename == NULL)
                return FALSE;
 
        if (mimeinfo->data.filename == NULL)
                return FALSE;
 
-       infp = procmime_fopen(mimeinfo->data.filename, "rb");
+       infp = claws_fopen(mimeinfo->data.filename, "rb");
        if (!infp) {
        if (!infp) {
-               FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
+               FILE_OP_ERROR(mimeinfo->data.filename, "claws_fopen");
                return FALSE;
        }
        if (fseek(infp, mimeinfo->offset, SEEK_SET) < 0) {
                FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
                return FALSE;
        }
        if (fseek(infp, mimeinfo->offset, SEEK_SET) < 0) {
                FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
-               procmime_fclose(infp);
+               claws_fclose(infp);
                return FALSE;
        }
 
        outfp = get_tmpfile_in_dir(get_mime_tmp_dir(), &tmpfilename);
        if (!outfp) {
                perror("tmpfile");
                return FALSE;
        }
 
        outfp = get_tmpfile_in_dir(get_mime_tmp_dir(), &tmpfilename);
        if (!outfp) {
                perror("tmpfile");
-               procmime_fclose(infp);
+               claws_fclose(infp);
                return FALSE;
        }
                return FALSE;
        }
-#ifdef HAVE_FGETS_UNLOCKED
-       flockfile(outfp);
-#endif
+
        tmp_file = TRUE;
        readend = mimeinfo->offset + mimeinfo->length;
 
        tmp_file = TRUE;
        readend = mimeinfo->offset + mimeinfo->length;
 
@@ -388,12 +352,12 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
 
        *buf = '\0';
        if (encoding == ENC_QUOTED_PRINTABLE) {
 
        *buf = '\0';
        if (encoding == ENC_QUOTED_PRINTABLE) {
-               while ((ftell(infp) < readend) && (SC_FGETS(buf, sizeof(buf), infp) != NULL)) {
+               while ((ftell(infp) < readend) && (claws_fgets(buf, sizeof(buf), infp) != NULL)) {
                        gint len;
                        len = qp_decode_line(buf);
                        buf[len] = '\0';
                        if (!flowed) {
                        gint len;
                        len = qp_decode_line(buf);
                        buf[len] = '\0';
                        if (!flowed) {
-                               if (SC_FWRITE(buf, 1, len, outfp) < len)
+                               if (claws_fwrite(buf, 1, len, outfp) < len)
                                        err = TRUE;
                        } else {
                                FLUSH_LASTLINE();
                                        err = TRUE;
                        } else {
                                FLUSH_LASTLINE();
@@ -417,18 +381,15 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
                        if (!tmpfp) {
                                perror("my_tmpfile");
                                if (tmp_file) 
                        if (!tmpfp) {
                                perror("my_tmpfile");
                                if (tmp_file) 
-                                       procmime_fclose(outfp);
-                               procmime_fclose(infp);
+                                       claws_fclose(outfp);
+                               claws_fclose(infp);
                                return FALSE;
                        }
                                return FALSE;
                        }
-#ifdef HAVE_FGETS_UNLOCKED
-                       flockfile(tmpfp);
-#endif
                } else
                        tmpfp = outfp;
 
                while ((inlen = MIN(readend - ftell(infp), sizeof(buf))) > 0 && !err) {
                } else
                        tmpfp = outfp;
 
                while ((inlen = MIN(readend - ftell(infp), sizeof(buf))) > 0 && !err) {
-                       inread = SC_FREAD(buf, 1, inlen, infp);
+                       inread = claws_fread(buf, 1, inlen, infp);
                        len = g_base64_decode_step(buf, inlen, outbuf, &state, &save);
                        if (uncanonicalize == TRUE && strlen(outbuf) < len && starting) {
                                uncanonicalize = FALSE;
                        len = g_base64_decode_step(buf, inlen, outbuf, &state, &save);
                        if (uncanonicalize == TRUE && strlen(outbuf) < len && starting) {
                                uncanonicalize = FALSE;
@@ -437,7 +398,7 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
                        starting = FALSE;
                        if (((inread != inlen) || len < 0) && !got_error) {
                                g_warning("Bad BASE64 content.");
                        starting = FALSE;
                        if (((inread != inlen) || len < 0) && !got_error) {
                                g_warning("Bad BASE64 content.");
-                               if (SC_FWRITE(_("[Error decoding BASE64]\n"),
+                               if (claws_fwrite(_("[Error decoding BASE64]\n"),
                                        sizeof(gchar),
                                        strlen(_("[Error decoding BASE64]\n")),
                                        tmpfp) < strlen(_("[Error decoding BASE64]\n")))
                                        sizeof(gchar),
                                        strlen(_("[Error decoding BASE64]\n")),
                                        tmpfp) < strlen(_("[Error decoding BASE64]\n")))
@@ -449,10 +410,10 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
                                 * per block */
                                if (null_bytes) {
                                        /* we won't uncanonicalize, output to outfp directly */
                                 * per block */
                                if (null_bytes) {
                                        /* we won't uncanonicalize, output to outfp directly */
-                                       if (SC_FWRITE(outbuf, sizeof(gchar), len, outfp) < len)
+                                       if (claws_fwrite(outbuf, sizeof(gchar), len, outfp) < len)
                                                err = TRUE;
                                } else {
                                                err = TRUE;
                                } else {
-                                       if (SC_FWRITE(outbuf, sizeof(gchar), len, tmpfp) < len)
+                                       if (claws_fwrite(outbuf, sizeof(gchar), len, tmpfp) < len)
                                                err = TRUE;
                                }
                                got_error = FALSE;
                                                err = TRUE;
                                }
                                got_error = FALSE;
@@ -461,20 +422,20 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
 
                if (uncanonicalize) {
                        rewind(tmpfp);
 
                if (uncanonicalize) {
                        rewind(tmpfp);
-                       while (SC_FGETS(buf, sizeof(buf), tmpfp) != NULL) {
+                       while (claws_fgets(buf, sizeof(buf), tmpfp) != NULL) {
                                strcrchomp(buf);
                                strcrchomp(buf);
-                               if (SC_FPUTS(buf, outfp) == EOF)
+                               if (claws_fputs(buf, outfp) == EOF)
                                        err = TRUE;
                        }
                }
                if (tmpfp != outfp)
                                        err = TRUE;
                        }
                }
                if (tmpfp != outfp)
-                       procmime_fclose(tmpfp);
+                       claws_fclose(tmpfp);
        } else if (encoding == ENC_X_UUENCODE) {
                gchar outbuf[BUFFSIZE];
                gint len;
                gboolean flag = FALSE;
 
        } else if (encoding == ENC_X_UUENCODE) {
                gchar outbuf[BUFFSIZE];
                gint len;
                gboolean flag = FALSE;
 
-               while ((ftell(infp) < readend) && (SC_FGETS(buf, sizeof(buf), infp) != NULL)) {
+               while ((ftell(infp) < readend) && (claws_fgets(buf, sizeof(buf), infp) != NULL)) {
                        if (!flag && strncmp(buf,"begin ", 6)) continue;
 
                        if (flag) {
                        if (!flag && strncmp(buf,"begin ", 6)) continue;
 
                        if (flag) {
@@ -484,15 +445,15 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
                                                g_warning("Bad UUENCODE content (%d)", len);
                                        break;
                                }
                                                g_warning("Bad UUENCODE content (%d)", len);
                                        break;
                                }
-                               if (SC_FWRITE(outbuf, sizeof(gchar), len, outfp) < len)
+                               if (claws_fwrite(outbuf, sizeof(gchar), len, outfp) < len)
                                        err = TRUE;
                        } else
                                flag = TRUE;
                }
        } else {
                                        err = TRUE;
                        } else
                                flag = TRUE;
                }
        } else {
-               while ((ftell(infp) < readend) && (SC_FGETS(buf, sizeof(buf), infp) != NULL)) {
+               while ((ftell(infp) < readend) && (claws_fgets(buf, sizeof(buf), infp) != NULL)) {
                        if (!flowed) {
                        if (!flowed) {
-                               if (SC_FPUTS(buf, outfp) == EOF)
+                               if (claws_fputs(buf, outfp) == EOF)
                                        err = TRUE;
                        } else {
                                FLUSH_LASTLINE();
                                        err = TRUE;
                        } else {
                                FLUSH_LASTLINE();
@@ -504,8 +465,8 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
                        g_warning("write error");
        }
 
                        g_warning("write error");
        }
 
-       procmime_fclose(outfp);
-       procmime_fclose(infp);
+       claws_fclose(outfp);
+       claws_fclose(infp);
 
        account_signatures_matchlist_delete();
 
 
        account_signatures_matchlist_delete();
 
@@ -556,27 +517,21 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
                perror("tmpfile");
                return FALSE;
        }
                perror("tmpfile");
                return FALSE;
        }
-#ifdef HAVE_FGETS_UNLOCKED
-       flockfile(outfp);
-#endif
 
        if (mimeinfo->content == MIMECONTENT_FILE && mimeinfo->data.filename) {
 
        if (mimeinfo->content == MIMECONTENT_FILE && mimeinfo->data.filename) {
-               if ((infp = procmime_fopen(mimeinfo->data.filename, "rb")) == NULL) {
+               if ((infp = claws_fopen(mimeinfo->data.filename, "rb")) == NULL) {
                        g_warning("Can't open file %s", mimeinfo->data.filename);
                        g_warning("Can't open file %s", mimeinfo->data.filename);
-                       procmime_fclose(outfp);
+                       claws_fclose(outfp);
                        return FALSE;
                }
        } else if (mimeinfo->content == MIMECONTENT_MEM) {
                infp = str_open_as_stream(mimeinfo->data.mem);
                if (infp == NULL) {
                        return FALSE;
                }
        } else if (mimeinfo->content == MIMECONTENT_MEM) {
                infp = str_open_as_stream(mimeinfo->data.mem);
                if (infp == NULL) {
-                       procmime_fclose(outfp);
+                       claws_fclose(outfp);
                        return FALSE;
                }
                        return FALSE;
                }
-#ifdef HAVE_FGETS_UNLOCKED
-               flockfile(infp);
-#endif
        } else {
        } else {
-               procmime_fclose(outfp);
+               claws_fclose(outfp);
                g_warning("Unknown mimeinfo");
                return FALSE;
        }
                g_warning("Unknown mimeinfo");
                return FALSE;
        }
@@ -592,62 +547,59 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
                                tmp_file = get_tmp_file();
                                if (canonicalize_file(mimeinfo->data.filename, tmp_file) < 0) {
                                        g_free(tmp_file);
                                tmp_file = get_tmp_file();
                                if (canonicalize_file(mimeinfo->data.filename, tmp_file) < 0) {
                                        g_free(tmp_file);
-                                       procmime_fclose(infp);
-                                       procmime_fclose(outfp);
+                                       claws_fclose(infp);
+                                       claws_fclose(outfp);
                                        return FALSE;
                                }
                                        return FALSE;
                                }
-                               if ((tmp_fp = procmime_fopen(tmp_file, "rb")) == NULL) {
-                                       FILE_OP_ERROR(tmp_file, "fopen");
+                               if ((tmp_fp = claws_fopen(tmp_file, "rb")) == NULL) {
+                                       FILE_OP_ERROR(tmp_file, "claws_fopen");
                                        claws_unlink(tmp_file);
                                        g_free(tmp_file);
                                        claws_unlink(tmp_file);
                                        g_free(tmp_file);
-                                       procmime_fclose(infp);
-                                       procmime_fclose(outfp);
+                                       claws_fclose(infp);
+                                       claws_fclose(outfp);
                                        return FALSE;
                                }
                        } else {
                                gchar *out = canonicalize_str(mimeinfo->data.mem);
                                        return FALSE;
                                }
                        } else {
                                gchar *out = canonicalize_str(mimeinfo->data.mem);
-                               procmime_fclose(infp);
+                               claws_fclose(infp);
                                infp = str_open_as_stream(out);
                                tmp_fp = infp;
                                g_free(out);
                                if (infp == NULL) {
                                infp = str_open_as_stream(out);
                                tmp_fp = infp;
                                g_free(out);
                                if (infp == NULL) {
-                                       procmime_fclose(outfp);
+                                       claws_fclose(outfp);
                                        return FALSE;
                                }
                                        return FALSE;
                                }
-#ifdef HAVE_FGETS_UNLOCKED
-                               flockfile(infp);
-#endif
                        }
                }
 
                        }
                }
 
-               while ((len = SC_FREAD(inbuf, sizeof(gchar),
+               while ((len = claws_fread(inbuf, sizeof(gchar),
                                    B64_LINE_SIZE, tmp_fp))
                       == B64_LINE_SIZE) {
                        out = g_base64_encode(inbuf, B64_LINE_SIZE);
                                    B64_LINE_SIZE, tmp_fp))
                       == B64_LINE_SIZE) {
                        out = g_base64_encode(inbuf, B64_LINE_SIZE);
-                       if (SC_FPUTS(out, outfp) == EOF)
+                       if (claws_fputs(out, outfp) == EOF)
                                err = TRUE;
                        g_free(out);
                                err = TRUE;
                        g_free(out);
-                       if (SC_FPUTC('\n', outfp) == EOF)
+                       if (claws_fputc('\n', outfp) == EOF)
                                err = TRUE;
                }
                                err = TRUE;
                }
-               if (len > 0 && SC_FEOF(tmp_fp)) {
+               if (len > 0 && claws_feof(tmp_fp)) {
                        out = g_base64_encode(inbuf, len);
                        out = g_base64_encode(inbuf, len);
-                       if (SC_FPUTS(out, outfp) == EOF)
+                       if (claws_fputs(out, outfp) == EOF)
                                err = TRUE;
                        g_free(out);
                                err = TRUE;
                        g_free(out);
-                       if (SC_FPUTC('\n', outfp) == EOF)
+                       if (claws_fputc('\n', outfp) == EOF)
                                err = TRUE;
                }
 
                if (tmp_file) {
                                err = TRUE;
                }
 
                if (tmp_file) {
-                       procmime_fclose(tmp_fp);
+                       claws_fclose(tmp_fp);
                        claws_unlink(tmp_file);
                        g_free(tmp_file);
                }
        } else if (encoding == ENC_QUOTED_PRINTABLE) {
                gchar inbuf[BUFFSIZE], outbuf[BUFFSIZE * 4];
 
                        claws_unlink(tmp_file);
                        g_free(tmp_file);
                }
        } else if (encoding == ENC_QUOTED_PRINTABLE) {
                gchar inbuf[BUFFSIZE], outbuf[BUFFSIZE * 4];
 
-               while (SC_FGETS(inbuf, sizeof(inbuf), infp) != NULL) {
+               while (claws_fgets(inbuf, sizeof(inbuf), infp) != NULL) {
                        qp_encode_line(outbuf, inbuf);
 
                        if (!strncmp("From ", outbuf, sizeof("From ")-1)) {
                        qp_encode_line(outbuf, inbuf);
 
                        if (!strncmp("From ", outbuf, sizeof("From ")-1)) {
@@ -655,27 +607,27 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding)
                                
                                tmpbuf += sizeof("From ")-1;
                                
                                
                                tmpbuf += sizeof("From ")-1;
                                
-                               if (SC_FPUTS("=46rom ", outfp) == EOF)
+                               if (claws_fputs("=46rom ", outfp) == EOF)
                                        err = TRUE;
                                        err = TRUE;
-                               if (SC_FPUTS(tmpbuf, outfp) == EOF)
+                               if (claws_fputs(tmpbuf, outfp) == EOF)
                                        err = TRUE;
                        } else {
                                        err = TRUE;
                        } else {
-                               if (SC_FPUTS(outbuf, outfp) == EOF)
+                               if (claws_fputs(outbuf, outfp) == EOF)
                                        err = TRUE;
                        }
                }
        } else {
                gchar buf[BUFFSIZE];
 
                                        err = TRUE;
                        }
                }
        } else {
                gchar buf[BUFFSIZE];
 
-               while (SC_FGETS(buf, sizeof(buf), infp) != NULL) {
+               while (claws_fgets(buf, sizeof(buf), infp) != NULL) {
                        strcrchomp(buf);
                        strcrchomp(buf);
-                       if (SC_FPUTS(buf, outfp) == EOF)
+                       if (claws_fputs(buf, outfp) == EOF)
                                err = TRUE;
                }
        }
 
                                err = TRUE;
                }
        }
 
-       procmime_fclose(outfp);
-       procmime_fclose(infp);
+       claws_fclose(outfp);
+       claws_fclose(infp);
 
        if (err == TRUE)
                return FALSE;
 
        if (err == TRUE)
                return FALSE;
@@ -716,30 +668,30 @@ static gint procmime_get_part_to_stream(FILE *outfp, MimeInfo *mimeinfo)
        if (mimeinfo->encoding_type != ENC_BINARY && !procmime_decode_content(mimeinfo))
                return -EINVAL;
 
        if (mimeinfo->encoding_type != ENC_BINARY && !procmime_decode_content(mimeinfo))
                return -EINVAL;
 
-       if ((infp = procmime_fopen(mimeinfo->data.filename, "rb")) == NULL) {
+       if ((infp = claws_fopen(mimeinfo->data.filename, "rb")) == NULL) {
                saved_errno = errno;
                saved_errno = errno;
-               FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
+               FILE_OP_ERROR(mimeinfo->data.filename, "claws_fopen");
                return -(saved_errno);
        }
        if (fseek(infp, mimeinfo->offset, SEEK_SET) < 0) {
                saved_errno = errno;
                FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
                return -(saved_errno);
        }
        if (fseek(infp, mimeinfo->offset, SEEK_SET) < 0) {
                saved_errno = errno;
                FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
-               procmime_fclose(infp);
+               claws_fclose(infp);
                return -(saved_errno);
        }
 
        restlength = mimeinfo->length;
 
                return -(saved_errno);
        }
 
        restlength = mimeinfo->length;
 
-       while ((restlength > 0) && ((readlength = SC_FREAD(buf, 1, restlength > BUFFSIZE ? BUFFSIZE : restlength, infp)) > 0)) {
-               if (SC_FWRITE(buf, 1, readlength, outfp) != readlength) {
+       while ((restlength > 0) && ((readlength = claws_fread(buf, 1, restlength > BUFFSIZE ? BUFFSIZE : restlength, infp)) > 0)) {
+               if (claws_fwrite(buf, 1, readlength, outfp) != readlength) {
                        saved_errno = errno;
                        saved_errno = errno;
-                       procmime_fclose(infp);
+                       claws_fclose(infp);
                        return -(saved_errno);
                }
                restlength -= readlength;
        }
 
                        return -(saved_errno);
                }
                restlength -= readlength;
        }
 
-       procmime_fclose(infp);
+       claws_fclose(infp);
        rewind(outfp);
 
        return 0;
        rewind(outfp);
 
        return 0;
@@ -753,17 +705,17 @@ gint procmime_get_part(const gchar *outfile, MimeInfo *mimeinfo)
 
        cm_return_val_if_fail(outfile != NULL, -1);
 
 
        cm_return_val_if_fail(outfile != NULL, -1);
 
-       if ((outfp = procmime_fopen(outfile, "wb")) == NULL) {
+       if ((outfp = claws_fopen(outfile, "wb")) == NULL) {
                saved_errno = errno;
                saved_errno = errno;
-               FILE_OP_ERROR(outfile, "fopen");
+               FILE_OP_ERROR(outfile, "claws_fopen");
                return -(saved_errno);
        }
 
        result = procmime_get_part_to_stream(outfp, mimeinfo);
 
                return -(saved_errno);
        }
 
        result = procmime_get_part_to_stream(outfp, mimeinfo);
 
-       if (procmime_fclose(outfp) == EOF) {
+       if (claws_fclose(outfp) == EOF) {
                saved_errno = errno;
                saved_errno = errno;
-               FILE_OP_ERROR(outfile, "fclose");
+               FILE_OP_ERROR(outfile, "claws_fclose");
                claws_unlink(outfile);
                return -(saved_errno);
        }
                claws_unlink(outfile);
                return -(saved_errno);
        }
@@ -799,7 +751,7 @@ gboolean procmime_scan_text_content(MimeInfo *mimeinfo,
                return TRUE;
        }
 
                return TRUE;
        }
 
-       tmpfp = procmime_fopen(tmpfile, "w+");
+       tmpfp = claws_fopen(tmpfile, "w+");
 #endif
 
        if (tmpfp == NULL) {
 #endif
 
        if (tmpfp == NULL) {
@@ -855,7 +807,7 @@ gboolean procmime_scan_text_content(MimeInfo *mimeinfo,
                ertf_parser_destroy(parser);
                conv_code_converter_destroy(conv);
        } else if (mimeinfo->type == MIMETYPE_TEXT && mimeinfo->disposition != DISPOSITIONTYPE_ATTACHMENT) {
                ertf_parser_destroy(parser);
                conv_code_converter_destroy(conv);
        } else if (mimeinfo->type == MIMETYPE_TEXT && mimeinfo->disposition != DISPOSITIONTYPE_ATTACHMENT) {
-               while (SC_FGETS(buf, sizeof(buf), tmpfp) != NULL) {
+               while (claws_fgets(buf, sizeof(buf), tmpfp) != NULL) {
                        str = conv_codeset_strdup(buf, src_codeset, CS_UTF_8);
                        if (str) {
                                if ((scan_ret = scan_callback(str, cb_data)) == TRUE) {
                        str = conv_codeset_strdup(buf, src_codeset, CS_UTF_8);
                        if (str) {
                                if ((scan_ret = scan_callback(str, cb_data)) == TRUE) {
@@ -874,7 +826,7 @@ gboolean procmime_scan_text_content(MimeInfo *mimeinfo,
        if (conv_fail)
                g_warning("procmime_get_text_content(): Code conversion failed.");
 
        if (conv_fail)
                g_warning("procmime_get_text_content(): Code conversion failed.");
 
-       procmime_fclose(tmpfp);
+       claws_fclose(tmpfp);
 
 #if !HAVE_FMEMOPEN
        claws_unlink(tmpfile);
 
 #if !HAVE_FMEMOPEN
        claws_unlink(tmpfile);
@@ -886,7 +838,7 @@ gboolean procmime_scan_text_content(MimeInfo *mimeinfo,
 
 static gboolean scan_fputs_cb(const gchar *str, gpointer fp)
 {
 
 static gboolean scan_fputs_cb(const gchar *str, gpointer fp)
 {
-       if (SC_FPUTS(str, (FILE *)fp) == EOF)
+       if (claws_fputs(str, (FILE *)fp) == EOF)
                return TRUE;
        
        return FALSE;
                return TRUE;
        
        return FALSE;
@@ -901,20 +853,14 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo)
                perror("my_tmpfile");
                return NULL;
        }
                perror("my_tmpfile");
                return NULL;
        }
-#ifdef HAVE_FGETS_UNLOCKED
-       flockfile(outfp);
-#endif
 
        err = procmime_scan_text_content(mimeinfo, scan_fputs_cb, outfp);
 
        rewind(outfp);
        if (err == TRUE) {
 
        err = procmime_scan_text_content(mimeinfo, scan_fputs_cb, outfp);
 
        rewind(outfp);
        if (err == TRUE) {
-               procmime_fclose(outfp);
+               claws_fclose(outfp);
                return NULL;
        }
                return NULL;
        }
-#ifdef HAVE_FGETS_UNLOCKED
-       funlockfile(outfp);
-#endif
        return outfp;
 
 }
        return outfp;
 
 }
@@ -922,7 +868,9 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo)
 FILE *procmime_get_binary_content(MimeInfo *mimeinfo)
 {
        FILE *outfp;
 FILE *procmime_get_binary_content(MimeInfo *mimeinfo)
 {
        FILE *outfp;
+#if !HAVE_FMEMOPEN
        gchar *tmpfile = NULL;
        gchar *tmpfile = NULL;
+#endif
 
        cm_return_val_if_fail(mimeinfo != NULL, NULL);
 
 
        cm_return_val_if_fail(mimeinfo != NULL, NULL);
 
@@ -938,21 +886,18 @@ FILE *procmime_get_binary_content(MimeInfo *mimeinfo)
                return TRUE;
        }
 
                return TRUE;
        }
 
-       outfp = procmime_fopen(tmpfile, "w+");
-#endif
+       outfp = claws_fopen(tmpfile, "w+");
 
        if (tmpfile != NULL) {
                g_unlink(tmpfile);
                g_free(tmpfile);
        }
 
        if (tmpfile != NULL) {
                g_unlink(tmpfile);
                g_free(tmpfile);
        }
+#endif
 
        if (procmime_get_part_to_stream(outfp, mimeinfo) < 0) {
                return NULL;
        }
 
 
        if (procmime_get_part_to_stream(outfp, mimeinfo) < 0) {
                return NULL;
        }
 
-#ifdef HAVE_FGETS_UNLOCKED
-       funlockfile(outfp);
-#endif
        return outfp;
 }
 
        return outfp;
 }
 
@@ -998,7 +943,6 @@ scan_again:
        }
        procmime_mimeinfo_free_all(&mimeinfo);
 
        }
        procmime_mimeinfo_free_all(&mimeinfo);
 
-       /* outfp already unlocked at this time */
        return outfp;
 }
 
        return outfp;
 }
 
@@ -1061,7 +1005,6 @@ FILE *procmime_get_first_encrypted_text_content(MsgInfo *msginfo)
 
        procmime_mimeinfo_free_all(&mimeinfo);
 
 
        procmime_mimeinfo_free_all(&mimeinfo);
 
-       /* outfp already unlocked at this time */
        return outfp;
 }
 
        return outfp;
 }
 
@@ -1240,23 +1183,23 @@ GList *procmime_get_mime_type_list(void)
                return mime_type_list;
        
 #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
                return mime_type_list;
        
 #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
-       if ((fp = procmime_fopen(DATAROOTDIR "/mime/globs", "rb")) == NULL) 
+       if ((fp = claws_fopen(DATAROOTDIR "/mime/globs", "rb")) == NULL) 
 #else
 #else
-       if ((fp = procmime_fopen("/usr/share/mime/globs", "rb")) == NULL) 
+       if ((fp = claws_fopen("/usr/share/mime/globs", "rb")) == NULL) 
 #endif
        {
                fp_is_glob_file = FALSE;
 #endif
        {
                fp_is_glob_file = FALSE;
-               if ((fp = procmime_fopen("/etc/mime.types", "rb")) == NULL) {
-                       if ((fp = procmime_fopen(SYSCONFDIR "/mime.types", "rb")) 
+               if ((fp = claws_fopen("/etc/mime.types", "rb")) == NULL) {
+                       if ((fp = claws_fopen(SYSCONFDIR "/mime.types", "rb")) 
                                == NULL) {
                                FILE_OP_ERROR(SYSCONFDIR "/mime.types", 
                                == NULL) {
                                FILE_OP_ERROR(SYSCONFDIR "/mime.types", 
-                                       "fopen");
+                                       "claws_fopen");
                                return NULL;
                        }
                }
        }
 
                                return NULL;
                        }
                }
        }
 
-       while (SC_FGETS(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                p = strchr(buf, '#');
                if (p) *p = '\0';
                g_strstrip(buf);
                p = strchr(buf, '#');
                if (p) *p = '\0';
                g_strstrip(buf);
@@ -1295,7 +1238,7 @@ GList *procmime_get_mime_type_list(void)
                list = g_list_append(list, mime_type);
        }
 
                list = g_list_append(list, mime_type);
        }
 
-       procmime_fclose(fp);
+       claws_fclose(fp);
 
        if (!list)
                g_warning("Can't read mime.types");
 
        if (!list)
                g_warning("Can't read mime.types");
@@ -1334,12 +1277,12 @@ EncodingType procmime_get_encoding_for_text_file(const gchar *file, gboolean *ha
        gfloat octet_percentage;
        gboolean force_b64 = FALSE;
 
        gfloat octet_percentage;
        gboolean force_b64 = FALSE;
 
-       if ((fp = procmime_fopen(file, "rb")) == NULL) {
-               FILE_OP_ERROR(file, "fopen");
+       if ((fp = claws_fopen(file, "rb")) == NULL) {
+               FILE_OP_ERROR(file, "claws_fopen");
                return ENC_UNKNOWN;
        }
 
                return ENC_UNKNOWN;
        }
 
-       while ((len = SC_FREAD(buf, sizeof(guchar), sizeof(buf), fp)) > 0) {
+       while ((len = claws_fread(buf, sizeof(guchar), sizeof(buf), fp)) > 0) {
                guchar *p;
                gint i;
 
                guchar *p;
                gint i;
 
@@ -1354,7 +1297,7 @@ EncodingType procmime_get_encoding_for_text_file(const gchar *file, gboolean *ha
                total_len += len;
        }
 
                total_len += len;
        }
 
-       procmime_fclose(fp);
+       claws_fclose(fp);
        
        if (total_len > 0)
                octet_percentage = (gfloat)octet_chars / (gfloat)total_len;
        
        if (total_len > 0)
                octet_percentage = (gfloat)octet_chars / (gfloat)total_len;
@@ -1500,14 +1443,14 @@ static void procmime_parse_message_rfc822(MimeInfo *mimeinfo, gboolean short_sca
 
        procmime_decode_content(mimeinfo);
 
 
        procmime_decode_content(mimeinfo);
 
-       fp = procmime_fopen(mimeinfo->data.filename, "rb");
+       fp = claws_fopen(mimeinfo->data.filename, "rb");
        if (fp == NULL) {
        if (fp == NULL) {
-               FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
+               FILE_OP_ERROR(mimeinfo->data.filename, "claws_fopen");
                return;
        }
        if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) {
                FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
                return;
        }
        if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) {
                FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
-               procmime_fclose(fp);
+               claws_fclose(fp);
                return;
        }
        procheader_get_header_fields(fp, hentry);
                return;
        }
        procheader_get_header_fields(fp, hentry);
@@ -1543,7 +1486,7 @@ static void procmime_parse_message_rfc822(MimeInfo *mimeinfo, gboolean short_sca
         }
   
        content_start = ftell(fp);
         }
   
        content_start = ftell(fp);
-       procmime_fclose(fp);
+       claws_fclose(fp);
        
        len = mimeinfo->length - (content_start - mimeinfo->offset);
        if (len < 0)
        
        len = mimeinfo->length - (content_start - mimeinfo->offset);
        if (len < 0)
@@ -1577,14 +1520,14 @@ static void procmime_parse_disposition_notification(MimeInfo *mimeinfo,
        procmime_decode_content(mimeinfo);
 
        debug_print("parse disposition notification\n");
        procmime_decode_content(mimeinfo);
 
        debug_print("parse disposition notification\n");
-       fp = procmime_fopen(mimeinfo->data.filename, "rb");
+       fp = claws_fopen(mimeinfo->data.filename, "rb");
        if (fp == NULL) {
        if (fp == NULL) {
-               FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
+               FILE_OP_ERROR(mimeinfo->data.filename, "claws_fopen");
                return;
        }
        if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) {
                FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
                return;
        }
        if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) {
                FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
-               procmime_fclose(fp);
+               claws_fclose(fp);
                return;
        }
 
                return;
        }
 
@@ -1595,7 +1538,7 @@ static void procmime_parse_disposition_notification(MimeInfo *mimeinfo,
                procheader_get_header_fields(fp, hentry);
        }
     
                procheader_get_header_fields(fp, hentry);
        }
     
-        procmime_fclose(fp);
+        claws_fclose(fp);
 
        if (!hentry[0].body || !hentry[1].body) {
                debug_print("MsgId %s, Disp %s\n",
 
        if (!hentry[0].body || !hentry[1].body) {
                debug_print("MsgId %s, Disp %s\n",
@@ -1706,19 +1649,19 @@ static void procmime_parse_multipart(MimeInfo *mimeinfo, gboolean short_scan)
 
        procmime_decode_content(mimeinfo);
 
 
        procmime_decode_content(mimeinfo);
 
-       fp = procmime_fopen(mimeinfo->data.filename, "rb");
+       fp = claws_fopen(mimeinfo->data.filename, "rb");
        if (fp == NULL) {
        if (fp == NULL) {
-               FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
+               FILE_OP_ERROR(mimeinfo->data.filename, "claws_fopen");
                return;
        }
 
        if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) {
                FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
                return;
        }
 
        if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) {
                FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
-               procmime_fclose(fp);
+               claws_fclose(fp);
                return;
        }
 
                return;
        }
 
-       while (SC_FGETS(buf, sizeof(buf), fp) != NULL && result == 0) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL && result == 0) {
                if (ftell(fp) - 1 > (mimeinfo->offset + mimeinfo->length))
                        break;
 
                if (ftell(fp) - 1 > (mimeinfo->offset + mimeinfo->length))
                        break;
 
@@ -1774,7 +1717,7 @@ static void procmime_parse_multipart(MimeInfo *mimeinfo, gboolean short_scan)
                g_free(hentry[i].body);
                hentry[i].body = NULL;
        }
                g_free(hentry[i].body);
                hentry[i].body = NULL;
        }
-       procmime_fclose(fp);
+       claws_fclose(fp);
 }
 
 static void parse_parameters(const gchar *parameters, GHashTable *table)
 }
 
 static void parse_parameters(const gchar *parameters, GHashTable *table)
@@ -2264,10 +2207,10 @@ static MimeInfo *procmime_scan_queue_file_full(const gchar *filename, gboolean s
        cm_return_val_if_fail(filename != NULL, NULL);
 
        /* Open file */
        cm_return_val_if_fail(filename != NULL, NULL);
 
        /* Open file */
-       if ((fp = procmime_fopen(filename, "rb")) == NULL)
+       if ((fp = claws_fopen(filename, "rb")) == NULL)
                return NULL;
        /* Skip queue header */
                return NULL;
        /* Skip queue header */
-       while (SC_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:"))) ||
                /* new way */
                if ((!strncmp(buf, "X-Claws-End-Special-Headers: 1",
                        strlen("X-Claws-End-Special-Headers:"))) ||
@@ -2286,7 +2229,7 @@ static MimeInfo *procmime_scan_queue_file_full(const gchar *filename, gboolean s
                }
        }
        offset = ftell(fp);
                }
        }
        offset = ftell(fp);
-       procmime_fclose(fp);
+       claws_fclose(fp);
 
        mimeinfo = procmime_scan_file_with_offset(filename, offset, short_scan);
 
 
        mimeinfo = procmime_scan_file_with_offset(filename, offset, short_scan);
 
@@ -2537,16 +2480,16 @@ static gint procmime_write_message_rfc822(MimeInfo *mimeinfo, FILE *fp)
        /* write header */
        switch (mimeinfo->content) {
        case MIMECONTENT_FILE:
        /* write header */
        switch (mimeinfo->content) {
        case MIMECONTENT_FILE:
-               if ((infp = procmime_fopen(mimeinfo->data.filename, "rb")) == NULL) {
-                       FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
+               if ((infp = claws_fopen(mimeinfo->data.filename, "rb")) == NULL) {
+                       FILE_OP_ERROR(mimeinfo->data.filename, "claws_fopen");
                        return -1;
                }
                if (fseek(infp, mimeinfo->offset, SEEK_SET) < 0) {
                        FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
                        return -1;
                }
                if (fseek(infp, mimeinfo->offset, SEEK_SET) < 0) {
                        FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
-                       procmime_fclose(infp);
+                       claws_fclose(infp);
                        return -1;
                }
                        return -1;
                }
-               while (SC_FGETS(buf, sizeof(buf), infp) == buf) {
+               while (claws_fgets(buf, sizeof(buf), infp) == buf) {
                        strcrchomp(buf);
                        if (buf[0] == '\n' && buf[1] == '\0')
                                break;
                        strcrchomp(buf);
                        if (buf[0] == '\n' && buf[1] == '\0')
                                break;
@@ -2563,19 +2506,19 @@ static gint procmime_write_message_rfc822(MimeInfo *mimeinfo, FILE *fp)
                                continue;
                        }
                        len = strlen(buf);
                                continue;
                        }
                        len = strlen(buf);
-                       if (SC_FWRITE(buf, sizeof(gchar), len, fp) < len) {
+                       if (claws_fwrite(buf, sizeof(gchar), len, fp) < len) {
                                g_warning("failed to dump %zd bytes from file", len);
                                g_warning("failed to dump %zd bytes from file", len);
-                               procmime_fclose(infp);
+                               claws_fclose(infp);
                                return -1;
                        }
                        skip = FALSE;
                }
                                return -1;
                        }
                        skip = FALSE;
                }
-               procmime_fclose(infp);
+               claws_fclose(infp);
                break;
 
        case MIMECONTENT_MEM:
                len = strlen(mimeinfo->data.mem);
                break;
 
        case MIMECONTENT_MEM:
                len = strlen(mimeinfo->data.mem);
-               if (SC_FWRITE(mimeinfo->data.mem, sizeof(gchar), len, fp) < len) {
+               if (claws_fwrite(mimeinfo->data.mem, sizeof(gchar), len, fp) < len) {
                        g_warning("failed to dump %zd bytes from mem", len);
                        return -1;
                }
                        g_warning("failed to dump %zd bytes from mem", len);
                        return -1;
                }
@@ -2614,26 +2557,26 @@ static gint procmime_write_multipart(MimeInfo *mimeinfo, FILE *fp)
 
        switch (mimeinfo->content) {
        case MIMECONTENT_FILE:
 
        switch (mimeinfo->content) {
        case MIMECONTENT_FILE:
-               if ((infp = procmime_fopen(mimeinfo->data.filename, "rb")) == NULL) {
-                       FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
+               if ((infp = claws_fopen(mimeinfo->data.filename, "rb")) == NULL) {
+                       FILE_OP_ERROR(mimeinfo->data.filename, "claws_fopen");
                        return -1;
                }
                if (fseek(infp, mimeinfo->offset, SEEK_SET) < 0) {
                        FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
                        return -1;
                }
                if (fseek(infp, mimeinfo->offset, SEEK_SET) < 0) {
                        FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
-                       procmime_fclose(infp);
+                       claws_fclose(infp);
                        return -1;
                }
                        return -1;
                }
-               while (SC_FGETS(buf, sizeof(buf), infp) == buf) {
+               while (claws_fgets(buf, sizeof(buf), infp) == buf) {
                        if (IS_BOUNDARY(buf, boundary, strlen(boundary)))
                                break;
                        len = strlen(buf);
                        if (IS_BOUNDARY(buf, boundary, strlen(boundary)))
                                break;
                        len = strlen(buf);
-                       if (SC_FWRITE(buf, sizeof(gchar), len, fp) < len) {
+                       if (claws_fwrite(buf, sizeof(gchar), len, fp) < len) {
                                g_warning("failed to write %zd", len);
                                g_warning("failed to write %zd", len);
-                               procmime_fclose(infp);
+                               claws_fclose(infp);
                                return -1;
                        }
                }
                                return -1;
                        }
                }
-               procmime_fclose(infp);
+               claws_fclose(infp);
                break;
 
        case MIMECONTENT_MEM:
                break;
 
        case MIMECONTENT_MEM:
@@ -2642,7 +2585,7 @@ static gint procmime_write_multipart(MimeInfo *mimeinfo, FILE *fp)
                    (*(str2 - 1) == '-') && (*(str2 - 2) == '-'))
                        *(str2 - 2) = '\0';
                len = strlen(str);
                    (*(str2 - 1) == '-') && (*(str2 - 2) == '-'))
                        *(str2 - 2) = '\0';
                len = strlen(str);
-               if (SC_FWRITE(str, sizeof(gchar), len, fp) < len) {
+               if (claws_fwrite(str, sizeof(gchar), len, fp) < len) {
                        g_warning("failed to write %zd from mem", len);
                        g_free(str);
                        return -1;
                        g_warning("failed to write %zd from mem", len);
                        g_free(str);
                        return -1;
@@ -2687,17 +2630,17 @@ gint procmime_write_mimeinfo(MimeInfo *mimeinfo, FILE *fp)
        if (G_NODE_IS_LEAF(mimeinfo->node)) {
                switch (mimeinfo->content) {
                case MIMECONTENT_FILE:
        if (G_NODE_IS_LEAF(mimeinfo->node)) {
                switch (mimeinfo->content) {
                case MIMECONTENT_FILE:
-                       if ((infp = procmime_fopen(mimeinfo->data.filename, "rb")) == NULL) {
-                               FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
+                       if ((infp = claws_fopen(mimeinfo->data.filename, "rb")) == NULL) {
+                               FILE_OP_ERROR(mimeinfo->data.filename, "claws_fopen");
                                return -1;
                        }
                        copy_file_part_to_fp(infp, mimeinfo->offset, mimeinfo->length, fp);
                                return -1;
                        }
                        copy_file_part_to_fp(infp, mimeinfo->offset, mimeinfo->length, fp);
-                       procmime_fclose(infp);
+                       claws_fclose(infp);
                        return 0;
 
                case MIMECONTENT_MEM:
                        len = strlen(mimeinfo->data.mem);
                        return 0;
 
                case MIMECONTENT_MEM:
                        len = strlen(mimeinfo->data.mem);
-                       if (SC_FWRITE(mimeinfo->data.mem, sizeof(gchar), len, fp) < len)
+                       if (claws_fwrite(mimeinfo->data.mem, sizeof(gchar), len, fp) < len)
                                return -1;
                        return 0;
 
                                return -1;
                        return 0;
 
index 73cd7c0057684a7ecf4f4182d5bd391165dc50e2..34eff5197e5604af863dcd867d170b2de58bccd6 100644 (file)
@@ -496,8 +496,8 @@ FILE *procmsg_open_message(MsgInfo *msginfo)
                        return NULL;
        }
 
                        return NULL;
        }
 
-       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 NULL;
        }
                g_free(file);
                return NULL;
        }
@@ -507,7 +507,7 @@ FILE *procmsg_open_message(MsgInfo *msginfo)
        if (MSG_IS_QUEUED(msginfo->flags) || MSG_IS_DRAFT(msginfo->flags)) {
                gchar buf[BUFFSIZE];
 
        if (MSG_IS_QUEUED(msginfo->flags) || MSG_IS_DRAFT(msginfo->flags)) {
                gchar buf[BUFFSIZE];
 
-               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:"))) ||
                        /* new way */
                        if ((!strncmp(buf, "X-Claws-End-Special-Headers: 1",
                                strlen("X-Claws-End-Special-Headers:"))) ||
@@ -581,7 +581,7 @@ void procmsg_get_filter_keyword(MsgInfo *msginfo, gchar **header, gchar **key,
                if ((fp = procmsg_open_message(msginfo)) == NULL)
                        return;
                procheader_get_header_fields(fp, hentry);
                if ((fp = procmsg_open_message(msginfo)) == NULL)
                        return;
                procheader_get_header_fields(fp, hentry);
-               fclose(fp);
+               claws_fclose(fp);
 
 #define SET_FILTER_KEY(hstr, idx)      \
 {                                      \
 
 #define SET_FILTER_KEY(hstr, idx)      \
 {                                      \
@@ -743,8 +743,8 @@ static PrefsAccount *procmsg_get_account_from_file(const gchar *file)
        
        cm_return_val_if_fail(file != NULL, NULL);
 
        
        cm_return_val_if_fail(file != NULL, NULL);
 
-       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 NULL;
        }
 
                return NULL;
        }
 
@@ -758,7 +758,7 @@ static PrefsAccount *procmsg_get_account_from_file(const gchar *file)
                g_free(buf);
                buf = NULL;
        }
                g_free(buf);
                buf = NULL;
        }
-       fclose(fp);
+       claws_fclose(fp);
        return mailac;
 }
 
        return mailac;
 }
 
@@ -1086,16 +1086,16 @@ gint procmsg_remove_special_headers(const gchar *in, const gchar *out)
        FILE *fp, *outfp;
        gchar buf[BUFFSIZE];
        
        FILE *fp, *outfp;
        gchar buf[BUFFSIZE];
        
-       if ((fp = g_fopen(in, "rb")) == NULL) {
-               FILE_OP_ERROR(in, "fopen");
+       if ((fp = claws_fopen(in, "rb")) == NULL) {
+               FILE_OP_ERROR(in, "claws_fopen");
                return -1;
        }
                return -1;
        }
-       if ((outfp = g_fopen(out, "wb")) == NULL) {
-               FILE_OP_ERROR(out, "fopen");
-               fclose(fp);
+       if ((outfp = claws_fopen(out, "wb")) == NULL) {
+               FILE_OP_ERROR(out, "claws_fopen");
+               claws_fclose(fp);
                return -1;
        }
                return -1;
        }
-       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:"))) ||
                /* new way */
                if ((!strncmp(buf, "X-Claws-End-Special-Headers: 1",
                        strlen("X-Claws-End-Special-Headers:"))) ||
@@ -1113,16 +1113,16 @@ gint procmsg_remove_special_headers(const gchar *in, const gchar *out)
                        break;
                }
        }
                        break;
                }
        }
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
-               if (fputs(buf, outfp) == EOF) {
-                       FILE_OP_ERROR(out, "fputs");
-                       fclose(outfp);
-                       fclose(fp);
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
+               if (claws_fputs(buf, outfp) == EOF) {
+                       FILE_OP_ERROR(out, "claws_fputs");
+                       claws_fclose(outfp);
+                       claws_fclose(fp);
                        return -1;
                }
        }
                        return -1;
                }
        }
-       safe_fclose(outfp);
-       fclose(fp);
+       claws_safe_fclose(outfp);
+       claws_fclose(fp);
        return 0;
 }
 
        return 0;
 }
 
@@ -1549,8 +1549,8 @@ static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_ses
 
        cm_return_val_if_fail(file != NULL, -1);
 
 
        cm_return_val_if_fail(file != NULL, -1);
 
-       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");
                if (errstr) {
                        if (*errstr) g_free(*errstr);
                        *errstr = g_strdup_printf(_("Couldn't open file %s."), file);
                if (errstr) {
                        if (*errstr) g_free(*errstr);
                        *errstr = g_strdup_printf(_("Couldn't open file %s."), file);
@@ -1686,8 +1686,8 @@ send_mail:
                /* write to temporary file */
                tmp = g_strdup_printf("%s%cnntp%p", get_tmp_dir(),
                            G_DIR_SEPARATOR, file);
                /* write to temporary file */
                tmp = g_strdup_printf("%s%cnntp%p", get_tmp_dir(),
                            G_DIR_SEPARATOR, file);
-               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");
                        newsval = -1;
                        alertpanel_error(_("Couldn't create temporary file for news sending."));
                } else {
                        newsval = -1;
                        alertpanel_error(_("Couldn't create temporary file for news sending."));
                } else {
@@ -1696,9 +1696,9 @@ send_mail:
                                g_warning("can't change file mode");
                        }
 
                                g_warning("can't change file mode");
                        }
 
-                       while ((newsval == 0) && fgets(buf, sizeof(buf), fp) != NULL) {
-                               if (fputs(buf, tmpfp) == EOF) {
-                                       FILE_OP_ERROR(tmp, "fputs");
+                       while ((newsval == 0) && claws_fgets(buf, sizeof(buf), fp) != NULL) {
+                               if (claws_fputs(buf, tmpfp) == EOF) {
+                                       FILE_OP_ERROR(tmp, "claws_fputs");
                                        newsval = -1;
                                        if (errstr) {
                                                if (*errstr) g_free(*errstr);
                                        newsval = -1;
                                        if (errstr) {
                                                if (*errstr) g_free(*errstr);
@@ -1706,7 +1706,7 @@ send_mail:
                                        }
                                }
                        }
                                        }
                                }
                        }
-                       safe_fclose(tmpfp);
+                       claws_safe_fclose(tmpfp);
 
                        if (newsval == 0) {
                                debug_print("Sending message by news\n");
 
                        if (newsval == 0) {
                                debug_print("Sending message by news\n");
@@ -1725,7 +1725,7 @@ send_mail:
                g_free(tmp);
        }
 
                g_free(tmp);
        }
 
-       fclose(fp);
+       claws_fclose(fp);
 
        /* update session statistics */
        if (mailval == 0 && newsval == 0) {
 
        /* update session statistics */
        if (mailval == 0 && newsval == 0) {
@@ -2328,26 +2328,26 @@ MsgInfo *procmsg_msginfo_new_from_mimeinfo(MsgInfo *src_msginfo, MimeInfo *mimei
        MsgInfo *tmp_msginfo = NULL;
        MsgFlags flags = {0, 0};
        gchar *tmpfile = get_tmp_file();
        MsgInfo *tmp_msginfo = NULL;
        MsgFlags flags = {0, 0};
        gchar *tmpfile = get_tmp_file();
-       FILE *fp = g_fopen(tmpfile, "wb");
+       FILE *fp = claws_fopen(tmpfile, "wb");
        
        if (!mimeinfo || mimeinfo->type != MIMETYPE_MESSAGE ||
            g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
                g_warning("procmsg_msginfo_new_from_mimeinfo(): unsuitable mimeinfo");
                if (fp) 
        
        if (!mimeinfo || mimeinfo->type != MIMETYPE_MESSAGE ||
            g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
                g_warning("procmsg_msginfo_new_from_mimeinfo(): unsuitable mimeinfo");
                if (fp) 
-                       fclose(fp);
+                       claws_fclose(fp);
                g_free(tmpfile);
                return NULL;
        }
        
        if (fp && procmime_write_mimeinfo(mimeinfo, fp) >= 0) {
                g_free(tmpfile);
                return NULL;
        }
        
        if (fp && procmime_write_mimeinfo(mimeinfo, fp) >= 0) {
-               safe_fclose(fp);
+               claws_safe_fclose(fp);
                fp = NULL;
                tmp_msginfo = procheader_parse_file(
                        tmpfile, flags, 
                        TRUE, FALSE);
        }
        if (fp)
                fp = NULL;
                tmp_msginfo = procheader_parse_file(
                        tmpfile, flags, 
                        TRUE, FALSE);
        }
        if (fp)
-               safe_fclose(fp);
+               claws_safe_fclose(fp);
 
        if (tmp_msginfo != NULL) {
                if (src_msginfo)
 
        if (tmp_msginfo != NULL) {
                if (src_msginfo)
index 92e300e03b977ed033255726a6c2903bd8af12e0..515d910aeefdb9a5d671eb28e1ede6d27c5a9709 100644 (file)
@@ -37,6 +37,7 @@
 #include "quote_fmt.h"
 #include "quote_fmt_lex.h"
 #include "account.h"
 #include "quote_fmt.h"
 #include "quote_fmt_lex.h"
 #include "account.h"
+#include "claws_io.h"
 
 /* decl */
 /*
 
 /* decl */
 /*
index 497fe4de311b20610de5eb34ca16354e13e69346..d0a2160f804a727013ace4859052db8a26b9082c 100644 (file)
@@ -56,6 +56,7 @@
 #include "inc.h"
 #include "log.h"
 #include "passwordstore.h"
 #include "inc.h"
 #include "log.h"
 #include "passwordstore.h"
+#include "claws_io.h"
 
 typedef struct _SendProgressDialog     SendProgressDialog;
 
 
 typedef struct _SendProgressDialog     SendProgressDialog;
 
@@ -110,8 +111,8 @@ gint send_message(const gchar *file, PrefsAccount *ac_prefs, GSList *to_list)
        cm_return_val_if_fail(ac_prefs != NULL, -1);
        cm_return_val_if_fail(to_list != NULL, -1);
 
        cm_return_val_if_fail(ac_prefs != NULL, -1);
        cm_return_val_if_fail(to_list != NULL, -1);
 
-       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 -1;
        }
 
                return -1;
        }
 
@@ -119,13 +120,13 @@ gint send_message(const gchar *file, PrefsAccount *ac_prefs, GSList *to_list)
        if (ac_prefs->use_mail_command && ac_prefs->mail_command &&
            (*ac_prefs->mail_command)) {
                val = send_message_local(ac_prefs->mail_command, fp);
        if (ac_prefs->use_mail_command && ac_prefs->mail_command &&
            (*ac_prefs->mail_command)) {
                val = send_message_local(ac_prefs->mail_command, fp);
-               fclose(fp);
+               claws_fclose(fp);
                inc_unlock();
                return val;
        } else {
                val = send_message_smtp(ac_prefs, to_list, fp);
                
                inc_unlock();
                return val;
        } else {
                val = send_message_smtp(ac_prefs, to_list, fp);
                
-               fclose(fp);
+               claws_fclose(fp);
                inc_unlock();
                return val;
        }
                inc_unlock();
                return val;
        }
@@ -172,7 +173,7 @@ gint send_message_local(const gchar *command, FILE *fp)
        }
        g_strfreev(argv);
 
        }
        g_strfreev(argv);
 
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
                strretchomp(buf);
                if (buf[0] == '.' && buf[1] == '\0') {
                        if (fd_write_all(child_stdin, ".", 1) < 0) {
                strretchomp(buf);
                if (buf[0] == '.' && buf[1] == '\0') {
                        if (fd_write_all(child_stdin, ".", 1) < 0) {
index 43c40ff954de5e7f7709897827abc15498acee66..a16ce866f501fe5a72b1fd31fe6ec79ecf3d35be 100644 (file)
@@ -30,6 +30,7 @@
 #include "utils.h"
 #include "gtkutils.h"
 #include "prefs_common.h"
 #include "utils.h"
 #include "gtkutils.h"
 #include "prefs_common.h"
+#include "claws_io.h"
 
 static void source_window_size_alloc_cb        (GtkWidget      *widget,
                                         GtkAllocation  *allocation);
 
 static void source_window_size_alloc_cb        (GtkWidget      *widget,
                                         GtkAllocation  *allocation);
@@ -148,8 +149,8 @@ void source_window_show_msg(SourceWindow *sourcewin, MsgInfo *msginfo)
 
        cm_return_if_fail(file != NULL);
 
 
        cm_return_if_fail(file != NULL);
 
-       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;
        }
                g_free(file);
                return;
        }
@@ -161,10 +162,10 @@ void source_window_show_msg(SourceWindow *sourcewin, MsgInfo *msginfo)
        g_free(title);
        g_free(file);
 
        g_free(title);
        g_free(file);
 
-       while (fgets(buf, sizeof(buf), fp) != NULL)
+       while (claws_fgets(buf, sizeof(buf), fp) != NULL)
                source_window_append(sourcewin, buf);
 
                source_window_append(sourcewin, buf);
 
-       fclose(fp);
+       claws_fclose(fp);
 }
 
 static void source_window_append(SourceWindow *sourcewin, const gchar *str)
 }
 
 static void source_window_append(SourceWindow *sourcewin, const gchar *str)
index 8fe04840faea08d0327ff72ae97902e750b7fbfd..1bba49561af19f6700a04b4865095f2ae6a0f34e 100644 (file)
@@ -1151,7 +1151,7 @@ static void summaryview_quicksearch_recurse(SummaryView *summaryview)
                || summaryview->folder_item == NULL) {
                return;
        }
                || summaryview->folder_item == NULL) {
                return;
        }
-
+       START_TIMING("");
        main_window_cursor_wait(summaryview->mainwin);
 
        summaryview_reset_recursive_folder_match(summaryview);
        main_window_cursor_wait(summaryview->mainwin);
 
        summaryview_reset_recursive_folder_match(summaryview);
@@ -1160,6 +1160,7 @@ static void summaryview_quicksearch_recurse(SummaryView *summaryview)
        summaryview_quicksearch_search_subfolders(summaryview, summaryview->folder_item);
        
        main_window_cursor_normal(summaryview->mainwin);
        summaryview_quicksearch_search_subfolders(summaryview, summaryview->folder_item);
        
        main_window_cursor_normal(summaryview->mainwin);
+       END_TIMING();
 }
 
 static gboolean summary_check_consistency(FolderItem *item, GSList *mlist)
 }
 
 static gboolean summary_check_consistency(FolderItem *item, GSList *mlist)
@@ -8452,12 +8453,8 @@ gboolean summary_is_opened_message_selected(SummaryView *summaryview)
 
 gboolean summary_has_opened_message(SummaryView *summaryview)
 {
 
 gboolean summary_has_opened_message(SummaryView *summaryview)
 {
-       GList *sel = NULL;
-
        cm_return_val_if_fail(summaryview != NULL, FALSE);
 
        cm_return_val_if_fail(summaryview != NULL, FALSE);
 
-       sel = GTK_CMCLIST(summaryview->ctree)->selection;
-
        return (summaryview->displayed != NULL);
 }
 
        return (summaryview->displayed != NULL);
 }
 
index fb72094e8c1a8df68be6ee818fcfabadb0a1aad2..e4d2b510be1d0f7936e1efda2ec6f96588f5830f 100644 (file)
@@ -69,6 +69,7 @@
 #include "folder_item_prefs.h"
 #include "hooks.h"
 #include "avatars.h"
 #include "folder_item_prefs.h"
 #include "hooks.h"
 #include "avatars.h"
+#include "claws_io.h"
 
 static GdkColor quote_colors[3] = {
        {(gulong)0, (gushort)0, (gushort)0, (gushort)0},
 
 static GdkColor quote_colors[3] = {
        {(gulong)0, (gushort)0, (gushort)0, (gushort)0},
@@ -688,15 +689,15 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                if (mimeinfo->content == MIMECONTENT_MEM)
                        fp = str_open_as_stream(mimeinfo->data.mem);
                else
                if (mimeinfo->content == MIMECONTENT_MEM)
                        fp = str_open_as_stream(mimeinfo->data.mem);
                else
-                       fp = g_fopen(mimeinfo->data.filename, "rb");
+                       fp = claws_fopen(mimeinfo->data.filename, "rb");
                if (!fp) {
                if (!fp) {
-                       FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
+                       FILE_OP_ERROR(mimeinfo->data.filename, "claws_fopen");
                        END_TIMING();
                        return;
                }
                if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) {
                        FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
                        END_TIMING();
                        return;
                }
                if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) {
                        FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
-                       fclose(fp);
+                       claws_fclose(fp);
                        END_TIMING();
                        return;
                }
                        END_TIMING();
                        return;
                }
@@ -710,7 +711,7 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                        textview_show_header(textview, headers);
                        procheader_header_array_destroy(headers);
                }
                        textview_show_header(textview, headers);
                        procheader_header_array_destroy(headers);
                }
-               fclose(fp);
+               claws_fclose(fp);
                END_TIMING();
                return;
        }
                END_TIMING();
                return;
        }
@@ -1089,10 +1090,10 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                
                filename = procmime_get_tmp_file_name(mimeinfo);
                if (procmime_get_part(filename, mimeinfo) == 0) {
                
                filename = procmime_get_tmp_file_name(mimeinfo);
                if (procmime_get_part(filename, mimeinfo) == 0) {
-                       tmpfp = g_fopen(filename, "rb");
+                       tmpfp = claws_fopen(filename, "rb");
                        if (tmpfp) {
                                textview_show_html(textview, tmpfp, conv);
                        if (tmpfp) {
                                textview_show_html(textview, tmpfp, conv);
-                               fclose(tmpfp);
+                               claws_fclose(tmpfp);
                        }
                        claws_unlink(filename);
                }
                        }
                        claws_unlink(filename);
                }
@@ -1102,10 +1103,10 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                
                filename = procmime_get_tmp_file_name(mimeinfo);
                if (procmime_get_part(filename, mimeinfo) == 0) {
                
                filename = procmime_get_tmp_file_name(mimeinfo);
                if (procmime_get_part(filename, mimeinfo) == 0) {
-                       tmpfp = g_fopen(filename, "rb");
+                       tmpfp = claws_fopen(filename, "rb");
                        if (tmpfp) {
                                textview_show_ertf(textview, tmpfp, conv);
                        if (tmpfp) {
                                textview_show_ertf(textview, tmpfp, conv);
-                               fclose(tmpfp);
+                               claws_fclose(tmpfp);
                        }
                        claws_unlink(filename);
                }
                        }
                        claws_unlink(filename);
                }
@@ -1156,12 +1157,12 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                        exit(255);
                }
                close(pfd[1]);
                        exit(255);
                }
                close(pfd[1]);
-               tmpfp = fdopen(pfd[0], "rb");
-               while (fgets(buf, sizeof(buf), tmpfp)) {
+               tmpfp = claws_fdopen(pfd[0], "rb");
+               while (claws_fgets(buf, sizeof(buf), tmpfp)) {
                        textview_write_line(textview, buf, conv, TRUE);
                        
                        if (textview->stop_loading) {
                        textview_write_line(textview, buf, conv, TRUE);
                        
                        if (textview->stop_loading) {
-                               fclose(tmpfp);
+                               claws_fclose(tmpfp);
                                waitpid(pid, pfd, 0);
                                g_unlink(fname);
                                account_signatures_matchlist_delete();
                                waitpid(pid, pfd, 0);
                                g_unlink(fname);
                                account_signatures_matchlist_delete();
@@ -1169,7 +1170,7 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                        }
                }
 
                        }
                }
 
-               fclose(tmpfp);
+               claws_fclose(tmpfp);
                waitpid(pid, pfd, 0);
                g_unlink(fname);
 #endif
                waitpid(pid, pfd, 0);
                g_unlink(fname);
 #endif
@@ -1191,25 +1192,25 @@ textview_default:
                if (mimeinfo->content == MIMECONTENT_MEM)
                        tmpfp = str_open_as_stream(mimeinfo->data.mem);
                else
                if (mimeinfo->content == MIMECONTENT_MEM)
                        tmpfp = str_open_as_stream(mimeinfo->data.mem);
                else
-                       tmpfp = g_fopen(mimeinfo->data.filename, "rb");
+                       tmpfp = claws_fopen(mimeinfo->data.filename, "rb");
                if (!tmpfp) {
                if (!tmpfp) {
-                       FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
+                       FILE_OP_ERROR(mimeinfo->data.filename, "claws_fopen");
                        account_signatures_matchlist_delete();
                        return;
                }
                if (fseek(tmpfp, mimeinfo->offset, SEEK_SET) < 0) {
                        FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
                        account_signatures_matchlist_delete();
                        return;
                }
                if (fseek(tmpfp, mimeinfo->offset, SEEK_SET) < 0) {
                        FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
-                       fclose(tmpfp);
+                       claws_fclose(tmpfp);
                        account_signatures_matchlist_delete();
                        return;
                }
                debug_print("Viewing text content of type: %s (length: %d)\n", mimeinfo->subtype, mimeinfo->length);
                while (((i = ftell(tmpfp)) < mimeinfo->offset + mimeinfo->length) &&
                        account_signatures_matchlist_delete();
                        return;
                }
                debug_print("Viewing text content of type: %s (length: %d)\n", mimeinfo->subtype, mimeinfo->length);
                while (((i = ftell(tmpfp)) < mimeinfo->offset + mimeinfo->length) &&
-                      (fgets(buf, sizeof(buf), tmpfp) != NULL)
+                      (claws_fgets(buf, sizeof(buf), tmpfp) != NULL)
                       && continue_write) {
                        textview_write_line(textview, buf, conv, TRUE);
                        if (textview->stop_loading) {
                       && continue_write) {
                        textview_write_line(textview, buf, conv, TRUE);
                        if (textview->stop_loading) {
-                               fclose(tmpfp);
+                               claws_fclose(tmpfp);
                                account_signatures_matchlist_delete();
                                return;
                        }
                                account_signatures_matchlist_delete();
                                return;
                        }
@@ -1220,7 +1221,7 @@ textview_default:
                                continue_write = FALSE;
                        }
                }
                                continue_write = FALSE;
                        }
                }
-               fclose(tmpfp);
+               claws_fclose(tmpfp);
        }
 
        account_signatures_matchlist_delete();
        }
 
        account_signatures_matchlist_delete();
@@ -1954,7 +1955,7 @@ static GPtrArray *textview_scan_header(TextView *textview, FILE *fp)
        }
 
        if (!prefs_common.display_header) {
        }
 
        if (!prefs_common.display_header) {
-               while (fgets(buf, sizeof(buf), fp) != NULL)
+               while (claws_fgets(buf, sizeof(buf), fp) != NULL)
                        if (buf[0] == '\r' || buf[0] == '\n') break;
                return NULL;
        }
                        if (buf[0] == '\r' || buf[0] == '\n') break;
                return NULL;
        }
index 514ab4ffbc615a97a28cc103536a0169d9698b44..deb083d5a344cfbf49bbd50e117a47e2e503cb68 100644 (file)
  * RFC2426 for more information.
  */
 
  * RFC2426 for more information.
  */
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
+
 #include <glib.h>
 #include <sys/stat.h>
 #include <string.h>
 #include <glib.h>
 #include <sys/stat.h>
 #include <string.h>
@@ -35,6 +40,7 @@
 #include "utils.h"
 #include "codeconv.h"
 #include "quoted-printable.h"
 #include "utils.h"
 #include "codeconv.h"
 #include "quoted-printable.h"
+#include "claws_io.h"
 
 #define GNOMECARD_DIR     ".gnome"
 #define GNOMECARD_FILE    "GnomeCard"
 
 #define GNOMECARD_DIR     ".gnome"
 #define GNOMECARD_FILE    "GnomeCard"
@@ -136,7 +142,7 @@ void vcard_free( VCardFile *cardFile ) {
        cm_return_if_fail( cardFile != NULL );
 
        /* Close file */
        cm_return_if_fail( cardFile != NULL );
 
        /* Close file */
-       if( cardFile->file ) fclose( cardFile->file );
+       if( cardFile->file ) claws_fclose( cardFile->file );
 
        /* Clear cache */
        addrcache_clear( cardFile->addressCache );
 
        /* Clear cache */
        addrcache_clear( cardFile->addressCache );
@@ -168,7 +174,7 @@ static gint vcard_open_file( VCardFile* cardFile ) {
        /* g_print( "Opening file\n" ); */
        cardFile->addressCache->dataRead = FALSE;
        if( cardFile->path ) {
        /* g_print( "Opening file\n" ); */
        cardFile->addressCache->dataRead = FALSE;
        if( cardFile->path ) {
-               cardFile->file = g_fopen( cardFile->path, "rb" );
+               cardFile->file = claws_fopen( cardFile->path, "rb" );
                if( ! cardFile->file ) {
                        /* g_printerr( "can't open %s\n", cardFile->path ); */
                        cardFile->retVal = MGU_OPEN_FILE;
                if( ! cardFile->file ) {
                        /* g_printerr( "can't open %s\n", cardFile->path ); */
                        cardFile->retVal = MGU_OPEN_FILE;
@@ -193,7 +199,7 @@ static gint vcard_open_file( VCardFile* cardFile ) {
 */
 static void vcard_close_file( VCardFile *cardFile ) {
        cm_return_if_fail( cardFile != NULL );
 */
 static void vcard_close_file( VCardFile *cardFile ) {
        cm_return_if_fail( cardFile != NULL );
-       if( cardFile->file ) fclose( cardFile->file );
+       if( cardFile->file ) claws_fclose( cardFile->file );
        cardFile->file = NULL;
 }
 
        cardFile->file = NULL;
 }
 
@@ -203,7 +209,7 @@ static void vcard_close_file( VCardFile *cardFile ) {
 */
 static gchar *vcard_read_line( VCardFile *cardFile ) {
        while( *cardFile->bufptr == '\n' || *cardFile->bufptr == '\0' ) {
 */
 static gchar *vcard_read_line( VCardFile *cardFile ) {
        while( *cardFile->bufptr == '\n' || *cardFile->bufptr == '\0' ) {
-               if( fgets( cardFile->buffer, VCARDBUFSIZE, cardFile->file ) == NULL )
+               if( claws_fgets( cardFile->buffer, VCARDBUFSIZE, cardFile->file ) == NULL )
                        return NULL;
                g_strstrip( cardFile->buffer );
                cardFile->bufptr = cardFile->buffer;
                        return NULL;
                g_strstrip( cardFile->buffer );
                cardFile->bufptr = cardFile->buffer;
@@ -584,16 +590,16 @@ gchar *vcard_find_gnomecard( void ) {
        strncat( str, GNOMECARD_FILE, WORK_BUFLEN - strlen(str) );
 
        fileSpec = NULL;
        strncat( str, GNOMECARD_FILE, WORK_BUFLEN - strlen(str) );
 
        fileSpec = NULL;
-       if( ( fp = g_fopen( str, "rb" ) ) != NULL ) {
+       if( ( fp = claws_fopen( str, "rb" ) ) != NULL ) {
                /* Read configuration file */
                lenlbl = strlen( GNOMECARD_SECTION );
                /* Read configuration file */
                lenlbl = strlen( GNOMECARD_SECTION );
-               while( fgets( buf, sizeof( buf ), fp ) != NULL ) {
+               while( claws_fgets( buf, sizeof( buf ), fp ) != NULL ) {
                        if( 0 == g_ascii_strncasecmp( buf, GNOMECARD_SECTION, lenlbl ) ) {
                                break;
                        }
                }
 
                        if( 0 == g_ascii_strncasecmp( buf, GNOMECARD_SECTION, lenlbl ) ) {
                                break;
                        }
                }
 
-               while( fgets( buf, sizeof( buf ), fp ) != NULL ) {
+               while( claws_fgets( buf, sizeof( buf ), fp ) != NULL ) {
                        g_strchomp( buf );
                        if( buf[0] == '[' ) break;
                        for( i = 0; i < lenlbl; i++ ) {
                        g_strchomp( buf );
                        if( buf[0] == '[' ) break;
                        for( i = 0; i < lenlbl; i++ ) {
@@ -605,7 +611,7 @@ gchar *vcard_find_gnomecard( void ) {
                                }
                        }
                }
                                }
                        }
                }
-               fclose( fp );
+               claws_fclose( fp );
        }
 
        if( fileSpec == NULL ) {
        }
 
        if( fileSpec == NULL ) {