diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-01-18 10:50:43 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-01-18 10:50:43 +0000 |
commit | 295bd43a38d1b785183ba1599e78fa6fbbcd8e02 (patch) | |
tree | 1e872659029f80928f3f98b4352aae8888a6928d /src/codeconv.c | |
parent | 3fec59fac205ff4588f8afe93b28943b31f9ab8d (diff) |
implemented the migration of configuration.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@14 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'src/codeconv.c')
-rw-r--r-- | src/codeconv.c | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/src/codeconv.c b/src/codeconv.c index 454cb0e4..3502f1d3 100644 --- a/src/codeconv.c +++ b/src/codeconv.c @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2004 Hiroyuki Yamamoto + * Copyright (C) 1999-2005 Hiroyuki Yamamoto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,6 +21,8 @@ # include "config.h" #endif +#include "defs.h" + #include <glib.h> #include <string.h> #include <ctype.h> @@ -1760,3 +1762,53 @@ void conv_encode_header(gchar *dest, gint len, const gchar *src, } #undef LBREAK_IF_REQUIRED + +gint conv_copy_file(const gchar *src, const gchar *dest, const gchar *encoding) +{ + FILE *src_fp, *dest_fp; + gchar buf[BUFFSIZE], outbuf[BUFFSIZE]; + CodeConverter *conv; + gboolean err = FALSE; + + if ((src_fp = fopen(src, "rb")) == NULL) { + FILE_OP_ERROR(src, "fopen"); + return -1; + } + if ((dest_fp = fopen(dest, "wb")) == NULL) { + FILE_OP_ERROR(dest, "fopen"); + fclose(src_fp); + return -1; + } + + if (change_file_mode_rw(dest_fp, dest) < 0) { + FILE_OP_ERROR(dest, "chmod"); + g_warning("can't change file mode\n"); + } + + conv = conv_code_converter_new(encoding); + + while (fgets(buf, sizeof(buf), src_fp) != NULL) { + if (conv_convert(conv, outbuf, sizeof(outbuf), buf) == 0) + fputs(outbuf, dest_fp); + else + fputs(buf, dest_fp); + } + + conv_code_converter_destroy(conv); + + if (ferror(src_fp)) { + FILE_OP_ERROR(src, "fgets"); + err = TRUE; + } + fclose(src_fp); + if (fclose(dest_fp) == EOF) { + FILE_OP_ERROR(dest, "fclose"); + err = TRUE; + } + if (err) { + unlink(dest); + return -1; + } + + return 0; +} |