diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-08-08 07:07:19 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-08-08 07:07:19 +0000 |
commit | e5c03181ba3cd06f27e10677960575e44e7900a6 (patch) | |
tree | cfa341f7b9c46b2c7b692e11def79e72622152ab | |
parent | 38ad5762fb87ec8278108d4a8d06e32612e64a13 (diff) |
added wrappers for C library function that take pathname arguments.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@478 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | ChangeLog.ja | 13 | ||||
-rw-r--r-- | src/account.c | 4 | ||||
-rw-r--r-- | src/addrbook.c | 5 | ||||
-rw-r--r-- | src/addrcache.c | 5 | ||||
-rw-r--r-- | src/addrindex.c | 3 | ||||
-rw-r--r-- | src/codeconv.c | 6 | ||||
-rw-r--r-- | src/compose.c | 84 | ||||
-rw-r--r-- | src/imap.c | 10 | ||||
-rw-r--r-- | src/inc.c | 2 | ||||
-rw-r--r-- | src/jpilot.c | 12 | ||||
-rw-r--r-- | src/ldif.c | 3 | ||||
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/mbox.c | 24 | ||||
-rw-r--r-- | src/mh.c | 12 | ||||
-rw-r--r-- | src/mimeview.c | 8 | ||||
-rw-r--r-- | src/news.c | 6 | ||||
-rw-r--r-- | src/pop.c | 16 | ||||
-rw-r--r-- | src/prefs.c | 15 | ||||
-rw-r--r-- | src/prefs_actions.c | 2 | ||||
-rw-r--r-- | src/prefs_common.c | 4 | ||||
-rw-r--r-- | src/prefs_customheader.c | 4 | ||||
-rw-r--r-- | src/prefs_display_header.c | 2 | ||||
-rw-r--r-- | src/prefs_filter.c | 2 | ||||
-rw-r--r-- | src/procheader.c | 6 | ||||
-rw-r--r-- | src/procmime.c | 12 | ||||
-rw-r--r-- | src/procmsg.c | 12 | ||||
-rw-r--r-- | src/recv.c | 12 | ||||
-rw-r--r-- | src/rfc2015.c | 24 | ||||
-rw-r--r-- | src/send_message.c | 8 | ||||
-rw-r--r-- | src/sourcewindow.c | 2 | ||||
-rw-r--r-- | src/template.c | 6 | ||||
-rw-r--r-- | src/textview.c | 2 | ||||
-rw-r--r-- | src/utils.c | 210 | ||||
-rw-r--r-- | src/utils.h | 32 | ||||
-rw-r--r-- | src/vcard.c | 4 | ||||
-rw-r--r-- | src/xml.c | 2 |
37 files changed, 363 insertions, 221 deletions
@@ -1,3 +1,9 @@ +2005-08-08 + + * src/utils.[ch]: added wrappers for C library function that take + pathname arguments. + * src/*.c: use wrapper functions. + 2005-08-07 * src/defs.h: modification for Win32. diff --git a/ChangeLog.ja b/ChangeLog.ja index 8edc3eeb..10d969e0 100644 --- a/ChangeLog.ja +++ b/ChangeLog.ja @@ -1,8 +1,15 @@ +2005-08-08 + + * src/utils.[ch]: 引数にパス名をとる C ライブラリ関数のラッパーを + 追加。 + * src/*.c: ラッパー関数を使用。 + 2005-08-07 - * src/defs.h: modification for Win32. - * src/main.c: check filename encoding only on Unix. - * src/prefs_common.c: modification for Win32. + * src/defs.h: Win32 向けの修正。 + * src/main.c: Unix 上でのみファイル名エンコーディングをチェックする + ようにした。 + * src/prefs_common.c: Win32 向けの修正。 2005-08-07 diff --git a/src/account.c b/src/account.c index 82348f8c..ce2f2689 100644 --- a/src/account.c +++ b/src/account.c @@ -137,7 +137,7 @@ void account_read_config_all(void) debug_print(_("Reading all config for each account...\n")); rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL); - if ((fp = fopen(rcpath, "rb")) == NULL) { + if ((fp = g_fopen(rcpath, "rb")) == NULL) { if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen"); g_free(rcpath); return; @@ -290,7 +290,7 @@ PrefsAccount *account_find_from_message_file(const gchar *file) g_return_val_if_fail(file != NULL, NULL); - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return NULL; } diff --git a/src/addrbook.c b/src/addrbook.c index b11a6504..62995580 100644 --- a/src/addrbook.c +++ b/src/addrbook.c @@ -34,6 +34,7 @@ #include "addritem.h" #include "addrcache.h" #include "addrbook.h" +#include "utils.h" #ifndef DEV_STANDALONE #include "prefs.h" @@ -1071,7 +1072,7 @@ gint addrbook_write_to( AddressBookFile *book, gchar *newFile ) { book->retVal = MGU_OPEN_FILE; #ifdef DEV_STANDALONE - fp = fopen( fileSpec, "wb" ); + fp = g_fopen( fileSpec, "wb" ); g_free( fileSpec ); if( fp ) { fputs( "<?xml version=\"1.0\" ?>\n", fp ); @@ -1672,7 +1673,7 @@ GList *addrbook_get_bookfile_list( AddressBookFile *book ) { strcpy( buf, adbookdir ); strcat( buf, entry->d_name ); - stat( buf, &statbuf ); + g_stat( buf, &statbuf ); if( S_IFREG & statbuf.st_mode ) { if( strncmp( entry->d_name, ADDRBOOK_PREFIX, lenpre ) == 0 ) { if( strncmp( (entry->d_name) + lennum, ADDRBOOK_SUFFIX, lensuf ) == 0 ) { diff --git a/src/addrcache.c b/src/addrcache.c index 28a65d58..9f538e0c 100644 --- a/src/addrcache.c +++ b/src/addrcache.c @@ -29,6 +29,7 @@ /* #include "mgutils.h" */ #include "addritem.h" #include "addrcache.h" +#include "utils.h" #define ID_TIME_OFFSET 998000000 #define ADDRCACHE_MAX_SEARCH_COUNT 1000 @@ -194,7 +195,7 @@ gboolean addrcache_check_file( AddressCache *cache, gchar *path ) { struct stat filestat; retVal = TRUE; if( path ) { - if( 0 == stat( path, &filestat ) ) { + if( 0 == g_stat( path, &filestat ) ) { if( filestat.st_mtime == cache->modifyTime ) retVal = FALSE; } } @@ -209,7 +210,7 @@ gboolean addrcache_mark_file( AddressCache *cache, gchar *path ) { gboolean retVal = FALSE; struct stat filestat; if( path ) { - if( 0 == stat( path, &filestat ) ) { + if( 0 == g_stat( path, &filestat ) ) { cache->modifyTime = filestat.st_mtime; retVal = TRUE; } diff --git a/src/addrindex.c b/src/addrindex.c index 64f6a4aa..62f1061d 100644 --- a/src/addrindex.c +++ b/src/addrindex.c @@ -37,6 +37,7 @@ #include "addrbook.h" #include "addrindex.h" #include "xml.h" +#include "utils.h" #ifndef DEV_STANDALONE #include "prefs.h" @@ -1105,7 +1106,7 @@ gint addrindex_write_to( AddressIndex *addrIndex, const gchar *newFile ) { fileSpec = g_strconcat( addrIndex->filePath, G_DIR_SEPARATOR_S, newFile, NULL ); addrIndex->retVal = MGU_OPEN_FILE; #ifdef DEV_STANDALONE - fp = fopen( fileSpec, "wb" ); + fp = g_fopen( fileSpec, "wb" ); g_free( fileSpec ); if( fp ) { fputs( "<?xml version=\"1.0\" ?>\n", fp ); diff --git a/src/codeconv.c b/src/codeconv.c index 470b5e13..b2d3e2b6 100644 --- a/src/codeconv.c +++ b/src/codeconv.c @@ -1868,11 +1868,11 @@ gint conv_copy_file(const gchar *src, const gchar *dest, const gchar *encoding) CodeConverter *conv; gboolean err = FALSE; - if ((src_fp = fopen(src, "rb")) == NULL) { + if ((src_fp = g_fopen(src, "rb")) == NULL) { FILE_OP_ERROR(src, "fopen"); return -1; } - if ((dest_fp = fopen(dest, "wb")) == NULL) { + if ((dest_fp = g_fopen(dest, "wb")) == NULL) { FILE_OP_ERROR(dest, "fopen"); fclose(src_fp); return -1; @@ -1908,7 +1908,7 @@ gint conv_copy_file(const gchar *src, const gchar *dest, const gchar *encoding) err = TRUE; } if (err) { - unlink(dest); + g_unlink(dest); return -1; } diff --git a/src/compose.c b/src/compose.c index 0b971857..aecdb455 100644 --- a/src/compose.c +++ b/src/compose.c @@ -1738,7 +1738,7 @@ static void compose_insert_file(Compose *compose, const gchar *file, g_return_if_fail(file != NULL); - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return; } @@ -1809,7 +1809,7 @@ static void compose_attach_append(Compose *compose, const gchar *file, alertpanel_notice(_("File %s is empty."), file); return; } - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { alertpanel_error(_("Can't read %s."), file); return; } @@ -2536,7 +2536,7 @@ static gint compose_send(Compose *compose) if (!compose->to_list && !compose->newsgroup_list) { g_warning(_("can't get recipient list.")); - unlink(tmp); + g_unlink(tmp); lock = FALSE; return -1; } @@ -2557,7 +2557,7 @@ static gint compose_send(Compose *compose) if (!ac || ac->protocol == A_NNTP) { alertpanel_error(_("Account for sending mail is not specified.\n" "Please select a mail account before sending.")); - unlink(tmp); + g_unlink(tmp); lock = FALSE; return -1; } @@ -2571,7 +2571,7 @@ static gint compose_send(Compose *compose) if (ok < 0) { alertpanel_error(_("Error occurred while posting the message to %s ."), compose->account->nntp_server); - unlink(tmp); + g_unlink(tmp); lock = FALSE; return -1; } @@ -2612,7 +2612,7 @@ static gint compose_send(Compose *compose) } } - unlink(tmp); + g_unlink(tmp); lock = FALSE; return ok; } @@ -2665,14 +2665,14 @@ static gint compose_clearsign_text(Compose *compose, gchar **text) if (compose_create_signers_list(compose, &key_list) < 0 || rfc2015_clearsign(tmp_file, key_list) < 0) { - unlink(tmp_file); + g_unlink(tmp_file); g_free(tmp_file); return -1; } g_free(*text); *text = file_read_to_str(tmp_file); - unlink(tmp_file); + g_unlink(tmp_file); g_free(tmp_file); if (*text == NULL) return -1; @@ -2698,7 +2698,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, EncodingType encoding; gint line; - if ((fp = fopen(file, "wb")) == NULL) { + if ((fp = g_fopen(file, "wb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return -1; } @@ -2752,7 +2752,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, if (aval != G_ALERTDEFAULT) { g_free(chars); fclose(fp); - unlink(file); + g_unlink(file); return -1; } else { buf = chars; @@ -2794,7 +2794,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, if (compose_clearsign_text(compose, &buf) < 0) { g_warning("clearsign failed\n"); fclose(fp); - unlink(file); + g_unlink(file); g_free(buf); return -1; } @@ -2824,7 +2824,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, if (aval != G_ALERTDEFAULT) { g_free(msg); fclose(fp); - unlink(file); + g_unlink(file); g_free(buf); return -1; } @@ -2835,7 +2835,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, body_charset, encoding, is_draft) < 0) { g_warning("can't write headers\n"); fclose(fp); - unlink(file); + g_unlink(file); g_free(buf); return -1; } @@ -2884,7 +2884,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, if (fwrite(outbuf, sizeof(gchar), outlen, fp) != outlen) { FILE_OP_ERROR(file, "fwrite"); fclose(fp); - unlink(file); + g_unlink(file); g_free(outbuf); g_free(buf); return -1; @@ -2893,7 +2893,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, } else if (fwrite(buf, sizeof(gchar), len, fp) != len) { FILE_OP_ERROR(file, "fwrite"); fclose(fp); - unlink(file); + g_unlink(file); g_free(buf); return -1; } @@ -2905,7 +2905,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, if (fclose(fp) == EOF) { FILE_OP_ERROR(file, "fclose"); - unlink(file); + g_unlink(file); return -1; } @@ -2918,7 +2918,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, if ((compose->use_signing && !compose->account->clearsign) || compose->use_encryption) { if (canonicalize_file_replace(file) < 0) { - unlink(file); + g_unlink(file); return -1; } } @@ -2928,14 +2928,14 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, if (compose_create_signers_list(compose, &key_list) < 0 || rfc2015_sign(file, key_list) < 0) { - unlink(file); + g_unlink(file); return -1; } } if (compose->use_encryption) { if (rfc2015_encrypt(file, compose->to_list, compose->account->ascii_armored) < 0) { - unlink(file); + g_unlink(file); return -1; } } @@ -2954,7 +2954,7 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file) size_t len; gchar *chars, *tmp; - if ((fp = fopen(file, "wb")) == NULL) { + if ((fp = g_fopen(file, "wb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return -1; } @@ -2977,7 +2977,7 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file) if (!chars) { fclose(fp); - unlink(file); + g_unlink(file); return -1; } @@ -2987,7 +2987,7 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file) FILE_OP_ERROR(file, "fwrite"); g_free(chars); fclose(fp); - unlink(file); + g_unlink(file); return -1; } @@ -2995,7 +2995,7 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file) if (fclose(fp) == EOF) { FILE_OP_ERROR(file, "fclose"); - unlink(file); + g_unlink(file); return -1; } return 0; @@ -3017,7 +3017,7 @@ static gint compose_redirect_write_to_file(Compose *compose, const gchar *file) if ((fp = procmsg_open_message(compose->targetinfo)) == NULL) return -1; - if ((fdest = fopen(file, "wb")) == NULL) { + if ((fdest = g_fopen(file, "wb")) == NULL) { FILE_OP_ERROR(file, "fopen"); fclose(fp); return -1; @@ -3077,7 +3077,7 @@ static gint compose_redirect_write_to_file(Compose *compose, const gchar *file) fclose(fp); if (fclose(fdest) == EOF) { FILE_OP_ERROR(file, "fclose"); - unlink(file); + g_unlink(file); return -1; } @@ -3085,7 +3085,7 @@ static gint compose_redirect_write_to_file(Compose *compose, const gchar *file) error: fclose(fp); fclose(fdest); - unlink(file); + g_unlink(file); return -1; } @@ -3131,15 +3131,15 @@ static gint compose_queue(Compose *compose, const gchar *file) tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(), G_DIR_SEPARATOR, compose); - if ((fp = fopen(tmp, "wb")) == NULL) { + if ((fp = g_fopen(tmp, "wb")) == NULL) { FILE_OP_ERROR(tmp, "fopen"); g_free(tmp); return -1; } - if ((src_fp = fopen(file, "rb")) == NULL) { + if ((src_fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); fclose(fp); - unlink(tmp); + g_unlink(tmp); g_free(tmp); return -1; } @@ -3189,7 +3189,7 @@ static gint compose_queue(Compose *compose, const gchar *file) FILE_OP_ERROR(tmp, "fputs"); fclose(fp); fclose(src_fp); - unlink(tmp); + g_unlink(tmp); g_free(tmp); return -1; } @@ -3198,7 +3198,7 @@ static gint compose_queue(Compose *compose, const gchar *file) fclose(src_fp); if (fclose(fp) == EOF) { FILE_OP_ERROR(tmp, "fclose"); - unlink(tmp); + g_unlink(tmp); g_free(tmp); return -1; } @@ -3206,14 +3206,14 @@ static gint compose_queue(Compose *compose, const gchar *file) queue = account_get_special_folder(compose->account, F_QUEUE); if (!queue) { g_warning(_("can't find queue folder\n")); - unlink(tmp); + g_unlink(tmp); g_free(tmp); return -1; } folder_item_scan(queue); if ((num = folder_item_add_msg(queue, tmp, &flag, TRUE)) < 0) { g_warning(_("can't queue the message\n")); - unlink(tmp); + g_unlink(tmp); g_free(tmp); return -1; } @@ -3249,7 +3249,7 @@ static void compose_write_attach(Compose *compose, FILE *fp, valid = gtk_tree_model_iter_next(model, &iter)) { gtk_tree_model_get(model, &iter, COL_ATTACH_INFO, &ainfo, -1); - if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) { + if ((attach_fp = g_fopen(ainfo->file, "rb")) == NULL) { g_warning("Can't open file %s\n", ainfo->file); continue; } @@ -3302,9 +3302,9 @@ static void compose_write_attach(Compose *compose, FILE *fp, fclose(attach_fp); continue; } - if ((tmp_fp = fopen(tmp_file, "rb")) == NULL) { + if ((tmp_fp = g_fopen(tmp_file, "rb")) == NULL) { FILE_OP_ERROR(tmp_file, "fopen"); - unlink(tmp_file); + g_unlink(tmp_file); g_free(tmp_file); fclose(attach_fp); continue; @@ -3327,7 +3327,7 @@ static void compose_write_attach(Compose *compose, FILE *fp, if (tmp_file) { fclose(tmp_fp); - unlink(tmp_file); + g_unlink(tmp_file); g_free(tmp_file); } } else if (encoding == ENC_QUOTED_PRINTABLE) { @@ -5278,11 +5278,11 @@ static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition, compose_changed_cb(NULL, compose); - if (unlink(compose->exteditor_file) < 0) + if (g_unlink(compose->exteditor_file) < 0) FILE_OP_ERROR(compose->exteditor_file, "unlink"); } else if (buf[0] == '1') { /* failed */ g_warning(_("Couldn't exec external editor\n")); - if (unlink(compose->exteditor_file) < 0) + if (g_unlink(compose->exteditor_file) < 0) FILE_OP_ERROR(compose->exteditor_file, "unlink"); } else if (buf[0] == '2') { g_warning(_("Couldn't write to file\n")); @@ -5611,7 +5611,7 @@ static void compose_send_later_cb(gpointer data, guint action, return; } - if (unlink(tmp) < 0) + if (g_unlink(tmp) < 0) FILE_OP_ERROR(tmp, "unlink"); compose_destroy(compose); @@ -5644,7 +5644,7 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget) folder_item_scan(draft); if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) { - unlink(tmp); + g_unlink(tmp); g_free(tmp); lock = FALSE; return; @@ -5674,7 +5674,7 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget) path = folder_item_fetch_msg(draft, msgnum); g_return_if_fail(path != NULL); - if (stat(path, &s) < 0) { + if (g_stat(path, &s) < 0) { FILE_OP_ERROR(path, "stat"); g_free(path); lock = FALSE; @@ -1222,7 +1222,7 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list, if (remove_source) { for (cur = file_list; cur != NULL; cur = cur->next) { fileinfo = (MsgFileInfo *)cur->data; - if (unlink(fileinfo->file) < 0) + if (g_unlink(fileinfo->file) < 0) FILE_OP_ERROR(fileinfo->file, "unlink"); } } @@ -2149,7 +2149,7 @@ static gint imap_rename_folder_real(Folder *folder, FolderItem *item, if (is_dir_exist(old_cache_dir)) { new_cache_dir = folder_item_get_path(item); - if (rename(old_cache_dir, new_cache_dir) < 0) { + if (g_rename(old_cache_dir, new_cache_dir) < 0) { FILE_OP_ERROR(old_cache_dir, "rename"); } g_free(new_cache_dir); @@ -2320,7 +2320,7 @@ static void imap_delete_cached_message(FolderItem *item, guint32 uid) debug_print("Deleting cached message: %s\n", file); - unlink(file); + g_unlink(file); g_free(file); g_free(dir); @@ -2464,7 +2464,7 @@ static GList *imap_parse_namespace_str(gchar *str) static void imap_parse_namespace(IMAPSession *session, IMAPFolder *folder) { - gchar *ns_str; + gchar *ns_str = NULL; gchar **str_array; g_return_if_fail(session != NULL); @@ -3507,7 +3507,7 @@ static gint imap_cmd_append(IMAPSession *session, const gchar *destfolder, g_return_val_if_fail(file != NULL, IMAP_ERROR); size = get_file_size_as_crlf(file); - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return -1; } @@ -1269,7 +1269,7 @@ static gint get_spool(FolderItem *dest, const gchar *mbox) folder_table = g_hash_table_new(NULL, NULL); msgs = proc_mbox(dest, tmp_mbox, folder_table); - unlink(tmp_mbox); + g_unlink(tmp_mbox); if (msgs >= 0) empty_mbox(mbox); unlock_mbox(mbox, lockfd, LOCK_FLOCK); diff --git a/src/jpilot.c b/src/jpilot.c index 7e5caa49..4624e141 100644 --- a/src/jpilot.c +++ b/src/jpilot.c @@ -339,7 +339,7 @@ static gboolean jpilot_mark_files( JPilotFile *pilotFile ) { pilotFile->pc3ModifyTime = 0; pcFile = jpilot_get_pc3_file( pilotFile ); if( pcFile == NULL ) return retVal; - if( 0 == lstat( pcFile, &filestat ) ) { + if( 0 == g_lstat( pcFile, &filestat ) ) { pilotFile->havePC3 = TRUE; pilotFile->pc3ModifyTime = filestat.st_mtime; retVal = TRUE; @@ -367,7 +367,7 @@ static gboolean jpilot_check_files( JPilotFile *pilotFile ) { pcFile = jpilot_get_pc3_file( pilotFile ); if( pcFile == NULL ) return FALSE; - if( 0 == lstat( pcFile, &filestat ) ) { + if( 0 == g_lstat( pcFile, &filestat ) ) { if( filestat.st_mtime == pilotFile->pc3ModifyTime ) retVal = FALSE; } g_free( pcFile ); @@ -644,7 +644,7 @@ static gint jpilot_get_file_info( JPilotFile *pilotFile, unsigned char **buf, in *buf_size=0; if( pilotFile->path ) { - in = fopen( pilotFile->path, "rb" ); + in = g_fopen( pilotFile->path, "rb" ); if( !in ) { return MGU_OPEN_FILE; } @@ -826,7 +826,7 @@ static gint jpilot_read_db_files( JPilotFile *pilotFile, GList **records ) { return MGU_BAD_ARGS; } - in = fopen( pilotFile->path, "rb" ); + in = g_fopen( pilotFile->path, "rb" ); if (!in) { return MGU_OPEN_FILE; } @@ -943,7 +943,7 @@ static gint jpilot_read_db_files( JPilotFile *pilotFile, GList **records ) { /* Read the PC3 file, if present */ pcFile = jpilot_get_pc3_file( pilotFile ); if( pcFile == NULL ) return MGU_SUCCESS; - pc_in = fopen( pcFile, "rb"); + pc_in = g_fopen( pcFile, "rb"); g_free( pcFile ); if( pc_in == NULL ) { @@ -1641,7 +1641,7 @@ gchar *jpilot_find_pilotdb( void ) { strcat( str, JPILOT_DBHOME_FILE ); /* Attempt to open */ - if( ( fp = fopen( str, "rb" ) ) != NULL ) { + if( ( fp = g_fopen( str, "rb" ) ) != NULL ) { fclose( fp ); } else { @@ -32,6 +32,7 @@ #include "addrcache.h" #include "base64.h" +#include "utils.h" /* * Create new object. @@ -192,7 +193,7 @@ void ldif_print_file( LdifFile *ldifFile, FILE *stream ) { static gint ldif_open_file( LdifFile* ldifFile ) { /* printf( "Opening file\n" ); */ if( ldifFile->path ) { - ldifFile->file = fopen( ldifFile->path, "rb" ); + ldifFile->file = g_fopen( ldifFile->path, "rb" ); if( ! ldifFile->file ) { /* printf( "can't open %s\n", ldifFile->path ); */ ldifFile->retVal = MGU_OPEN_FILE; @@ -592,7 +592,7 @@ static gint prohibit_duplicate_launch(void) path = get_socket_name(); uxsock = fd_connect_unix(path); if (uxsock < 0) { - unlink(path); + g_unlink(path); return fd_open_unix(path); } @@ -678,7 +678,7 @@ static gint lock_socket_remove(void) gdk_input_remove(lock_socket_tag); fd_close(lock_socket); filename = get_socket_name(); - unlink(filename); + g_unlink(filename); #endif return 0; @@ -50,7 +50,7 @@ g_warning(_("can't write to temporary file\n")); \ fclose(tmp_fp); \ fclose(mbox_fp); \ - unlink(tmp_file); \ + g_unlink(tmp_file); \ g_free(tmp_file); \ return -1; \ } \ @@ -68,7 +68,7 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, GHashTable *folder_table) debug_print(_("Getting messages from %s into %s...\n"), mbox, dest->path); - if ((mbox_fp = fopen(mbox, "rb")) == NULL) { + if ((mbox_fp = g_fopen(mbox, "rb")) == NULL) { FILE_OP_ERROR(mbox, "fopen"); return -1; } @@ -105,7 +105,7 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, GHashTable *folder_table) gboolean is_next_msg = FALSE; FilterInfo *fltinfo; - if ((tmp_fp = fopen(tmp_file, "wb")) == NULL) { + if ((tmp_fp = g_fopen(tmp_file, "wb")) == NULL) { FILE_OP_ERROR(tmp_file, "fopen"); g_warning(_("can't open temporary file\n")); g_free(tmp_file); @@ -194,7 +194,7 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, GHashTable *folder_table) if (fclose(tmp_fp) == EOF) { FILE_OP_ERROR(tmp_file, "fclose"); g_warning(_("can't write to temporary file\n")); - unlink(tmp_file); + g_unlink(tmp_file); g_free(tmp_file); fclose(mbox_fp); return -1; @@ -212,7 +212,7 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, GHashTable *folder_table) if (folder_item_add_msg(dest, tmp_file, &fltinfo->flags, FALSE) < 0) { filter_info_free(fltinfo); - unlink(tmp_file); + g_unlink(tmp_file); g_free(tmp_file); fclose(mbox_fp); return -1; @@ -243,7 +243,7 @@ gint proc_mbox(FolderItem *dest, const gchar *mbox, GHashTable *folder_table) } filter_info_free(fltinfo); - unlink(tmp_file); + g_unlink(tmp_file); msgs++; } while (from_line[0] != '\0'); @@ -266,7 +266,7 @@ gint lock_mbox(const gchar *base, LockType type) FILE *lockfp; lockfile = g_strdup_printf("%s.%d", base, getpid()); - if ((lockfp = fopen(lockfile, "wb")) == NULL) { + if ((lockfp = g_fopen(lockfile, "wb")) == NULL) { FILE_OP_ERROR(lockfile, "fopen"); g_warning(_("can't create lock file %s\n"), lockfile); g_warning(_("use 'flock' instead of 'file' if possible.\n")); @@ -282,7 +282,7 @@ gint lock_mbox(const gchar *base, LockType type) FILE_OP_ERROR(lockfile, "link"); if (retry >= 5) { g_warning(_("can't create %s\n"), lockfile); - unlink(lockfile); + g_unlink(lockfile); g_free(lockfile); return -1; } @@ -292,7 +292,7 @@ gint lock_mbox(const gchar *base, LockType type) retry++; sleep(5); } - unlink(lockfile); + g_unlink(lockfile); g_free(lockfile); } else if (type == LOCK_FLOCK) { gint lockfd; @@ -339,7 +339,7 @@ gint unlock_mbox(const gchar *base, gint fd, LockType type) gchar *lockfile; lockfile = g_strconcat(base, ".lock", NULL); - if (unlink(lockfile) < 0) { + if (g_unlink(lockfile) < 0) { FILE_OP_ERROR(lockfile, "unlink"); g_free(lockfile); return -1; @@ -392,7 +392,7 @@ void empty_mbox(const gchar *mbox) #if HAVE_TRUNCATE FILE_OP_ERROR(mbox, "truncate"); #endif - if ((fp = fopen(mbox, "wb")) == NULL) { + if ((fp = g_fopen(mbox, "wb")) == NULL) { FILE_OP_ERROR(mbox, "fopen"); g_warning(_("can't truncate mailbox to zero.\n")); return; @@ -420,7 +420,7 @@ gint export_to_mbox(FolderItem *src, const gchar *mbox) debug_print(_("Exporting messages from %s into %s...\n"), src->path, mbox); - if ((mbox_fp = fopen(mbox, "wb")) == NULL) { + if ((mbox_fp = g_fopen(mbox, "wb")) == NULL) { FILE_OP_ERROR(mbox, "fopen"); return -1; } @@ -455,7 +455,7 @@ static gint mh_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list, if (remove_source) { for (cur = file_list; cur != NULL; cur = cur->next) { fileinfo = (MsgFileInfo *)cur->data; - if (unlink(fileinfo->file) < 0) + if (g_unlink(fileinfo->file) < 0) FILE_OP_ERROR(fileinfo->file, "unlink"); } } @@ -659,7 +659,7 @@ static gint mh_remove_msg(Folder *folder, FolderItem *item, MsgInfo *msginfo) file = mh_fetch_msg(folder, item, msginfo->msgnum); g_return_val_if_fail(file != NULL, -1); - if (unlink(file) < 0) { + if (g_unlink(file) < 0) { FILE_OP_ERROR(file, "unlink"); g_free(file); return -1; @@ -705,7 +705,7 @@ static gboolean mh_is_msg_changed(Folder *folder, FolderItem *item, { struct stat s; - if (stat(itos(msginfo->msgnum), &s) < 0 || + if (g_stat(itos(msginfo->msgnum), &s) < 0 || msginfo->size != s.st_size || msginfo->mtime != s.st_mtime) return TRUE; @@ -955,7 +955,7 @@ static gint mh_move_folder_real(Folder *folder, FolderItem *item, debug_print("mh_move_folder: rename(%s, %s)\n", oldpath, newpath); - if (rename(oldpath, newpath) < 0) { + if (g_rename(oldpath, newpath) < 0) { FILE_OP_ERROR(oldpath, "rename"); g_free(oldpath); g_free(newpath); @@ -1043,7 +1043,7 @@ static time_t mh_get_mtime(FolderItem *item) struct stat s; path = folder_item_get_path(item); - if (stat(path, &s) < 0) { + if (g_stat(path, &s) < 0) { FILE_OP_ERROR(path, "stat"); return -1; } else { @@ -1280,7 +1280,7 @@ static void mh_scan_tree_recursive(FolderItem *item) d->d_type == DT_DIR || (d->d_type == DT_UNKNOWN && #endif - stat(entry, &s) == 0 && S_ISDIR(s.st_mode) + g_stat(entry, &s) == 0 && S_ISDIR(s.st_mode) #ifdef HAVE_DIRENT_D_TYPE ) #endif diff --git a/src/mimeview.c b/src/mimeview.c index 22232448..251ec9e2 100644 --- a/src/mimeview.c +++ b/src/mimeview.c @@ -324,7 +324,7 @@ void mimeview_show_message(MimeView *mimeview, MimeInfo *mimeinfo, if (prefs_common.auto_check_signatures) { FILE *fp; - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return; } @@ -530,7 +530,7 @@ static void mimeview_show_message_part(MimeView *mimeview, MimeInfo *partinfo) #endif /* USE_GPGME */ if (!fname) return; - if ((fp = fopen(fname, "rb")) == NULL) { + if ((fp = g_fopen(fname, "rb")) == NULL) { FILE_OP_ERROR(fname, "fopen"); return; } @@ -562,7 +562,7 @@ static void mimeview_show_image_part(MimeView *mimeview, MimeInfo *partinfo) mimeview_change_view_type(mimeview, MIMEVIEW_IMAGE); imageview_show_image(mimeview->imageview, partinfo, filename, prefs_common.resize_image); - unlink(filename); + g_unlink(filename); } g_free(filename); @@ -1192,7 +1192,7 @@ static void mimeview_check_signature(MimeView *mimeview) while (mimeinfo->parent) mimeinfo = mimeinfo->parent; - if ((fp = fopen(mimeview->file, "rb")) == NULL) { + if ((fp = g_fopen(mimeview->file, "rb")) == NULL) { FILE_OP_ERROR(mimeview->file, "fopen"); return; } @@ -525,7 +525,7 @@ GSList *news_get_group_list(Folder *folder) filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL); g_free(path); - if ((fp = fopen(filename, "rb")) == NULL) { + if ((fp = g_fopen(filename, "rb")) == NULL) { NNTPSession *session; gint ok; @@ -552,7 +552,7 @@ GSList *news_get_group_list(Folder *folder) return NULL; } - if ((fp = fopen(filename, "rb")) == NULL) { + if ((fp = g_fopen(filename, "rb")) == NULL) { FILE_OP_ERROR(filename, "fopen"); g_free(filename); return NULL; @@ -632,7 +632,7 @@ gint news_post(Folder *folder, const gchar *file) g_return_val_if_fail(FOLDER_TYPE(folder) == F_NEWS, -1); g_return_val_if_fail(file != NULL, -1); - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return -1; } @@ -336,7 +336,7 @@ static gint pop3_retr_recv(Pop3Session *session, const gchar *data, guint len) } drop_ok = session->drop_message(session, file); - unlink(file); + g_unlink(file); g_free(file); if (drop_ok < 0) { session->error_val = PS_IOERR; @@ -458,7 +458,7 @@ GHashTable *pop3_get_uidl_table(PrefsAccount *ac_prefs) path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, UIDL_DIR, G_DIR_SEPARATOR_S, ac_prefs->recv_server, "-", ac_prefs->userid, NULL); - if ((fp = fopen(path, "rb")) == NULL) { + if ((fp = g_fopen(path, "rb")) == NULL) { if (ENOENT != errno) FILE_OP_ERROR(path, "fopen"); g_free(path); return table; @@ -499,7 +499,7 @@ gint pop3_write_uidl_list(Pop3Session *session) "uidl", G_DIR_SEPARATOR_S, session->ac_prefs->recv_server, "-", session->ac_prefs->userid, NULL); - if ((fp = fopen(path, "wb")) == NULL) { + if ((fp = g_fopen(path, "wb")) == NULL) { FILE_OP_ERROR(path, "fopen"); g_free(path); return -1; @@ -525,7 +525,7 @@ static gint pop3_write_msg_to_file(const gchar *file, const gchar *data, g_return_val_if_fail(file != NULL, -1); - if ((fp = fopen(file, "wb")) == NULL) { + if ((fp = g_fopen(file, "wb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return -1; } @@ -544,7 +544,7 @@ static gint pop3_write_msg_to_file(const gchar *file, const gchar *data, FILE_OP_ERROR(file, "fwrite"); g_warning("can't write to file: %s\n", file); fclose(fp); - unlink(file); + g_unlink(file); return -1; } @@ -570,7 +570,7 @@ static gint pop3_write_msg_to_file(const gchar *file, const gchar *data, FILE_OP_ERROR(file, "fwrite"); g_warning("can't write to file: %s\n", file); fclose(fp); - unlink(file); + g_unlink(file); return -1; } if (data[len - 1] != '\r' && data[len - 1] != '\n') { @@ -578,14 +578,14 @@ static gint pop3_write_msg_to_file(const gchar *file, const gchar *data, FILE_OP_ERROR(file, "fputc"); g_warning("can't write to file: %s\n", file); fclose(fp); - unlink(file); + g_unlink(file); return -1; } } if (fclose(fp) == EOF) { FILE_OP_ERROR(file, "fclose"); - unlink(file); + g_unlink(file); return -1; } diff --git a/src/prefs.c b/src/prefs.c index 7fb6f666..759a1564 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -56,7 +56,7 @@ void prefs_read_config(PrefParam *param, const gchar *label, prefs_set_default(param); - if ((fp = fopen(rcfile, "rb")) == NULL) { + if ((fp = g_fopen(rcfile, "rb")) == NULL) { if (ENOENT != errno) FILE_OP_ERROR(rcfile, "fopen"); return; } @@ -178,7 +178,7 @@ void prefs_write_config(PrefParam *param, const gchar *label, g_return_if_fail(rcfile != NULL); rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, rcfile, NULL); - if ((orig_fp = fopen(rcpath, "rb")) == NULL) { + if ((orig_fp = g_fopen(rcpath, "rb")) == NULL) { if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen"); } @@ -286,7 +286,7 @@ PrefFile *prefs_file_open(const gchar *path) g_return_val_if_fail(path != NULL, NULL); tmppath = g_strconcat(path, ".tmp", NULL); - if ((fp = fopen(tmppath, "wb")) == NULL) { + if ((fp = g_fopen(tmppath, "wb")) == NULL) { FILE_OP_ERROR(tmppath, "fopen"); g_free(tmppath); return NULL; @@ -320,7 +320,7 @@ gint prefs_file_close(PrefFile *pfile) tmppath = g_strconcat(path, ".tmp", NULL); if (fclose(fp) == EOF) { FILE_OP_ERROR(tmppath, "fclose"); - unlink(tmppath); + g_unlink(tmppath); g_free(path); g_free(tmppath); return -1; @@ -330,7 +330,7 @@ gint prefs_file_close(PrefFile *pfile) bakpath = g_strconcat(path, ".bak", NULL); if (rename_force(path, bakpath) < 0) { FILE_OP_ERROR(path, "rename"); - unlink(tmppath); + g_unlink(tmppath); g_free(path); g_free(tmppath); g_free(bakpath); @@ -340,7 +340,7 @@ gint prefs_file_close(PrefFile *pfile) if (rename_force(tmppath, path) < 0) { FILE_OP_ERROR(tmppath, "rename"); - unlink(tmppath); + g_unlink(tmppath); g_free(path); g_free(tmppath); g_free(bakpath); @@ -361,7 +361,8 @@ gint prefs_file_close_revert(PrefFile *pfile) tmppath = g_strconcat(pfile->path, ".tmp", NULL); fclose(pfile->fp); - if (unlink(tmppath) < 0) FILE_OP_ERROR(tmppath, "unlink"); + if (g_unlink(tmppath) < 0) + FILE_OP_ERROR(tmppath, "unlink"); g_free(tmppath); g_free(pfile->path); g_free(pfile); diff --git a/src/prefs_actions.c b/src/prefs_actions.c index 8d3ad758..6f994c9d 100644 --- a/src/prefs_actions.c +++ b/src/prefs_actions.c @@ -349,7 +349,7 @@ void prefs_actions_read_config(void) debug_print("Reading actions configurations...\n"); rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACTIONS_RC, NULL); - if ((fp = fopen(rcpath, "rb")) == NULL) { + if ((fp = g_fopen(rcpath, "rb")) == NULL) { if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen"); g_free(rcpath); return; diff --git a/src/prefs_common.c b/src/prefs_common.c index cef89305..9c9b8c88 100644 --- a/src/prefs_common.c +++ b/src/prefs_common.c @@ -826,7 +826,7 @@ void prefs_common_read_config(void) path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMAND_HISTORY, NULL); - if ((fp = fopen(path, "rb")) == NULL) { + if ((fp = g_fopen(path, "rb")) == NULL) { if (ENOENT != errno) FILE_OP_ERROR(path, "fopen"); g_free(path); return; @@ -854,7 +854,7 @@ void prefs_common_write_config(void) path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMAND_HISTORY, NULL); - if ((fp = fopen(path, "wb")) == NULL) { + if ((fp = g_fopen(path, "wb")) == NULL) { FILE_OP_ERROR(path, "fopen"); g_free(path); return; diff --git a/src/prefs_customheader.c b/src/prefs_customheader.c index d44387b7..97df2bbf 100644 --- a/src/prefs_customheader.c +++ b/src/prefs_customheader.c @@ -314,7 +314,7 @@ void prefs_custom_header_read_config(PrefsAccount *ac) rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, CUSTOM_HEADER_RC, NULL); - if ((fp = fopen(rcpath, "rb")) == NULL) { + if ((fp = g_fopen(rcpath, "rb")) == NULL) { if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen"); g_free(rcpath); ac->customhdr_list = NULL; @@ -359,7 +359,7 @@ void prefs_custom_header_write_config(PrefsAccount *ac) rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, CUSTOM_HEADER_RC, NULL); - if ((fp = fopen(rcpath, "rb")) == NULL) { + if ((fp = g_fopen(rcpath, "rb")) == NULL) { if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen"); } else { all_hdrs = NULL; diff --git a/src/prefs_display_header.c b/src/prefs_display_header.c index 42c88306..6d21aef8 100644 --- a/src/prefs_display_header.c +++ b/src/prefs_display_header.c @@ -369,7 +369,7 @@ void prefs_display_header_read_config(void) rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, DISPLAY_HEADER_RC, NULL); - if ((fp = fopen(rcpath, "rb")) == NULL) { + if ((fp = g_fopen(rcpath, "rb")) == NULL) { if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen"); g_free(rcpath); prefs_common.disphdr_list = NULL; diff --git a/src/prefs_filter.c b/src/prefs_filter.c index cd8abe1a..8af08f4b 100644 --- a/src/prefs_filter.c +++ b/src/prefs_filter.c @@ -623,7 +623,7 @@ static void prefs_filter_set_header_list(MsgInfo *msginfo) list = NULL; path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, FILTER_HEADER_RC, NULL); - if ((fp = fopen(path, "rb")) != NULL) { + if ((fp = g_fopen(path, "rb")) != NULL) { gchar buf[PREFSBUFSIZE]; while (fgets(buf, sizeof(buf), fp) != NULL) { diff --git a/src/procheader.c b/src/procheader.c index cf1331cf..4ca1490c 100644 --- a/src/procheader.c +++ b/src/procheader.c @@ -212,7 +212,7 @@ GSList *procheader_get_header_list_from_file(const gchar *file) FILE *fp; GSList *hlist; - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return NULL; } @@ -421,14 +421,14 @@ MsgInfo *procheader_parse_file(const gchar *file, MsgFlags flags, FILE *fp; MsgInfo *msginfo; - if (stat(file, &s) < 0) { + if (g_stat(file, &s) < 0) { FILE_OP_ERROR(file, "stat"); return NULL; } if (!S_ISREG(s.st_mode)) return NULL; - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return NULL; } diff --git a/src/procmime.c b/src/procmime.c index dd576bb6..7dcd3f89 100644 --- a/src/procmime.c +++ b/src/procmime.c @@ -666,7 +666,7 @@ gint procmime_get_part(const gchar *outfile, const gchar *infile, g_return_val_if_fail(infile != NULL, -1); g_return_val_if_fail(mimeinfo != NULL, -1); - if ((infp = fopen(infile, "rb")) == NULL) { + if ((infp = g_fopen(infile, "rb")) == NULL) { FILE_OP_ERROR(infile, "fopen"); return -1; } @@ -689,7 +689,7 @@ gint procmime_get_part_fp(const gchar *outfile, FILE *infp, MimeInfo *mimeinfo) FILE_OP_ERROR("procmime_get_part_fp()", "fseek"); return -1; } - if ((outfp = fopen(outfile, "wb")) == NULL) { + if ((outfp = g_fopen(outfile, "wb")) == NULL) { FILE_OP_ERROR(outfile, "fopen"); return -1; } @@ -701,7 +701,7 @@ gint procmime_get_part_fp(const gchar *outfile, FILE *infp, MimeInfo *mimeinfo) if (fclose(outfp) == EOF) { FILE_OP_ERROR(outfile, "fclose"); - unlink(outfile); + g_unlink(outfile); return -1; } @@ -826,7 +826,7 @@ gboolean procmime_find_string_part(MimeInfo *mimeinfo, const gchar *filename, g_return_val_if_fail(str != NULL, FALSE); g_return_val_if_fail(find_func != NULL, FALSE); - if ((infp = fopen(filename, "rb")) == NULL) { + if ((infp = g_fopen(filename, "rb")) == NULL) { FILE_OP_ERROR(filename, "fopen"); return FALSE; } @@ -1051,7 +1051,7 @@ static GList *procmime_get_mime_type_list(const gchar *file) gchar *delim; MimeType *mime_type; - if ((fp = fopen(file, "rb")) == NULL) return NULL; + if ((fp = g_fopen(file, "rb")) == NULL) return NULL; debug_print("Reading %s ...\n", file); @@ -1117,7 +1117,7 @@ EncodingType procmime_get_encoding_for_text_file(const gchar *file) size_t total_len = 0; gfloat octet_percentage; - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return ENC_UNKNOWN; } diff --git a/src/procmsg.c b/src/procmsg.c index dcfe07e2..8931536d 100644 --- a/src/procmsg.c +++ b/src/procmsg.c @@ -693,7 +693,7 @@ static FILE *procmsg_open_data_file(const gchar *file, guint version, g_return_val_if_fail(file != NULL, NULL); if (mode == DATA_WRITE) { - if ((fp = fopen(file, "wb")) == NULL) { + if ((fp = g_fopen(file, "wb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return NULL; } @@ -705,7 +705,7 @@ static FILE *procmsg_open_data_file(const gchar *file, guint version, } /* check version */ - if ((fp = fopen(file, "rb")) == NULL) + if ((fp = g_fopen(file, "rb")) == NULL) debug_print("Mark/Cache file '%s' not found\n", file); else { if (buf && buf_size > 0) @@ -725,7 +725,7 @@ static FILE *procmsg_open_data_file(const gchar *file, guint version, if (fp) { /* reopen with append mode */ fclose(fp); - if ((fp = fopen(file, "ab")) == NULL) + if ((fp = g_fopen(file, "ab")) == NULL) FILE_OP_ERROR(file, "fopen"); } else { /* open with overwrite mode if mark file doesn't exist or @@ -1034,7 +1034,7 @@ FILE *procmsg_open_message(MsgInfo *msginfo) return NULL; } - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); g_free(file); return NULL; @@ -1298,7 +1298,7 @@ gint procmsg_send_queue(FolderItem *queue, gboolean save_msgs, filter_info_free(fltinfo); } - unlink(tmp); + g_unlink(tmp); } send_queue_info_free(qinfo); @@ -1357,7 +1357,7 @@ void procmsg_print_message(MsgInfo *msginfo, const gchar *cmdline) prtmp = g_strdup_printf("%s%cprinttmp.%08x", get_mime_tmp_dir(), G_DIR_SEPARATOR, id++); - if ((prfp = fopen(prtmp, "wb")) == NULL) { + if ((prfp = g_fopen(prtmp, "wb")) == NULL) { FILE_OP_ERROR(prtmp, "fopen"); g_free(prtmp); fclose(tmpfp); @@ -43,7 +43,7 @@ gint recv_write_to_file(SockInfo *sock, const gchar *filename) g_return_val_if_fail(filename != NULL, -1); - if ((fp = fopen(filename, "wb")) == NULL) { + if ((fp = g_fopen(filename, "wb")) == NULL) { FILE_OP_ERROR(filename, "fopen"); recv_write(sock, NULL); return -1; @@ -54,13 +54,13 @@ gint recv_write_to_file(SockInfo *sock, const gchar *filename) if ((ret = recv_write(sock, fp)) < 0) { fclose(fp); - unlink(filename); + g_unlink(filename); return ret; } if (fclose(fp) == EOF) { FILE_OP_ERROR(filename, "fclose"); - unlink(filename); + g_unlink(filename); return -1; } @@ -74,7 +74,7 @@ gint recv_bytes_write_to_file(SockInfo *sock, glong size, const gchar *filename) g_return_val_if_fail(filename != NULL, -1); - if ((fp = fopen(filename, "wb")) == NULL) { + if ((fp = g_fopen(filename, "wb")) == NULL) { FILE_OP_ERROR(filename, "fopen"); recv_write(sock, NULL); return -1; @@ -85,13 +85,13 @@ gint recv_bytes_write_to_file(SockInfo *sock, glong size, const gchar *filename) if ((ret = recv_bytes_write(sock, size, fp)) < 0) { fclose(fp); - unlink(filename); + g_unlink(filename); return ret; } if (fclose(fp) == EOF) { FILE_OP_ERROR(filename, "fclose"); - unlink(filename); + g_unlink(filename); return -1; } diff --git a/src/rfc2015.c b/src/rfc2015.c index 0aded39e..ef6a9230 100644 --- a/src/rfc2015.c +++ b/src/rfc2015.c @@ -114,7 +114,7 @@ void rfc2015_secure_remove(const gchar *fname) if (!fname) return; /* fixme: overwrite the file first */ - remove(fname); + g_remove(fname); } static void sig_status_for_key(GString *str, gpgme_ctx_t ctx, @@ -232,14 +232,14 @@ static void check_signature(MimeInfo *mimeinfo, MimeInfo *partinfo, FILE *fp) goto leave; } if (canonicalize_file_replace(tmp_file) < 0) { - unlink(tmp_file); + g_unlink(tmp_file); g_free(tmp_file); goto leave; } err = gpgme_data_new_from_file(&text, tmp_file, 1); - unlink(tmp_file); + g_unlink(tmp_file); g_free(tmp_file); if (!err) @@ -305,7 +305,7 @@ static gchar *copy_gpgmedata_to_temp(GpgmeData data, guint *length) tmp = g_strdup_printf("%s%cgpgtmp.%08x", get_mime_tmp_dir(), G_DIR_SEPARATOR, ++id); - if ((fp = fopen(tmp, "wb")) == NULL) { + if ((fp = g_fopen(tmp, "wb")) == NULL) { FILE_OP_ERROR(tmp, "fopen"); g_free(tmp); return NULL; @@ -466,7 +466,7 @@ gboolean rfc2015_msg_is_encrypted(const gchar *file) MimeInfo *mimeinfo; gint ret; - if ((fp = fopen(file, "rb")) == NULL) + if ((fp = g_fopen(file, "rb")) == NULL) return FALSE; mimeinfo = procmime_scan_mime_header(fp); @@ -586,7 +586,7 @@ void rfc2015_decrypt_message(MsgInfo *msginfo, MimeInfo *mimeinfo, FILE *fp) fname = g_strdup_printf("%s%cplaintext.%08x", get_mime_tmp_dir(), G_DIR_SEPARATOR, ++id); - if ((dstfp = fopen(fname, "wb")) == NULL) { + if ((dstfp = g_fopen(fname, "wb")) == NULL) { FILE_OP_ERROR(fname, "fopen"); g_free(fname); DECRYPTION_ABORT(); @@ -752,7 +752,7 @@ gint rfc2015_encrypt(const gchar *file, GSList *recp_list, } /* Open the source file */ - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); goto failure; } @@ -849,7 +849,7 @@ gint rfc2015_encrypt(const gchar *file, GSList *recp_list, FILE_OP_ERROR(file, "fclose"); goto failure; } - if ((fp = fopen(file, "wb")) == NULL) { + if ((fp = g_fopen(file, "wb")) == NULL) { FILE_OP_ERROR(file, "fopen"); goto failure; } @@ -1062,7 +1062,7 @@ gint rfc2015_sign(const gchar *file, GSList *key_list) boundary = generate_mime_boundary("Signature"); /* Open the source file */ - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); goto failure; } @@ -1142,7 +1142,7 @@ gint rfc2015_sign(const gchar *file, GSList *key_list) FILE_OP_ERROR(file, "fclose"); goto failure; } - if ((fp = fopen(file, "wb")) == NULL) { + if ((fp = g_fopen(file, "wb")) == NULL) { FILE_OP_ERROR(file, "fopen"); goto failure; } @@ -1268,7 +1268,7 @@ gint rfc2015_clearsign(const gchar *file, GSList *key_list) ssize_t bytesRW = 0; gchar *micalg = NULL; - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); goto failure; } @@ -1304,7 +1304,7 @@ gint rfc2015_clearsign(const gchar *file, GSList *key_list) fp = NULL; goto failure; } - if ((fp = fopen(file, "wb")) == NULL) { + if ((fp = g_fopen(file, "wb")) == NULL) { FILE_OP_ERROR(file, "fopen"); goto failure; } diff --git a/src/send_message.c b/src/send_message.c index fc67b209..87072818 100644 --- a/src/send_message.c +++ b/src/send_message.c @@ -101,7 +101,7 @@ gint send_message(const gchar *file, PrefsAccount *ac_prefs, GSList *to_list) g_return_val_if_fail(ac_prefs != NULL, -1); g_return_val_if_fail(to_list != NULL, -1); - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return -1; } @@ -140,7 +140,7 @@ QueueInfo *send_get_queue_info(const gchar *file) g_return_val_if_fail(file != NULL, NULL); - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return NULL; } @@ -206,7 +206,7 @@ gint send_get_queue_contents(QueueInfo *qinfo, const gchar *dest) g_return_val_if_fail(qinfo->fp != NULL, -1); g_return_val_if_fail(dest != NULL, -1); - if ((fp = fopen(dest, "wb")) == NULL) { + if ((fp = g_fopen(dest, "wb")) == NULL) { FILE_OP_ERROR(dest, "fopen"); return -1; } @@ -218,7 +218,7 @@ gint send_get_queue_contents(QueueInfo *qinfo, const gchar *dest) if (fclose(fp) < 0) { FILE_OP_ERROR(dest, "fclose"); - unlink(dest); + g_unlink(dest); return -1; } diff --git a/src/sourcewindow.c b/src/sourcewindow.c index f6eaf7e5..11e5c927 100644 --- a/src/sourcewindow.c +++ b/src/sourcewindow.c @@ -126,7 +126,7 @@ void source_window_show_msg(SourceWindow *sourcewin, MsgInfo *msginfo) file = procmsg_get_message_file(msginfo); g_return_if_fail(file != NULL); - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); g_free(file); return; diff --git a/src/template.c b/src/template.c index 9aafa09d..c2dc9b2e 100644 --- a/src/template.c +++ b/src/template.c @@ -40,7 +40,7 @@ static Template *template_load(gchar *filename) gchar buf[BUFFSIZE]; gint bytes_read; - if ((fp = fopen(filename, "rb")) == NULL) { + if ((fp = g_fopen(filename, "rb")) == NULL) { FILE_OP_ERROR(filename, "fopen"); return NULL; } @@ -136,7 +136,7 @@ GSList *template_read_config(void) filename = g_strconcat(path, G_DIR_SEPARATOR_S, de->d_name, NULL); - if (stat(filename, &s) != 0 || !S_ISREG(s.st_mode) ) { + if (g_stat(filename, &s) != 0 || !S_ISREG(s.st_mode) ) { debug_print("%s:%d %s is not an ordinary file\n", __FILE__, __LINE__, filename); continue; @@ -186,7 +186,7 @@ void template_write_config(GSList *tmpl_list) filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(tmpl_num), NULL); - if ((fp = fopen(filename, "wb")) == NULL) { + if ((fp = g_fopen(filename, "wb")) == NULL) { FILE_OP_ERROR(filename, "fopen"); g_free(filename); return; diff --git a/src/textview.c b/src/textview.c index 7df5e385..34360fbd 100644 --- a/src/textview.c +++ b/src/textview.c @@ -430,7 +430,7 @@ void textview_show_message(TextView *textview, MimeInfo *mimeinfo, buffer = gtk_text_view_get_buffer(text); - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return; } diff --git a/src/utils.c b/src/utils.c index 518b0737..0d4c08c8 100644 --- a/src/utils.c +++ b/src/utils.c @@ -45,6 +45,11 @@ #include <dirent.h> #include <time.h> +#ifdef G_OS_WIN32 +# include <direct.h> +# include <io.h> +#endif + #include "utils.h" #include "socket.h" #include "statusbar.h" @@ -54,7 +59,98 @@ extern gboolean debug_mode; -static void hash_free_strings_func(gpointer key, gpointer value, gpointer data); + +#if !GLIB_CHECK_VERSION(2, 7, 0) && !defined(G_OS_UNIX) +gint g_chdir(const gchar *path) +{ +#ifdef G_OS_WIN32 + if (G_WIN32_HAVE_WIDECHAR_API()) { + wchar_t *wpath; + gint retval; + gint save_errno; + + wpath = g_utf8_to_utf16(path, -1, NULL, NULL, NULL); + if (wpath == NULL) { + errno = EINVAL; + return -1; + } + + retval = _wchdir(wpath); + save_errno = errno; + + g_free(wpath); + + errno = save_errno; + return retval; + } else { + gchar *cp_path; + gint retval; + gint save_errno; + + cp_path = g_locale_from_utf8(path, -1, NULL, NULL, NULL); + if (cp_path == NULL) { + errno = EINVAL; + return -1; + } + + retval = chdir(cp_path); + save_errno = errno; + + g_free(cp_path); + + errno = save_errno; + return retval; + } +#else + return chdir(path); +#endif +} + +gint g_chmod(const gchar *path, gint mode) +{ +#ifdef G_OS_WIN32 + if (G_WIN32_HAVE_WIDECHAR_API()) { + wchar_t *wpath; + gint retval; + gint save_errno; + + wpath = g_utf8_to_utf16(path, -1, NULL, NULL, NULL); + if (wpath == NULL) { + errno = EINVAL; + return -1; + } + + retval = _wchmod(wpath, mode); + save_errno = errno; + + g_free(wpath); + + errno = save_errno; + return retval; + } else { + gchar *cp_path; + gint retval; + gint save_errno; + + cp_path = g_locale_from_utf8(path, -1, NULL, NULL, NULL); + if (cp_path == NULL) { + errno = EINVAL; + return -1; + } + + retval = chmod(cp_path, mode); + save_errno = errno; + + g_free(cp_path); + + errno = save_errno; + return retval; + } +#else + return chmod(path, mode); +#endif +} +#endif /* GLIB_CHECK_VERSION && G_OS_UNIX */ void list_free_strings(GList *list) { @@ -1782,7 +1878,7 @@ off_t get_file_size(const gchar *file) { struct stat s; - if (stat(file, &s) < 0) { + if (g_stat(file, &s) < 0) { FILE_OP_ERROR(file, "stat"); return -1; } @@ -1796,7 +1892,7 @@ off_t get_file_size_as_crlf(const gchar *file) off_t size = 0; gchar buf[BUFFSIZE]; - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return -1; } @@ -1850,7 +1946,7 @@ gboolean file_exist(const gchar *file, gboolean allow_fifo) if (file == NULL) return FALSE; - if (stat(file, &s) < 0) { + if (g_stat(file, &s) < 0) { if (ENOENT != errno) FILE_OP_ERROR(file, "stat"); return FALSE; } @@ -1908,7 +2004,7 @@ gint change_dir(const gchar *dir) if (debug_mode) prevdir = g_get_current_dir(); - if (chdir(dir) < 0) { + if (g_chdir(dir) < 0) { FILE_OP_ERROR(dir, "chdir"); if (debug_mode) g_free(prevdir); return -1; @@ -1927,15 +2023,11 @@ gint change_dir(const gchar *dir) gint make_dir(const gchar *dir) { -#ifdef G_OS_WIN32 - if (mkdir(dir) < 0) { -#else - if (mkdir(dir, S_IRWXU) < 0) { -#endif + if (g_mkdir(dir, S_IRWXU) < 0) { FILE_OP_ERROR(dir, "mkdir"); return -1; } - if (chmod(dir, S_IRWXU) < 0) + if (g_chmod(dir, S_IRWXU) < 0) FILE_OP_ERROR(dir, "chmod"); return 0; @@ -1975,7 +2067,7 @@ gint remove_all_files(const gchar *dir) prev_dir = g_get_current_dir(); - if (chdir(dir) < 0) { + if (g_chdir(dir) < 0) { FILE_OP_ERROR(dir, "chdir"); g_free(prev_dir); return -1; @@ -1992,13 +2084,13 @@ gint remove_all_files(const gchar *dir) !strcmp(d->d_name, "..")) continue; - if (unlink(d->d_name) < 0) + if (g_unlink(d->d_name) < 0) FILE_OP_ERROR(d->d_name, "unlink"); } closedir(dp); - if (chdir(prev_dir) < 0) { + if (g_chdir(prev_dir) < 0) { FILE_OP_ERROR(prev_dir, "chdir"); g_free(prev_dir); return -1; @@ -2018,7 +2110,7 @@ gint remove_numbered_files(const gchar *dir, guint first, guint last) prev_dir = g_get_current_dir(); - if (chdir(dir) < 0) { + if (g_chdir(dir) < 0) { FILE_OP_ERROR(dir, "chdir"); g_free(prev_dir); return -1; @@ -2035,14 +2127,14 @@ gint remove_numbered_files(const gchar *dir, guint first, guint last) if (file_no > 0 && first <= file_no && file_no <= last) { if (is_dir_exist(d->d_name)) continue; - if (unlink(d->d_name) < 0) + if (g_unlink(d->d_name) < 0) FILE_OP_ERROR(d->d_name, "unlink"); } } closedir(dp); - if (chdir(prev_dir) < 0) { + if (g_chdir(prev_dir) < 0) { FILE_OP_ERROR(prev_dir, "chdir"); g_free(prev_dir); return -1; @@ -2069,7 +2161,7 @@ gint remove_expired_files(const gchar *dir, guint hours) prev_dir = g_get_current_dir(); - if (chdir(dir) < 0) { + if (g_chdir(dir) < 0) { FILE_OP_ERROR(dir, "chdir"); g_free(prev_dir); return -1; @@ -2087,7 +2179,7 @@ gint remove_expired_files(const gchar *dir, guint hours) while ((d = readdir(dp)) != NULL) { file_no = to_number(d->d_name); if (file_no > 0) { - if (stat(d->d_name, &s) < 0) { + if (g_stat(d->d_name, &s) < 0) { FILE_OP_ERROR(d->d_name, "stat"); continue; } @@ -2095,7 +2187,7 @@ gint remove_expired_files(const gchar *dir, guint hours) continue; mtime = MAX(s.st_mtime, s.st_atime); if (now - mtime > expire_time) { - if (unlink(d->d_name) < 0) + if (g_unlink(d->d_name) < 0) FILE_OP_ERROR(d->d_name, "unlink"); } } @@ -2103,7 +2195,7 @@ gint remove_expired_files(const gchar *dir, guint hours) closedir(dp); - if (chdir(prev_dir) < 0) { + if (g_chdir(prev_dir) < 0) { FILE_OP_ERROR(prev_dir, "chdir"); g_free(prev_dir); return -1; @@ -2121,14 +2213,14 @@ static gint remove_dir_recursive_real(const gchar *dir) struct dirent *d; gchar *prev_dir; - if (stat(dir, &s) < 0) { + if (g_stat(dir, &s) < 0) { FILE_OP_ERROR(dir, "stat"); if (ENOENT == errno) return 0; return -1; } if (!S_ISDIR(s.st_mode)) { - if (unlink(dir) < 0) { + if (g_unlink(dir) < 0) { FILE_OP_ERROR(dir, "unlink"); return -1; } @@ -2139,7 +2231,7 @@ static gint remove_dir_recursive_real(const gchar *dir) prev_dir = g_get_current_dir(); /* g_print("prev_dir = %s\n", prev_dir); */ - if (chdir(dir) < 0) { + if (g_chdir(dir) < 0) { FILE_OP_ERROR(dir, "chdir"); g_free(prev_dir); return -1; @@ -2147,7 +2239,7 @@ static gint remove_dir_recursive_real(const gchar *dir) if ((dp = opendir(".")) == NULL) { FILE_OP_ERROR(dir, "opendir"); - chdir(prev_dir); + g_chdir(prev_dir); g_free(prev_dir); return -1; } @@ -2166,14 +2258,14 @@ static gint remove_dir_recursive_real(const gchar *dir) return -1; } } else { - if (unlink(d->d_name) < 0) + if (g_unlink(d->d_name) < 0) FILE_OP_ERROR(d->d_name, "unlink"); } } closedir(dp); - if (chdir(prev_dir) < 0) { + if (g_chdir(prev_dir) < 0) { FILE_OP_ERROR(prev_dir, "chdir"); g_free(prev_dir); return -1; @@ -2181,7 +2273,7 @@ static gint remove_dir_recursive_real(const gchar *dir) g_free(prev_dir); - if (rmdir(dir) < 0) { + if (g_rmdir(dir) < 0) { FILE_OP_ERROR(dir, "rmdir"); return -1; } @@ -2196,12 +2288,12 @@ gint remove_dir_recursive(const gchar *dir) cur_dir = g_get_current_dir(); - if (chdir(dir) < 0) { + if (g_chdir(dir) < 0) { FILE_OP_ERROR(dir, "chdir"); ret = -1; goto leave; } - if (chdir("..") < 0) { + if (g_chdir("..") < 0) { FILE_OP_ERROR(dir, "chdir"); ret = -1; goto leave; @@ -2211,7 +2303,7 @@ gint remove_dir_recursive(const gchar *dir) leave: if (is_dir_exist(cur_dir)) { - if (chdir(cur_dir) < 0) { + if (g_chdir(cur_dir) < 0) { FILE_OP_ERROR(cur_dir, "chdir"); } } @@ -2229,11 +2321,11 @@ gint rename_force(const gchar *oldpath, const gchar *newpath) return -1; } if (is_file_exist(newpath)) { - if (unlink(newpath) < 0) + if (g_unlink(newpath) < 0) FILE_OP_ERROR(newpath, "unlink"); } #endif - return rename(oldpath, newpath); + return g_rename(oldpath, newpath); } gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup) @@ -2244,7 +2336,7 @@ gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup) gchar *dest_bak = NULL; gboolean err = FALSE; - if ((src_fp = fopen(src, "rb")) == NULL) { + if ((src_fp = g_fopen(src, "rb")) == NULL) { FILE_OP_ERROR(src, "fopen"); return -1; } @@ -2258,7 +2350,7 @@ gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup) } } - if ((dest_fp = fopen(dest, "wb")) == NULL) { + if ((dest_fp = g_fopen(dest, "wb")) == NULL) { FILE_OP_ERROR(dest, "fopen"); fclose(src_fp); if (dest_bak) { @@ -2281,7 +2373,7 @@ gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup) g_warning(_("writing to %s failed.\n"), dest); fclose(dest_fp); fclose(src_fp); - unlink(dest); + g_unlink(dest); if (dest_bak) { if (rename_force(dest_bak, dest) < 0) FILE_OP_ERROR(dest_bak, "rename"); @@ -2302,7 +2394,7 @@ gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup) } if (err) { - unlink(dest); + g_unlink(dest); if (dest_bak) { if (rename_force(dest_bak, dest) < 0) FILE_OP_ERROR(dest_bak, "rename"); @@ -2312,7 +2404,7 @@ gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup) } if (keep_backup == FALSE && dest_bak) - unlink(dest_bak); + g_unlink(dest_bak); g_free(dest_bak); @@ -2370,7 +2462,7 @@ gint move_file(const gchar *src, const gchar *dest, gboolean overwrite) if (copy_file(src, dest, FALSE) < 0) return -1; - unlink(src); + g_unlink(src); return 0; } @@ -2388,7 +2480,7 @@ gint copy_file_part(FILE *fp, off_t offset, size_t length, const gchar *dest) return -1; } - if ((dest_fp = fopen(dest, "wb")) == NULL) { + if ((dest_fp = g_fopen(dest, "wb")) == NULL) { FILE_OP_ERROR(dest, "fopen"); return -1; } @@ -2407,7 +2499,7 @@ gint copy_file_part(FILE *fp, off_t offset, size_t length, const gchar *dest) if (fwrite(buf, n_read, 1, dest_fp) < 1) { g_warning(_("writing to %s failed.\n"), dest); fclose(dest_fp); - unlink(dest); + g_unlink(dest); return -1; } bytes_left -= n_read; @@ -2426,7 +2518,7 @@ gint copy_file_part(FILE *fp, off_t offset, size_t length, const gchar *dest) } if (err) { - unlink(dest); + g_unlink(dest); return -1; } @@ -2477,12 +2569,12 @@ gint canonicalize_file(const gchar *src, const gchar *dest) gboolean err = FALSE; gboolean last_linebreak = FALSE; - if ((src_fp = fopen(src, "rb")) == NULL) { + if ((src_fp = g_fopen(src, "rb")) == NULL) { FILE_OP_ERROR(src, "fopen"); return -1; } - if ((dest_fp = fopen(dest, "wb")) == NULL) { + if ((dest_fp = g_fopen(dest, "wb")) == NULL) { FILE_OP_ERROR(dest, "fopen"); fclose(src_fp); return -1; @@ -2519,7 +2611,7 @@ gint canonicalize_file(const gchar *src, const gchar *dest) g_warning("writing to %s failed.\n", dest); fclose(dest_fp); fclose(src_fp); - unlink(dest); + g_unlink(dest); return -1; } } @@ -2540,7 +2632,7 @@ gint canonicalize_file(const gchar *src, const gchar *dest) } if (err) { - unlink(dest); + g_unlink(dest); return -1; } @@ -2560,7 +2652,7 @@ gint canonicalize_file_replace(const gchar *file) if (move_file(tmp_file, file, TRUE) < 0) { g_warning("can't replace %s .\n", file); - unlink(tmp_file); + g_unlink(tmp_file); g_free(tmp_file); return -1; } @@ -2575,12 +2667,12 @@ gint uncanonicalize_file(const gchar *src, const gchar *dest) gchar buf[BUFFSIZE]; gboolean err = FALSE; - if ((src_fp = fopen(src, "rb")) == NULL) { + if ((src_fp = g_fopen(src, "rb")) == NULL) { FILE_OP_ERROR(src, "fopen"); return -1; } - if ((dest_fp = fopen(dest, "wb")) == NULL) { + if ((dest_fp = g_fopen(dest, "wb")) == NULL) { FILE_OP_ERROR(dest, "fopen"); fclose(src_fp); return -1; @@ -2597,7 +2689,7 @@ gint uncanonicalize_file(const gchar *src, const gchar *dest) g_warning("writing to %s failed.\n", dest); fclose(dest_fp); fclose(src_fp); - unlink(dest); + g_unlink(dest); return -1; } } @@ -2613,7 +2705,7 @@ gint uncanonicalize_file(const gchar *src, const gchar *dest) } if (err) { - unlink(dest); + g_unlink(dest); return -1; } @@ -2633,7 +2725,7 @@ gint uncanonicalize_file_replace(const gchar *file) if (move_file(tmp_file, file, TRUE) < 0) { g_warning("can't replace %s .\n", file); - unlink(tmp_file); + g_unlink(tmp_file); g_free(tmp_file); return -1; } @@ -2759,7 +2851,7 @@ gint change_file_mode_rw(FILE *fp, const gchar *file) #if HAVE_FCHMOD return fchmod(fileno(fp), S_IRUSR|S_IWUSR); #else - return chmod(file, S_IRUSR|S_IWUSR); + return g_chmod(file, S_IRUSR|S_IWUSR); #endif } @@ -2791,7 +2883,7 @@ FILE *my_tmpfile(void) if (fd < 0) return tmpfile(); - unlink(fname); + g_unlink(fname); fp = fdopen(fd, "w+b"); if (!fp) @@ -2837,7 +2929,7 @@ gint str_write_to_file(const gchar *str, const gchar *file) g_return_val_if_fail(str != NULL, -1); g_return_val_if_fail(file != NULL, -1); - if ((fp = fopen(file, "wb")) == NULL) { + if ((fp = g_fopen(file, "wb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return -1; } @@ -2851,13 +2943,13 @@ gint str_write_to_file(const gchar *str, const gchar *file) if (fwrite(str, len, 1, fp) != 1) { FILE_OP_ERROR(file, "fwrite"); fclose(fp); - unlink(file); + g_unlink(file); return -1; } if (fclose(fp) == EOF) { FILE_OP_ERROR(file, "fclose"); - unlink(file); + g_unlink(file); return -1; } @@ -2871,7 +2963,7 @@ gchar *file_read_to_str(const gchar *file) g_return_val_if_fail(file != NULL, NULL); - if ((fp = fopen(file, "rb")) == NULL) { + if ((fp = g_fopen(file, "rb")) == NULL) { FILE_OP_ERROR(file, "fopen"); return NULL; } @@ -3168,7 +3260,7 @@ static FILE *log_fp = NULL; void set_log_file(const gchar *filename) { if (log_fp) return; - log_fp = fopen(filename, "wb"); + log_fp = g_fopen(filename, "wb"); if (!log_fp) FILE_OP_ERROR(filename, "fopen"); } diff --git a/src/utils.h b/src/utils.h index 85f1ec2f..976525d8 100644 --- a/src/utils.h +++ b/src/utils.h @@ -39,6 +39,37 @@ # include <wchar.h> #endif +/* Wrappers for C library function that take pathname arguments. */ +#if GLIB_CHECK_VERSION(2, 6, 0) +# include <glib/gstdio.h> +#else + +#define g_open open +#define g_rename rename +#define g_mkdir mkdir +#define g_stat stat +#define g_lstat lstat +#define g_unlink unlink +#define g_remove remove +#define g_rmdir rmdir +#define g_fopen fopen +#define g_freopen freopen + +#endif /* GLIB_CHECK_VERSION */ + +#if !GLIB_CHECK_VERSION(2, 7, 0) + +#ifdef G_OS_UNIX +#define g_chdir chdir +#define g_chmod chmod +#else +gint g_chdir (const gchar *path); +gint g_chmod (const gchar *path, + gint mode); +#endif /* G_OS_UNIX */ + +#endif /* !GLIB_CHECK_VERSION */ + /* The AC_CHECK_SIZEOF() in configure fails for some machines. * we provide some fallback values here */ #if !SIZEOF_UNSIGNED_SHORT @@ -141,6 +172,7 @@ #define FILE_OP_ERROR(file, func) \ { \ fprintf(stderr, "%s: ", file); \ + fflush(stderr); \ perror(func); \ } diff --git a/src/vcard.c b/src/vcard.c index 286292a7..4d0d0180 100644 --- a/src/vcard.c +++ b/src/vcard.c @@ -186,7 +186,7 @@ static gint vcard_open_file( VCardFile* cardFile ) { /* fprintf( stdout, "Opening file\n" ); */ cardFile->addressCache->dataRead = FALSE; if( cardFile->path ) { - cardFile->file = fopen( cardFile->path, "rb" ); + cardFile->file = g_fopen( cardFile->path, "rb" ); if( ! cardFile->file ) { /* fprintf( stderr, "can't open %s\n", cardFile->path ); */ cardFile->retVal = MGU_OPEN_FILE; @@ -667,7 +667,7 @@ gchar *vcard_find_gnomecard( void ) { strcat( str, GNOMECARD_FILE ); fileSpec = NULL; - if( ( fp = fopen( str, "rb" ) ) != NULL ) { + if( ( fp = g_fopen( str, "rb" ) ) != NULL ) { /* Read configuration file */ lenlbl = strlen( GNOMECARD_SECTION ); while( fgets( buf, sizeof( buf ), fp ) != NULL ) { @@ -74,7 +74,7 @@ XMLFile *xml_open_file(const gchar *path) newfile = g_new(XMLFile, 1); - newfile->fp = fopen(path, "rb"); + newfile->fp = g_fopen(path, "rb"); if (!newfile->fp) { g_free(newfile); return NULL; |