commit ba2f6e56c829fb9dbe656a380ef4431cd6d11552 parent 247578410f3b87ac8af227a834a7b5e1736156e8 Author: Colin Leroy <colin@colino.net> Date: Sun, 7 Oct 2018 14:46:02 +0200 Rename claws_io to file-utils, and move file-related functions from utils.c to file-utils.c Diffstat:
106 files changed, 1066 insertions(+), 1036 deletions(-)
diff --git a/src/account.c b/src/account.c @@ -55,7 +55,7 @@ #include "prefs_actions.h" #include "hooks.h" #include "passwordstore.h" -#include "claws_io.h" +#include "file-utils.h" enum { ACCOUNT_IS_DEFAULT, diff --git a/src/addrbook.c b/src/addrbook.c @@ -38,7 +38,7 @@ #include "addrcache.h" #include "addrbook.h" #include "adbookbase.h" -#include "claws_io.h" +#include "file-utils.h" #ifndef DEV_STANDALONE #include "prefs_gtk.h" diff --git a/src/addrclip.c b/src/addrclip.c @@ -56,6 +56,7 @@ #include "addrclip.h" #include "alertpanel.h" #include "defs.h" +#include "file-utils.h" /* * Create a clipboard. diff --git a/src/addressbook.c b/src/addressbook.c @@ -44,6 +44,7 @@ #include "xml.h" #include "prefs_gtk.h" #include "procmime.h" +#include "file-utils.h" #include "utils.h" #include "gtkutils.h" #include "codeconv.h" diff --git a/src/addrharvest.c b/src/addrharvest.c @@ -40,7 +40,7 @@ #ifdef USE_ALT_ADDRBOOK #include "addressbook-dbus.h" #endif -#include "claws_io.h" +#include "file-utils.h" /* Mail header names of interest */ static gchar *_headerFrom_ = HEADER_FROM; diff --git a/src/addrindex.c b/src/addrindex.c @@ -43,7 +43,7 @@ #include "utils.h" #include "alertpanel.h" #include "passwordstore.h" -#include "claws_io.h" +#include "file-utils.h" #ifndef DEV_STANDALONE #include "prefs_gtk.h" diff --git a/src/addritem.c b/src/addritem.c @@ -25,6 +25,7 @@ #include <string.h> #include "defs.h" +#include "file-utils.h" #include "utils.h" #include "addritem.h" #include "mgutils.h" diff --git a/src/addrmerge.c b/src/addrmerge.c @@ -38,6 +38,7 @@ #include "addrmerge.h" #include "alertpanel.h" #include "gtkutils.h" +#include "file-utils.h" #include "utils.h" #include "prefs_common.h" diff --git a/src/autofaces.c b/src/autofaces.c @@ -27,7 +27,7 @@ #include "utils.h" #include "autofaces.h" -#include "claws_io.h" +#include "file-utils.h" static gint get_content_for_any_face(gchar *buf, gint len, gchar *anyname, gint maxlen) { diff --git a/src/common/Makefile.am b/src/common/Makefile.am @@ -25,6 +25,7 @@ endif libclawscommon_la_SOURCES = $(arch_sources) \ codeconv.c \ + file-utils.c \ hooks.c \ log.c \ md5.c \ @@ -43,7 +44,6 @@ libclawscommon_la_SOURCES = $(arch_sources) \ string_match.c \ stringtable.c \ claws.c \ - claws_io.c \ tags.c \ template.c \ utils.c \ @@ -56,6 +56,7 @@ libclawscommon_la_SOURCES = $(arch_sources) \ clawscommonincludedir = $(pkgincludedir)/common clawscommoninclude_HEADERS = $(arch_headers) \ codeconv.h \ + file-utils.h \ defs.h \ hooks.h \ log.h \ @@ -75,7 +76,6 @@ clawscommoninclude_HEADERS = $(arch_headers) \ string_match.h \ stringtable.h \ claws.h \ - claws_io.h \ tags.h \ template.h \ timing.h \ diff --git a/src/common/claws_io.c b/src/common/claws_io.c @@ -1,93 +0,0 @@ -/* - * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2018 Colin Leroy and the Claws Mail team - * - * 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * 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 <stdio.h> -#include <unistd.h> - -#include "timing.h" -#include "claws_io.h" - -gboolean prefs_common_get_flush_metadata(void); - -/* FIXME make static once every file I/O is done using claws_* wrappers */ -int safe_fclose(FILE *fp) -{ - int r; - START_TIMING(""); - - if (fflush(fp) != 0) { - return EOF; - } - if (prefs_common_get_flush_metadata() && fsync(fileno(fp)) != 0) { - return EOF; - } - - r = fclose(fp); - END_TIMING(); - - 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 diff --git a/src/common/claws_io.h b/src/common/claws_io.h @@ -1,62 +0,0 @@ -/* - * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2018 Colin Leroy and the Claws Mail team - * - * 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#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 diff --git a/src/common/file-utils.c b/src/common/file-utils.c @@ -0,0 +1,857 @@ +/* + * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client + * Copyright (C) 1999-2018 Colin Leroy and the Claws Mail team + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * 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 <errno.h> +#include <stdio.h> +#include <unistd.h> +#include <fcntl.h> + +#include "defs.h" +#include "codeconv.h" +#include "timing.h" +#include "file-utils.h" + +gboolean prefs_common_get_flush_metadata(void); +gboolean prefs_common_get_use_shred(void); + +/* FIXME make static once every file I/O is done using claws_* wrappers */ +int safe_fclose(FILE *fp) +{ + int r; + START_TIMING(""); + + if (fflush(fp) != 0) { + return EOF; + } + if (prefs_common_get_flush_metadata() && fsync(fileno(fp)) != 0) { + return EOF; + } + + r = fclose(fp); + END_TIMING(); + + 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); +} + +#ifdef G_OS_WIN32 +#define WEXITSTATUS(x) (x) +#endif + +int claws_unlink(const char *filename) +{ + GStatBuf s; + static int found_shred = -1; + static const gchar *args[4]; + + if (filename == NULL) + return 0; + + if (prefs_common_get_use_shred()) { + if (found_shred == -1) { + /* init */ + args[0] = g_find_program_in_path("shred"); + debug_print("found shred: %s\n", args[0]); + found_shred = (args[0] != NULL) ? 1:0; + args[1] = "-f"; + args[3] = NULL; + } + if (found_shred == 1) { + if (g_stat(filename, &s) == 0 && S_ISREG(s.st_mode)) { + if (s.st_nlink == 1) { + gint status=0; + args[2] = filename; + g_spawn_sync(NULL, (gchar **)args, NULL, 0, + NULL, NULL, NULL, NULL, &status, NULL); + debug_print("%s %s exited with status %d\n", + args[0], filename, WEXITSTATUS(status)); + if (truncate(filename, 0) < 0) + g_warning("couln't truncate: %s", filename); + } + } + } + } + return g_unlink(filename); +} + +gint file_strip_crs(const gchar *file) +{ + FILE *fp = NULL, *outfp = NULL; + gchar buf[4096]; + gchar *out = get_tmp_file(); + if (file == NULL) + goto freeout; + + fp = claws_fopen(file, "rb"); + if (!fp) + goto freeout; + + outfp = claws_fopen(out, "wb"); + if (!outfp) { + claws_fclose(fp); + goto freeout; + } + + while (claws_fgets(buf, sizeof (buf), fp) != NULL) { + strcrchomp(buf); + if (claws_fputs(buf, outfp) == EOF) { + claws_fclose(fp); + claws_fclose(outfp); + goto unlinkout; + } + } + + claws_fclose(fp); + if (claws_safe_fclose(outfp) == EOF) { + goto unlinkout; + } + + if (move_file(out, file, TRUE) < 0) + goto unlinkout; + + g_free(out); + return 0; +unlinkout: + claws_unlink(out); +freeout: + g_free(out); + return -1; +} + +/* + * Append src file body to the tail of dest file. + * Now keep_backup has no effects. + */ +gint append_file(const gchar *src, const gchar *dest, gboolean keep_backup) +{ + FILE *src_fp, *dest_fp; + gint n_read; + gchar buf[BUFSIZ]; + + gboolean err = FALSE; + + if ((src_fp = claws_fopen(src, "rb")) == NULL) { + FILE_OP_ERROR(src, "claws_fopen"); + return -1; + } + + if ((dest_fp = claws_fopen(dest, "ab")) == NULL) { + FILE_OP_ERROR(dest, "claws_fopen"); + claws_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: %s", dest); + } + + while ((n_read = claws_fread(buf, sizeof(gchar), sizeof(buf), src_fp)) > 0) { + if (n_read < sizeof(buf) && claws_ferror(src_fp)) + break; + if (claws_fwrite(buf, 1, n_read, dest_fp) < n_read) { + g_warning("writing to %s failed.", dest); + claws_fclose(dest_fp); + claws_fclose(src_fp); + claws_unlink(dest); + return -1; + } + } + + if (claws_ferror(src_fp)) { + FILE_OP_ERROR(src, "claws_fread"); + err = TRUE; + } + claws_fclose(src_fp); + if (claws_fclose(dest_fp) == EOF) { + FILE_OP_ERROR(dest, "claws_fclose"); + err = TRUE; + } + + if (err) { + claws_unlink(dest); + return -1; + } + + return 0; +} + +gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup) +{ + FILE *src_fp, *dest_fp; + gint n_read; + gchar buf[BUFSIZ]; + gchar *dest_bak = NULL; + gboolean err = FALSE; + + 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"); + claws_fclose(src_fp); + g_free(dest_bak); + return -1; + } + } + + 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"); + g_free(dest_bak); + } + return -1; + } + + if (change_file_mode_rw(dest_fp, dest) < 0) { + FILE_OP_ERROR(dest, "chmod"); + g_warning("can't change file mode: %s", dest); + } + + while ((n_read = claws_fread(buf, sizeof(gchar), sizeof(buf), src_fp)) > 0) { + if (n_read < sizeof(buf) && claws_ferror(src_fp)) + break; + if (claws_fwrite(buf, 1, n_read, dest_fp) < n_read) { + g_warning("writing to %s failed.", dest); + claws_fclose(dest_fp); + claws_fclose(src_fp); + claws_unlink(dest); + if (dest_bak) { + if (rename_force(dest_bak, dest) < 0) + FILE_OP_ERROR(dest_bak, "rename"); + g_free(dest_bak); + } + return -1; + } + } + + if (claws_ferror(src_fp)) { + FILE_OP_ERROR(src, "claws_fread"); + err = TRUE; + } + claws_fclose(src_fp); + if (claws_safe_fclose(dest_fp) == EOF) { + FILE_OP_ERROR(dest, "claws_fclose"); + err = TRUE; + } + + if (err) { + claws_unlink(dest); + if (dest_bak) { + if (rename_force(dest_bak, dest) < 0) + FILE_OP_ERROR(dest_bak, "rename"); + g_free(dest_bak); + } + return -1; + } + + if (keep_backup == FALSE && dest_bak) + claws_unlink(dest_bak); + + g_free(dest_bak); + + return 0; +} + +gint move_file(const gchar *src, const gchar *dest, gboolean overwrite) +{ + if (overwrite == FALSE && is_file_exist(dest)) { + g_warning("move_file(): file %s already exists.", dest); + return -1; + } + + if (rename_force(src, dest) == 0) return 0; + + if (EXDEV != errno) { + FILE_OP_ERROR(src, "rename"); + return -1; + } + + if (copy_file(src, dest, FALSE) < 0) return -1; + + claws_unlink(src); + + return 0; +} + +gint copy_file_part_to_fp(FILE *fp, off_t offset, size_t length, FILE *dest_fp) +{ + gint n_read; + gint bytes_left, to_read; + gchar buf[BUFSIZ]; + + if (fseek(fp, offset, SEEK_SET) < 0) { + perror("fseek"); + return -1; + } + + bytes_left = length; + to_read = MIN(bytes_left, sizeof(buf)); + + while ((n_read = claws_fread(buf, sizeof(gchar), to_read, fp)) > 0) { + if (n_read < to_read && claws_ferror(fp)) + break; + if (claws_fwrite(buf, 1, n_read, dest_fp) < n_read) { + return -1; + } + bytes_left -= n_read; + if (bytes_left == 0) + break; + to_read = MIN(bytes_left, sizeof(buf)); + } + + if (claws_ferror(fp)) { + perror("claws_fread"); + return -1; + } + + return 0; +} + +gint copy_file_part(FILE *fp, off_t offset, size_t length, const gchar *dest) +{ + FILE *dest_fp; + gboolean err = FALSE; + + if ((dest_fp = claws_fopen(dest, "wb")) == NULL) { + FILE_OP_ERROR(dest, "claws_fopen"); + return -1; + } + + if (change_file_mode_rw(dest_fp, dest) < 0) { + FILE_OP_ERROR(dest, "chmod"); + g_warning("can't change file mode: %s", dest); + } + + if (copy_file_part_to_fp(fp, offset, length, dest_fp) < 0) + err = TRUE; + + if (claws_safe_fclose(dest_fp) == EOF) { + FILE_OP_ERROR(dest, "claws_fclose"); + err = TRUE; + } + + if (err) { + g_warning("writing to %s failed.", dest); + claws_unlink(dest); + return -1; + } + + return 0; +} + +gint canonicalize_file(const gchar *src, const gchar *dest) +{ + FILE *src_fp, *dest_fp; + gchar buf[BUFFSIZE]; + gint len; + gboolean err = FALSE; + gboolean last_linebreak = FALSE; + + if (src == NULL || dest == NULL) + return -1; + + if ((src_fp = claws_fopen(src, "rb")) == NULL) { + FILE_OP_ERROR(src, "claws_fopen"); + return -1; + } + + if ((dest_fp = claws_fopen(dest, "wb")) == NULL) { + FILE_OP_ERROR(dest, "claws_fopen"); + claws_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: %s", dest); + } + + while (claws_fgets(buf, sizeof(buf), src_fp) != NULL) { + gint r = 0; + + len = strlen(buf); + if (len == 0) break; + last_linebreak = FALSE; + + if (buf[len - 1] != '\n') { + last_linebreak = TRUE; + r = claws_fputs(buf, dest_fp); + } else if (len > 1 && buf[len - 1] == '\n' && buf[len - 2] == '\r') { + r = claws_fputs(buf, dest_fp); + } else { + if (len > 1) { + r = claws_fwrite(buf, 1, len - 1, dest_fp); + if (r != (len -1)) + r = EOF; + } + if (r != EOF) + r = claws_fputs("\r\n", dest_fp); + } + + if (r == EOF) { + g_warning("writing to %s failed.", dest); + claws_fclose(dest_fp); + claws_fclose(src_fp); + claws_unlink(dest); + return -1; + } + } + + if (last_linebreak == TRUE) { + if (claws_fputs("\r\n", dest_fp) == EOF) + err = TRUE; + } + + if (claws_ferror(src_fp)) { + FILE_OP_ERROR(src, "claws_fgets"); + err = TRUE; + } + claws_fclose(src_fp); + if (claws_safe_fclose(dest_fp) == EOF) { + FILE_OP_ERROR(dest, "claws_fclose"); + err = TRUE; + } + + if (err) { + claws_unlink(dest); + return -1; + } + + return 0; +} + +gint canonicalize_file_replace(const gchar *file) +{ + gchar *tmp_file; + + tmp_file = get_tmp_file(); + + if (canonicalize_file(file, tmp_file) < 0) { + g_free(tmp_file); + return -1; + } + + if (move_file(tmp_file, file, TRUE) < 0) { + g_warning("can't replace file: %s", file); + claws_unlink(tmp_file); + g_free(tmp_file); + return -1; + } + + g_free(tmp_file); + return 0; +} + + +gint str_write_to_file(const gchar *str, const gchar *file) +{ + FILE *fp; + size_t len; + + cm_return_val_if_fail(str != NULL, -1); + cm_return_val_if_fail(file != NULL, -1); + + if ((fp = claws_fopen(file, "wb")) == NULL) { + FILE_OP_ERROR(file, "claws_fopen"); + return -1; + } + + len = strlen(str); + if (len == 0) { + claws_fclose(fp); + return 0; + } + + if (claws_fwrite(str, 1, len, fp) != len) { + FILE_OP_ERROR(file, "claws_fwrite"); + claws_fclose(fp); + claws_unlink(file); + return -1; + } + + if (claws_safe_fclose(fp) == EOF) { + FILE_OP_ERROR(file, "claws_fclose"); + claws_unlink(file); + return -1; + } + + return 0; +} + +static gchar *file_read_stream_to_str_full(FILE *fp, gboolean recode) +{ + GByteArray *array; + guchar buf[BUFSIZ]; + gint n_read; + gchar *str; + + cm_return_val_if_fail(fp != NULL, NULL); + + array = g_byte_array_new(); + + while ((n_read = claws_fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) { + if (n_read < sizeof(buf) && claws_ferror(fp)) + break; + g_byte_array_append(array, buf, n_read); + } + + if (claws_ferror(fp)) { + FILE_OP_ERROR("file stream", "claws_fread"); + g_byte_array_free(array, TRUE); + return NULL; + } + + buf[0] = '\0'; + g_byte_array_append(array, buf, 1); + str = (gchar *)array->data; + g_byte_array_free(array, FALSE); + + if (recode && !g_utf8_validate(str, -1, NULL)) { + const gchar *src_codeset, *dest_codeset; + gchar *tmp = NULL; + src_codeset = conv_get_locale_charset_str(); + dest_codeset = CS_UTF_8; + tmp = conv_codeset_strdup(str, src_codeset, dest_codeset); + g_free(str); + str = tmp; + } + + return str; +} + +static gchar *file_read_to_str_full(const gchar *file, gboolean recode) +{ + FILE *fp; + gchar *str; + GStatBuf s; +#ifndef G_OS_WIN32 + gint fd, err; + struct timeval timeout = {1, 0}; + fd_set fds; + int fflags = 0; +#endif + + cm_return_val_if_fail(file != NULL, NULL); + + if (g_stat(file, &s) != 0) { + FILE_OP_ERROR(file, "stat"); + return NULL; + } + if (S_ISDIR(s.st_mode)) { + g_warning("%s: is a directory", file); + return NULL; + } + +#ifdef G_OS_WIN32 + fp = claws_fopen (file, "rb"); + if (fp == NULL) { + FILE_OP_ERROR(file, "open"); + return NULL; + } +#else + /* test whether the file is readable without blocking */ + fd = g_open(file, O_RDONLY | O_NONBLOCK, 0); + if (fd == -1) { + FILE_OP_ERROR(file, "open"); + return NULL; + } + + FD_ZERO(&fds); + FD_SET(fd, &fds); + + /* allow for one second */ + err = select(fd+1, &fds, NULL, NULL, &timeout); + if (err <= 0 || !FD_ISSET(fd, &fds)) { + if (err < 0) { + FILE_OP_ERROR(file, "select"); + } else { + g_warning("%s: doesn't seem readable", file); + } + close(fd); + return NULL; + } + + /* Now clear O_NONBLOCK */ + if ((fflags = fcntl(fd, F_GETFL)) < 0) { + FILE_OP_ERROR(file, "fcntl (F_GETFL)"); + close(fd); + return NULL; + } + if (fcntl(fd, F_SETFL, (fflags & ~O_NONBLOCK)) < 0) { + FILE_OP_ERROR(file, "fcntl (F_SETFL)"); + close(fd); + return NULL; + } + + /* get the FILE pointer */ + fp = claws_fdopen(fd, "rb"); + + if (fp == NULL) { + 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); + + claws_fclose(fp); + + return str; +} + +gchar *file_read_to_str(const gchar *file) +{ + return file_read_to_str_full(file, TRUE); +} +gchar *file_read_stream_to_str(FILE *fp) +{ + return file_read_stream_to_str_full(fp, TRUE); +} + +gchar *file_read_to_str_no_recode(const gchar *file) +{ + return file_read_to_str_full(file, FALSE); +} +gchar *file_read_stream_to_str_no_recode(FILE *fp) +{ + return file_read_stream_to_str_full(fp, FALSE); +} + +gint rename_force(const gchar *oldpath, const gchar *newpath) +{ +#ifndef G_OS_UNIX + if (!is_file_entry_exist(oldpath)) { + errno = ENOENT; + return -1; + } + if (is_file_exist(newpath)) { + if (claws_unlink(newpath) < 0) + FILE_OP_ERROR(newpath, "unlink"); + } +#endif + return g_rename(oldpath, newpath); +} + +gint copy_dir(const gchar *src, const gchar *dst) +{ + GDir *dir; + const gchar *name; + + if ((dir = g_dir_open(src, 0, NULL)) == NULL) { + g_warning("failed to open directory: %s", src); + return -1; + } + + if (make_dir(dst) < 0) + return -1; + + while ((name = g_dir_read_name(dir)) != NULL) { + gchar *old_file, *new_file; + old_file = g_strconcat(src, G_DIR_SEPARATOR_S, name, NULL); + new_file = g_strconcat(dst, G_DIR_SEPARATOR_S, name, NULL); + debug_print("copying: %s -> %s\n", old_file, new_file); + if (g_file_test(old_file, G_FILE_TEST_IS_REGULAR)) { + gint r = copy_file(old_file, new_file, TRUE); + if (r < 0) { + g_dir_close(dir); + return r; + } + } +#ifndef G_OS_WIN32 + /* Windows has no symlinks. Or well, Vista seems to + have something like this but the semantics might be + different. Thus we don't use it under Windows. */ + else if (g_file_test(old_file, G_FILE_TEST_IS_SYMLINK)) { + GError *error = NULL; + gint r = 0; + gchar *target = g_file_read_link(old_file, &error); + if (target) + r = symlink(target, new_file); + g_free(target); + if (r < 0) { + g_dir_close(dir); + return r; + } + } +#endif /*G_OS_WIN32*/ + else if (g_file_test(old_file, G_FILE_TEST_IS_DIR)) { + gint r = copy_dir(old_file, new_file); + if (r < 0) { + g_dir_close(dir); + return r; + } + } + } + g_dir_close(dir); + return 0; +} + +gint change_file_mode_rw(FILE *fp, const gchar *file) +{ +#if HAVE_FCHMOD + return fchmod(fileno(fp), S_IRUSR|S_IWUSR); +#else + return g_chmod(file, S_IRUSR|S_IWUSR); +#endif +} + +FILE *my_tmpfile(void) +{ + const gchar suffix[] = ".XXXXXX"; + const gchar *tmpdir; + guint tmplen; + const gchar *progname; + guint proglen; + gchar *fname; + gint fd; + FILE *fp; +#ifndef G_OS_WIN32 + gchar buf[2]="\0"; +#endif + + tmpdir = get_tmp_dir(); + tmplen = strlen(tmpdir); + progname = g_get_prgname(); + if (progname == NULL) + progname = "claws-mail"; + proglen = strlen(progname); + Xalloca(fname, tmplen + 1 + proglen + sizeof(suffix), + return tmpfile()); + + memcpy(fname, tmpdir, tmplen); + fname[tmplen] = G_DIR_SEPARATOR; + memcpy(fname + tmplen + 1, progname, proglen); + memcpy(fname + tmplen + 1 + proglen, suffix, sizeof(suffix)); + + fd = g_mkstemp(fname); + if (fd < 0) + return tmpfile(); + +#ifndef G_OS_WIN32 + claws_unlink(fname); + + /* verify that we can write in the file after unlinking */ + if (write(fd, buf, 1) < 0) { + close(fd); + return tmpfile(); + } + +#endif + + fp = claws_fdopen(fd, "w+b"); + if (!fp) + close(fd); + else { + rewind(fp); + return fp; + } + + return tmpfile(); +} + +FILE *get_tmpfile_in_dir(const gchar *dir, gchar **filename) +{ + int fd; + *filename = g_strdup_printf("%s%cclaws.XXXXXX", dir, G_DIR_SEPARATOR); + fd = g_mkstemp(*filename); + if (fd < 0) + return NULL; + return claws_fdopen(fd, "w+"); +} + +FILE *str_open_as_stream(const gchar *str) +{ + FILE *fp; + size_t len; + + cm_return_val_if_fail(str != NULL, NULL); + + fp = my_tmpfile(); + if (!fp) { + FILE_OP_ERROR("str_open_as_stream", "my_tmpfile"); + return NULL; + } + + len = strlen(str); + if (len == 0) return fp; + + if (claws_fwrite(str, 1, len, fp) != len) { + FILE_OP_ERROR("str_open_as_stream", "claws_fwrite"); + claws_fclose(fp); + return NULL; + } + + rewind(fp); + return fp; +} + +#endif diff --git a/src/common/file-utils.h b/src/common/file-utils.h @@ -0,0 +1,107 @@ +/* + * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client + * Copyright (C) 1999-2018 Colin Leroy and the Claws Mail team + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __CLAWS_IO_H__ +#define __CLAWS_IO_H__ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#include "claws-features.h" +#endif + +#include <stdio.h> +#include <glib.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); +int claws_unlink (const char *filename); + +gint file_strip_crs (const gchar *file); +gint append_file (const gchar *src, + const gchar *dest, + gboolean keep_backup); +gint copy_file (const gchar *src, + const gchar *dest, + gboolean keep_backup); +gint move_file (const gchar *src, + const gchar *dest, + gboolean overwrite); +gint copy_file_part_to_fp (FILE *fp, + off_t offset, + size_t length, + FILE *dest_fp); +gint copy_file_part (FILE *fp, + off_t offset, + size_t length, + const gchar *dest); +gint canonicalize_file (const gchar *src, + const gchar *dest); +gint canonicalize_file_replace (const gchar *file); +gint str_write_to_file (const gchar *str, + const gchar *file); +gchar *file_read_to_str (const gchar *file); +gchar *file_read_to_str_no_recode(const gchar *file); +gchar *file_read_stream_to_str (FILE *fp); +gchar *file_read_stream_to_str_no_recode(FILE *fp); + +gint rename_force (const gchar *oldpath, + const gchar *newpath); +gint copy_dir (const gchar *src, + const gchar *dest); +gint change_file_mode_rw (FILE *fp, + const gchar *file); +FILE *my_tmpfile (void); +FILE *get_tmpfile_in_dir (const gchar *dir, + gchar **filename); +FILE *str_open_as_stream (const gchar *str); +gint str_write_to_file (const gchar *str, + const gchar *file); + +#endif diff --git a/src/common/log.c b/src/common/log.c @@ -34,7 +34,7 @@ #include "utils.h" #include "log.h" #include "hooks.h" -#include "claws_io.h" +#include "file-utils.h" #define FWRITE(_b,_s,_n,_f) if (claws_fwrite(_b,_s,_n,_f) != _n) { \ g_message("log claws_fwrite failed!\n"); \ diff --git a/src/common/plugin.c b/src/common/plugin.c @@ -41,7 +41,7 @@ #include "prefs.h" #include "claws.h" #include "timing.h" -#include "claws_io.h" +#include "file-utils.h" #ifdef G_OS_WIN32 #define PLUGINS_BLOCK_PREFIX "PluginsWin32_" diff --git a/src/common/prefs.c b/src/common/prefs.c @@ -30,7 +30,7 @@ #include "prefs.h" #include "utils.h" -#include "claws_io.h" +#include "file-utils.h" static gboolean prefs_is_readonly (const gchar *path); diff --git a/src/common/ssl_certificate.c b/src/common/ssl_certificate.c @@ -46,7 +46,7 @@ #include "socket.h" #include "hooks.h" #include "defs.h" -#include "claws_io.h" +#include "file-utils.h" static GHashTable *warned_expired = NULL; diff --git a/src/common/tags.c b/src/common/tags.c @@ -40,7 +40,7 @@ #include "defs.h" #include "utils.h" #include "tags.h" -#include "claws_io.h" +#include "file-utils.h" static GHashTable *tags_table = NULL; static GHashTable *tags_reverse_table = NULL; diff --git a/src/common/template.c b/src/common/template.c @@ -29,7 +29,7 @@ #include "utils.h" #include "template.h" #include "codeconv.h" -#include "claws_io.h" +#include "file-utils.h" static GSList *template_list; diff --git a/src/common/utils.c b/src/common/utils.c @@ -86,7 +86,7 @@ #include "codeconv.h" #include "tlds.h" #include "timing.h" -#include "claws_io.h" +#include "file-utils.h" #define BUFFSIZE 8192 @@ -314,50 +314,6 @@ gchar *strcrchomp(gchar *str) return str; } -gint file_strip_crs(const gchar *file) -{ - FILE *fp = NULL, *outfp = NULL; - gchar buf[4096]; - gchar *out = get_tmp_file(); - if (file == NULL) - goto freeout; - - fp = claws_fopen(file, "rb"); - if (!fp) - goto freeout; - - outfp = claws_fopen(out, "wb"); - if (!outfp) { - claws_fclose(fp); - goto freeout; - } - - while (claws_fgets(buf, sizeof (buf), fp) != NULL) { - strcrchomp(buf); - if (claws_fputs(buf, outfp) == EOF) { - claws_fclose(fp); - claws_fclose(outfp); - goto unlinkout; - } - } - - claws_fclose(fp); - if (claws_safe_fclose(outfp) == EOF) { - goto unlinkout; - } - - if (move_file(out, file, TRUE) < 0) - goto unlinkout; - - g_free(out); - return 0; -unlinkout: - claws_unlink(out); -freeout: - g_free(out); - return -1; -} - /* Similar to `strstr' but this function ignores the case of both strings. */ gchar *strcasestr(const gchar *haystack, const gchar *needle) { @@ -2392,249 +2348,6 @@ gint remove_dir_recursive(const gchar *dir) return 0; } -gint rename_force(const gchar *oldpath, const gchar *newpath) -{ -#ifndef G_OS_UNIX - if (!is_file_entry_exist(oldpath)) { - errno = ENOENT; - return -1; - } - if (is_file_exist(newpath)) { - if (claws_unlink(newpath) < 0) - FILE_OP_ERROR(newpath, "unlink"); - } -#endif - return g_rename(oldpath, newpath); -} - -/* - * Append src file body to the tail of dest file. - * Now keep_backup has no effects. - */ -gint append_file(const gchar *src, const gchar *dest, gboolean keep_backup) -{ - FILE *src_fp, *dest_fp; - gint n_read; - gchar buf[BUFSIZ]; - - gboolean err = FALSE; - - if ((src_fp = claws_fopen(src, "rb")) == NULL) { - FILE_OP_ERROR(src, "claws_fopen"); - return -1; - } - - if ((dest_fp = claws_fopen(dest, "ab")) == NULL) { - FILE_OP_ERROR(dest, "claws_fopen"); - claws_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: %s", dest); - } - - while ((n_read = claws_fread(buf, sizeof(gchar), sizeof(buf), src_fp)) > 0) { - if (n_read < sizeof(buf) && claws_ferror(src_fp)) - break; - if (claws_fwrite(buf, 1, n_read, dest_fp) < n_read) { - g_warning("writing to %s failed.", dest); - claws_fclose(dest_fp); - claws_fclose(src_fp); - claws_unlink(dest); - return -1; - } - } - - if (claws_ferror(src_fp)) { - FILE_OP_ERROR(src, "claws_fread"); - err = TRUE; - } - claws_fclose(src_fp); - if (claws_fclose(dest_fp) == EOF) { - FILE_OP_ERROR(dest, "claws_fclose"); - err = TRUE; - } - - if (err) { - claws_unlink(dest); - return -1; - } - - return 0; -} - -gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup) -{ - FILE *src_fp, *dest_fp; - gint n_read; - gchar buf[BUFSIZ]; - gchar *dest_bak = NULL; - gboolean err = FALSE; - - 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"); - claws_fclose(src_fp); - g_free(dest_bak); - return -1; - } - } - - 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"); - g_free(dest_bak); - } - return -1; - } - - if (change_file_mode_rw(dest_fp, dest) < 0) { - FILE_OP_ERROR(dest, "chmod"); - g_warning("can't change file mode: %s", dest); - } - - while ((n_read = claws_fread(buf, sizeof(gchar), sizeof(buf), src_fp)) > 0) { - if (n_read < sizeof(buf) && claws_ferror(src_fp)) - break; - if (claws_fwrite(buf, 1, n_read, dest_fp) < n_read) { - g_warning("writing to %s failed.", dest); - claws_fclose(dest_fp); - claws_fclose(src_fp); - claws_unlink(dest); - if (dest_bak) { - if (rename_force(dest_bak, dest) < 0) - FILE_OP_ERROR(dest_bak, "rename"); - g_free(dest_bak); - } - return -1; - } - } - - if (claws_ferror(src_fp)) { - FILE_OP_ERROR(src, "claws_fread"); - err = TRUE; - } - claws_fclose(src_fp); - if (claws_safe_fclose(dest_fp) == EOF) { - FILE_OP_ERROR(dest, "claws_fclose"); - err = TRUE; - } - - if (err) { - claws_unlink(dest); - if (dest_bak) { - if (rename_force(dest_bak, dest) < 0) - FILE_OP_ERROR(dest_bak, "rename"); - g_free(dest_bak); - } - return -1; - } - - if (keep_backup == FALSE && dest_bak) - claws_unlink(dest_bak); - - g_free(dest_bak); - - return 0; -} - -gint move_file(const gchar *src, const gchar *dest, gboolean overwrite) -{ - if (overwrite == FALSE && is_file_exist(dest)) { - g_warning("move_file(): file %s already exists.", dest); - return -1; - } - - if (rename_force(src, dest) == 0) return 0; - - if (EXDEV != errno) { - FILE_OP_ERROR(src, "rename"); - return -1; - } - - if (copy_file(src, dest, FALSE) < 0) return -1; - - claws_unlink(src); - - return 0; -} - -gint copy_file_part_to_fp(FILE *fp, off_t offset, size_t length, FILE *dest_fp) -{ - gint n_read; - gint bytes_left, to_read; - gchar buf[BUFSIZ]; - - if (fseek(fp, offset, SEEK_SET) < 0) { - perror("fseek"); - return -1; - } - - bytes_left = length; - to_read = MIN(bytes_left, sizeof(buf)); - - while ((n_read = claws_fread(buf, sizeof(gchar), to_read, fp)) > 0) { - if (n_read < to_read && claws_ferror(fp)) - break; - if (claws_fwrite(buf, 1, n_read, dest_fp) < n_read) { - return -1; - } - bytes_left -= n_read; - if (bytes_left == 0) - break; - to_read = MIN(bytes_left, sizeof(buf)); - } - - if (claws_ferror(fp)) { - perror("claws_fread"); - return -1; - } - - return 0; -} - -gint copy_file_part(FILE *fp, off_t offset, size_t length, const gchar *dest) -{ - FILE *dest_fp; - gboolean err = FALSE; - - if ((dest_fp = claws_fopen(dest, "wb")) == NULL) { - FILE_OP_ERROR(dest, "claws_fopen"); - return -1; - } - - if (change_file_mode_rw(dest_fp, dest) < 0) { - FILE_OP_ERROR(dest, "chmod"); - g_warning("can't change file mode: %s", dest); - } - - if (copy_file_part_to_fp(fp, offset, length, dest_fp) < 0) - err = TRUE; - - if (claws_safe_fclose(dest_fp) == EOF) { - FILE_OP_ERROR(dest, "claws_fclose"); - err = TRUE; - } - - if (err) { - g_warning("writing to %s failed.", dest); - claws_unlink(dest); - return -1; - } - - return 0; -} - /* convert line endings into CRLF. If the last line doesn't end with * linebreak, add it. */ @@ -2671,109 +2384,6 @@ gchar *canonicalize_str(const gchar *str) return out; } -gint canonicalize_file(const gchar *src, const gchar *dest) -{ - FILE *src_fp, *dest_fp; - gchar buf[BUFFSIZE]; - gint len; - gboolean err = FALSE; - gboolean last_linebreak = FALSE; - - if (src == NULL || dest == NULL) - return -1; - - if ((src_fp = claws_fopen(src, "rb")) == NULL) { - FILE_OP_ERROR(src, "claws_fopen"); - return -1; - } - - if ((dest_fp = claws_fopen(dest, "wb")) == NULL) { - FILE_OP_ERROR(dest, "claws_fopen"); - claws_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: %s", dest); - } - - while (claws_fgets(buf, sizeof(buf), src_fp) != NULL) { - gint r = 0; - - len = strlen(buf); - if (len == 0) break; - last_linebreak = FALSE; - - if (buf[len - 1] != '\n') { - last_linebreak = TRUE; - r = claws_fputs(buf, dest_fp); - } else if (len > 1 && buf[len - 1] == '\n' && buf[len - 2] == '\r') { - r = claws_fputs(buf, dest_fp); - } else { - if (len > 1) { - r = claws_fwrite(buf, 1, len - 1, dest_fp); - if (r != (len -1)) - r = EOF; - } - if (r != EOF) - r = claws_fputs("\r\n", dest_fp); - } - - if (r == EOF) { - g_warning("writing to %s failed.", dest); - claws_fclose(dest_fp); - claws_fclose(src_fp); - claws_unlink(dest); - return -1; - } - } - - if (last_linebreak == TRUE) { - if (claws_fputs("\r\n", dest_fp) == EOF) - err = TRUE; - } - - if (claws_ferror(src_fp)) { - FILE_OP_ERROR(src, "claws_fgets"); - err = TRUE; - } - claws_fclose(src_fp); - if (claws_safe_fclose(dest_fp) == EOF) { - FILE_OP_ERROR(dest, "claws_fclose"); - err = TRUE; - } - - if (err) { - claws_unlink(dest); - return -1; - } - - return 0; -} - -gint canonicalize_file_replace(const gchar *file) -{ - gchar *tmp_file; - - tmp_file = get_tmp_file(); - - if (canonicalize_file(file, tmp_file) < 0) { - g_free(tmp_file); - return -1; - } - - if (move_file(tmp_file, file, TRUE) < 0) { - g_warning("can't replace file: %s", file); - claws_unlink(tmp_file); - g_free(tmp_file); - return -1; - } - - g_free(tmp_file); - return 0; -} - gchar *normalize_newlines(const gchar *str) { const gchar *p; @@ -2874,280 +2484,6 @@ gchar *generate_mime_boundary(const gchar *prefix) buf_uniq); } -gint change_file_mode_rw(FILE *fp, const gchar *file) -{ -#if HAVE_FCHMOD - return fchmod(fileno(fp), S_IRUSR|S_IWUSR); -#else - return g_chmod(file, S_IRUSR|S_IWUSR); -#endif -} - -FILE *my_tmpfile(void) -{ - const gchar suffix[] = ".XXXXXX"; - const gchar *tmpdir; - guint tmplen; - const gchar *progname; - guint proglen; - gchar *fname; - gint fd; - FILE *fp; -#ifndef G_OS_WIN32 - gchar buf[2]="\0"; -#endif - - tmpdir = get_tmp_dir(); - tmplen = strlen(tmpdir); - progname = g_get_prgname(); - if (progname == NULL) - progname = "claws-mail"; - proglen = strlen(progname); - Xalloca(fname, tmplen + 1 + proglen + sizeof(suffix), - return tmpfile()); - - memcpy(fname, tmpdir, tmplen); - fname[tmplen] = G_DIR_SEPARATOR; - memcpy(fname + tmplen + 1, progname, proglen); - memcpy(fname + tmplen + 1 + proglen, suffix, sizeof(suffix)); - - fd = g_mkstemp(fname); - if (fd < 0) - return tmpfile(); - -#ifndef G_OS_WIN32 - claws_unlink(fname); - - /* verify that we can write in the file after unlinking */ - if (write(fd, buf, 1) < 0) { - close(fd); - return tmpfile(); - } - -#endif - - fp = claws_fdopen(fd, "w+b"); - if (!fp) - close(fd); - else { - rewind(fp); - return fp; - } - - return tmpfile(); -} - -FILE *get_tmpfile_in_dir(const gchar *dir, gchar **filename) -{ - int fd; - *filename = g_strdup_printf("%s%cclaws.XXXXXX", dir, G_DIR_SEPARATOR); - fd = g_mkstemp(*filename); - if (fd < 0) - return NULL; - return claws_fdopen(fd, "w+"); -} - -FILE *str_open_as_stream(const gchar *str) -{ - FILE *fp; - size_t len; - - cm_return_val_if_fail(str != NULL, NULL); - - fp = my_tmpfile(); - if (!fp) { - FILE_OP_ERROR("str_open_as_stream", "my_tmpfile"); - return NULL; - } - - len = strlen(str); - if (len == 0) return fp; - - if (claws_fwrite(str, 1, len, fp) != len) { - FILE_OP_ERROR("str_open_as_stream", "claws_fwrite"); - claws_fclose(fp); - return NULL; - } - - rewind(fp); - return fp; -} - -gint str_write_to_file(const gchar *str, const gchar *file) -{ - FILE *fp; - size_t len; - - cm_return_val_if_fail(str != NULL, -1); - cm_return_val_if_fail(file != NULL, -1); - - if ((fp = claws_fopen(file, "wb")) == NULL) { - FILE_OP_ERROR(file, "claws_fopen"); - return -1; - } - - len = strlen(str); - if (len == 0) { - claws_fclose(fp); - return 0; - } - - if (claws_fwrite(str, 1, len, fp) != len) { - FILE_OP_ERROR(file, "claws_fwrite"); - claws_fclose(fp); - claws_unlink(file); - return -1; - } - - if (claws_safe_fclose(fp) == EOF) { - FILE_OP_ERROR(file, "claws_fclose"); - claws_unlink(file); - return -1; - } - - return 0; -} - -static gchar *file_read_stream_to_str_full(FILE *fp, gboolean recode) -{ - GByteArray *array; - guchar buf[BUFSIZ]; - gint n_read; - gchar *str; - - cm_return_val_if_fail(fp != NULL, NULL); - - array = g_byte_array_new(); - - while ((n_read = claws_fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) { - if (n_read < sizeof(buf) && claws_ferror(fp)) - break; - g_byte_array_append(array, buf, n_read); - } - - if (claws_ferror(fp)) { - FILE_OP_ERROR("file stream", "claws_fread"); - g_byte_array_free(array, TRUE); - return NULL; - } - - buf[0] = '\0'; - g_byte_array_append(array, buf, 1); - str = (gchar *)array->data; - g_byte_array_free(array, FALSE); - - if (recode && !g_utf8_validate(str, -1, NULL)) { - const gchar *src_codeset, *dest_codeset; - gchar *tmp = NULL; - src_codeset = conv_get_locale_charset_str(); - dest_codeset = CS_UTF_8; - tmp = conv_codeset_strdup(str, src_codeset, dest_codeset); - g_free(str); - str = tmp; - } - - return str; -} - -static gchar *file_read_to_str_full(const gchar *file, gboolean recode) -{ - FILE *fp; - gchar *str; - GStatBuf s; -#ifndef G_OS_WIN32 - gint fd, err; - struct timeval timeout = {1, 0}; - fd_set fds; - int fflags = 0; -#endif - - cm_return_val_if_fail(file != NULL, NULL); - - if (g_stat(file, &s) != 0) { - FILE_OP_ERROR(file, "stat"); - return NULL; - } - if (S_ISDIR(s.st_mode)) { - g_warning("%s: is a directory", file); - return NULL; - } - -#ifdef G_OS_WIN32 - fp = claws_fopen (file, "rb"); - if (fp == NULL) { - FILE_OP_ERROR(file, "open"); - return NULL; - } -#else - /* test whether the file is readable without blocking */ - fd = g_open(file, O_RDONLY | O_NONBLOCK, 0); - if (fd == -1) { - FILE_OP_ERROR(file, "open"); - return NULL; - } - - FD_ZERO(&fds); - FD_SET(fd, &fds); - - /* allow for one second */ - err = select(fd+1, &fds, NULL, NULL, &timeout); - if (err <= 0 || !FD_ISSET(fd, &fds)) { - if (err < 0) { - FILE_OP_ERROR(file, "select"); - } else { - g_warning("%s: doesn't seem readable", file); - } - close(fd); - return NULL; - } - - /* Now clear O_NONBLOCK */ - if ((fflags = fcntl(fd, F_GETFL)) < 0) { - FILE_OP_ERROR(file, "fcntl (F_GETFL)"); - close(fd); - return NULL; - } - if (fcntl(fd, F_SETFL, (fflags & ~O_NONBLOCK)) < 0) { - FILE_OP_ERROR(file, "fcntl (F_SETFL)"); - close(fd); - return NULL; - } - - /* get the FILE pointer */ - fp = claws_fdopen(fd, "rb"); - - if (fp == NULL) { - 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); - - claws_fclose(fp); - - return str; -} - -gchar *file_read_to_str(const gchar *file) -{ - return file_read_to_str_full(file, TRUE); -} -gchar *file_read_stream_to_str(FILE *fp) -{ - return file_read_stream_to_str_full(fp, TRUE); -} - -gchar *file_read_to_str_no_recode(const gchar *file) -{ - return file_read_to_str_full(file, FALSE); -} -gchar *file_read_stream_to_str_no_recode(FILE *fp) -{ - return file_read_stream_to_str_full(fp, FALSE); -} - char *fgets_crlf(char *buf, int size, FILE *stream) { gboolean is_cr = FALSE; @@ -4592,60 +3928,6 @@ void mailcap_update_default(const gchar *type, const gchar *command) g_free(outpath); } -gint copy_dir(const gchar *src, const gchar *dst) -{ - GDir *dir; - const gchar *name; - - if ((dir = g_dir_open(src, 0, NULL)) == NULL) { - g_warning("failed to open directory: %s", src); - return -1; - } - - if (make_dir(dst) < 0) - return -1; - - while ((name = g_dir_read_name(dir)) != NULL) { - gchar *old_file, *new_file; - old_file = g_strconcat(src, G_DIR_SEPARATOR_S, name, NULL); - new_file = g_strconcat(dst, G_DIR_SEPARATOR_S, name, NULL); - debug_print("copying: %s -> %s\n", old_file, new_file); - if (g_file_test(old_file, G_FILE_TEST_IS_REGULAR)) { - gint r = copy_file(old_file, new_file, TRUE); - if (r < 0) { - g_dir_close(dir); - return r; - } - } -#ifndef G_OS_WIN32 - /* Windows has no symlinks. Or well, Vista seems to - have something like this but the semantics might be - different. Thus we don't use it under Windows. */ - else if (g_file_test(old_file, G_FILE_TEST_IS_SYMLINK)) { - GError *error = NULL; - gint r = 0; - gchar *target = g_file_read_link(old_file, &error); - if (target) - r = symlink(target, new_file); - g_free(target); - if (r < 0) { - g_dir_close(dir); - return r; - } - } -#endif /*G_OS_WIN32*/ - else if (g_file_test(old_file, G_FILE_TEST_IS_DIR)) { - gint r = copy_dir(old_file, new_file); - if (r < 0) { - g_dir_close(dir); - return r; - } - } - } - g_dir_close(dir); - return 0; -} - /* crude test to see if a file is an email. */ gboolean file_is_email (const gchar *filename) { @@ -5046,49 +4328,10 @@ size_t fast_strftime(gchar *buf, gint buflen, const gchar *format, struct tm *lt return total_done; } -gboolean prefs_common_get_use_shred(void); - - #ifdef G_OS_WIN32 #define WEXITSTATUS(x) (x) #endif -int claws_unlink(const gchar *filename) -{ - GStatBuf s; - static int found_shred = -1; - static const gchar *args[4]; - - if (filename == NULL) - return 0; - - if (prefs_common_get_use_shred()) { - if (found_shred == -1) { - /* init */ - args[0] = g_find_program_in_path("shred"); - debug_print("found shred: %s\n", args[0]); - found_shred = (args[0] != NULL) ? 1:0; - args[1] = "-f"; - args[3] = NULL; - } - if (found_shred == 1) { - if (g_stat(filename, &s) == 0 && S_ISREG(s.st_mode)) { - if (s.st_nlink == 1) { - gint status=0; - args[2] = filename; - g_spawn_sync(NULL, (gchar **)args, NULL, 0, - NULL, NULL, NULL, NULL, &status, NULL); - debug_print("%s %s exited with status %d\n", - args[0], filename, WEXITSTATUS(status)); - if (truncate(filename, 0) < 0) - g_warning("couln't truncate: %s", filename); - } - } - } - } - return g_unlink(filename); -} - GMutex *cm_mutex_new(void) { #if GLIB_CHECK_VERSION(2,32,0) GMutex *m = g_new0(GMutex, 1); diff --git a/src/common/utils.h b/src/common/utils.h @@ -281,7 +281,6 @@ gchar *strretchomp (gchar *str); gchar *strtailchomp (gchar *str, gchar tail_char); gchar *strcrchomp (gchar *str); -gint file_strip_crs (const gchar *file); gchar *strcasestr (const gchar *haystack, const gchar *needle); gchar *strncasestr (const gchar *haystack, @@ -427,50 +426,11 @@ gint remove_numbered_files_not_in_list(const gchar *dir, GSList *numberlist); gint remove_all_numbered_files (const gchar *dir); gint remove_dir_recursive (const gchar *dir); -gint append_file (const gchar *src, - const gchar *dest, - gboolean keep_backup); -gint rename_force (const gchar *oldpath, - const gchar *newpath); -gint copy_file (const gchar *src, - const gchar *dest, - gboolean keep_backup); -gint move_file (const gchar *src, - const gchar *dest, - gboolean overwrite); -gint copy_dir (const gchar *src, - const gchar *dest); -gint copy_file_part_to_fp (FILE *fp, - off_t offset, - size_t length, - FILE *dest_fp); -gint copy_file_part (FILE *fp, - off_t offset, - size_t length, - const gchar *dest); - gchar *canonicalize_str (const gchar *str); -gint canonicalize_file (const gchar *src, - const gchar *dest); -gint canonicalize_file_replace (const gchar *file); - gchar *normalize_newlines (const gchar *str); gchar *get_outgoing_rfc2822_str (FILE *fp); -gint change_file_mode_rw (FILE *fp, - const gchar *file); -FILE *my_tmpfile (void); -FILE *get_tmpfile_in_dir (const gchar *dir, - gchar **filename); -FILE *str_open_as_stream (const gchar *str); -gint str_write_to_file (const gchar *str, - const gchar *file); -gchar *file_read_to_str (const gchar *file); -gchar *file_read_stream_to_str (FILE *fp); -gchar *file_read_to_str_no_recode(const gchar *file); -gchar *file_read_stream_to_str_no_recode(FILE *fp); - char *fgets_crlf(char *buf, int size, FILE *stream); /* process execution */ @@ -563,8 +523,6 @@ gboolean file_is_email(const gchar *filename); gboolean sc_g_list_bigger(GList *list, gint max); gboolean sc_g_slist_bigger(GSList *list, gint max); -int claws_unlink(const gchar *filename); - GMutex *cm_mutex_new(void); void cm_mutex_free(GMutex *mutex); diff --git a/src/common/xml.c b/src/common/xml.c @@ -30,7 +30,7 @@ #include "xml.h" #include "utils.h" #include "codeconv.h" -#include "claws_io.h" +#include "file-utils.h" #define SPARSE_MEMORY /* if this is defined all attr.names and tag.names are stored diff --git a/src/common/xmlprops.c b/src/common/xmlprops.c @@ -45,7 +45,7 @@ #include "mgutils.h" #include "xmlprops.h" #include "utils.h" -#include "claws_io.h" +#include "file-utils.h" /* Element tag names */ #define XMLS_ELTAG_PROP_LIST "property-list" diff --git a/src/compose.c b/src/compose.c @@ -107,7 +107,7 @@ #include "autofaces.h" #include "spell_entry.h" #include "headers.h" -#include "claws_io.h" +#include "file-utils.h" #ifdef USE_LDAP #include "password.h" diff --git a/src/editaddress.c b/src/editaddress.c @@ -44,6 +44,7 @@ #include "prefs_common.h" #include "menu.h" #include "combobox.h" +#include "file-utils.h" /* transient data */ static struct _PersonEdit_dlg personeditdlg; diff --git a/src/enriched.c b/src/enriched.c @@ -29,7 +29,7 @@ #include "enriched.h" #include "utils.h" -#include "claws_io.h" +#include "file-utils.h" #define ERTFBUFSIZE 8192 diff --git a/src/etpan/imap-thread.c b/src/etpan/imap-thread.c @@ -44,7 +44,7 @@ #include "utils.h" #include "mainwindow.h" #include "proxy.h" -#include "claws_io.h" +#include "file-utils.h" #include "ssl.h" #include "ssl_certificate.h" #include "socket.h" diff --git a/src/exporthtml.c b/src/exporthtml.c @@ -46,7 +46,7 @@ #include "utils.h" #include "exporthtml.h" #include "xmlprops.h" -#include "claws_io.h" +#include "file-utils.h" #ifdef MKDIR_TAKES_ONE_ARG #undef mkdir diff --git a/src/exportldif.c b/src/exportldif.c @@ -38,7 +38,7 @@ #include "exportldif.h" #include "xmlprops.h" #include "ldif.h" -#include "claws_io.h" +#include "file-utils.h" #ifdef MKDIR_TAKES_ONE_ARG diff --git a/src/file_checker.c b/src/file_checker.c @@ -35,6 +35,7 @@ #include <string.h> #include <ctype.h> +#include "file-utils.h" #include "utils.h" #include "alertpanel.h" #include "folder.h" diff --git a/src/folder.c b/src/folder.c @@ -63,7 +63,7 @@ #include "privacy.h" #include "prefs_common.h" #include "prefs_migration.h" -#include "claws_io.h" +#include "file-utils.h" /* Dependecies to be removed ?! */ #include "prefs_account.h" diff --git a/src/gtk/about.c b/src/gtk/about.c @@ -43,7 +43,7 @@ #include "menu.h" #include "textview.h" #include "main.h" -#include "claws_io.h" +#include "file-utils.h" extern SessionStats session_stats; static GtkTextBuffer *stats_text_buffer; diff --git a/src/html.c b/src/html.c @@ -30,7 +30,7 @@ #include "codeconv.h" #include "utils.h" #include "entity.h" -#include "claws_io.h" +#include "file-utils.h" #define SC_HTMLBUFSIZE 8192 #define HR_STR "────────────────────────────────────────────────" diff --git a/src/image_viewer.c b/src/image_viewer.c @@ -27,6 +27,7 @@ #include <gtk/gtk.h> #include "procmime.h" +#include "file-utils.h" #include "utils.h" #include "mimeview.h" diff --git a/src/imap.c b/src/imap.c @@ -71,7 +71,7 @@ #include "tags.h" #include "main.h" #include "passwordstore.h" -#include "claws_io.h" +#include "file-utils.h" typedef struct _IMAPFolder IMAPFolder; typedef struct _IMAPSession IMAPSession; diff --git a/src/inc.c b/src/inc.c @@ -45,6 +45,7 @@ #include "pop.h" #include "recv.h" #include "mbox.h" +#include "file-utils.h" #include "utils.h" #include "gtkutils.h" #include "statusbar.h" diff --git a/src/jpilot.c b/src/jpilot.c @@ -56,7 +56,7 @@ #include "codeconv.h" #include "adbookbase.h" #include "utils.h" -#include "claws_io.h" +#include "file-utils.h" #define JPILOT_DBHOME_DIR ".jpilot" #define JPILOT_DBHOME_FILE "AddressDB.pdb" diff --git a/src/ldapquery.c b/src/ldapquery.c @@ -38,7 +38,7 @@ #include "ldapctrl.h" #include "ldapserver.h" #include "mgutils.h" -#include "claws_io.h" +#include "file-utils.h" #include "addritem.h" #include "addrcache.h" diff --git a/src/ldif.c b/src/ldif.c @@ -32,7 +32,7 @@ #include "addrcache.h" #include "utils.h" -#include "claws_io.h" +#include "file-utils.h" #define LDIF_SEP_TAG ':' #define LDIF_LANG_TAG ';' diff --git a/src/main.c b/src/main.c @@ -132,7 +132,7 @@ #include "advsearch.h" #include "avatars.h" #include "passwordstore.h" -#include "claws_io.h" +#include "file-utils.h" #ifdef HAVE_LIBETPAN #include "imap-thread.h" diff --git a/src/matcher.c b/src/matcher.c @@ -49,7 +49,7 @@ #include "tags.h" #include "folder_item_prefs.h" #include "procmsg.h" -#include "claws_io.h" +#include "file-utils.h" /*! *\brief Keyword lookup element diff --git a/src/mbox.c b/src/mbox.c @@ -55,7 +55,7 @@ #include "filtering.h" #include "alertpanel.h" #include "statusbar.h" -#include "claws_io.h" +#include "file-utils.h" #define MESSAGEBUFSIZE 8192 diff --git a/src/messageview.c b/src/messageview.c @@ -67,7 +67,7 @@ #include "statusbar.h" #include "folder_item_prefs.h" #include "avatars.h" -#include "claws_io.h" +#include "file-utils.h" #ifndef USE_ALT_ADDRBOOK #include "addressbook.h" diff --git a/src/mh.c b/src/mh.c @@ -44,7 +44,7 @@ #include "gtkutils.h" #include "timing.h" #include "msgcache.h" -#include "claws_io.h" +#include "file-utils.h" /* Define possible missing constants for Windows. */ #ifdef G_OS_WIN32 diff --git a/src/mimeview.c b/src/mimeview.c @@ -55,7 +55,7 @@ #include "timing.h" #include "manage_window.h" #include "privacy.h" -#include "claws_io.h" +#include "file-utils.h" typedef enum { diff --git a/src/msgcache.c b/src/msgcache.c @@ -46,7 +46,7 @@ #include "timing.h" #include "tags.h" #include "prefs_common.h" -#include "claws_io.h" +#include "file-utils.h" #if G_BYTE_ORDER == G_BIG_ENDIAN #define bswap_32(x) \ diff --git a/src/mutt.c b/src/mutt.c @@ -31,7 +31,7 @@ #include "mutt.h" #include "addritem.h" #include "addrcache.h" -#include "claws_io.h" +#include "file-utils.h" #define MUTT_HOME_FILE ".muttrc" #define MUTTBUFSIZE 2048 diff --git a/src/news.c b/src/news.c @@ -62,7 +62,7 @@ # include "ssl.h" #endif #include "main.h" -#include "claws_io.h" +#include "file-utils.h" #define NNTP_PORT 119 #ifdef USE_GNUTLS diff --git a/src/partial_download.c b/src/partial_download.c @@ -63,7 +63,7 @@ #include "folder.h" #include "procheader.h" #include "msgcache.h" -#include "claws_io.h" +#include "file-utils.h" int partial_msg_in_uidl_list(MsgInfo *msginfo) { diff --git a/src/passwordstore.c b/src/passwordstore.c @@ -37,7 +37,7 @@ #include "prefs_common.h" #include "prefs_gtk.h" #include "prefs_migration.h" -#include "claws_io.h" +#include "file-utils.h" static GSList *_password_store; diff --git a/src/pine.c b/src/pine.c @@ -30,7 +30,7 @@ #include "pine.h" #include "addritem.h" #include "addrcache.h" -#include "claws_io.h" +#include "file-utils.h" #define PINE_HOME_FILE ".addressbook" #define PINEBUFSIZE 2048 diff --git a/src/plugins/acpi_notifier/acpi_notifier.c b/src/plugins/acpi_notifier/acpi_notifier.c @@ -47,7 +47,7 @@ #include "utils.h" #include "folder_item_prefs.h" #include "gtkcmoptionmenu.h" -#include "claws_io.h" +#include "file-utils.h" #define PREFS_BLOCK_NAME "AcpiNotifier" #define PLUGIN_NAME _("Acpi Notifier") diff --git a/src/plugins/archive/archiver_gtk.c b/src/plugins/archive/archiver_gtk.c @@ -41,6 +41,7 @@ #include "common/md5.h" #include "plugin.h" #include "mainwindow.h" +#include "file-utils.h" #include "utils.h" #include "prefs.h" #include "folder.h" diff --git a/src/plugins/bogofilter/bogofilter.c b/src/plugins/bogofilter/bogofilter.c @@ -52,7 +52,7 @@ #include "prefs_common.h" #include "alertpanel.h" #include "addr_compl.h" -#include "claws_io.h" +#include "file-utils.h" #ifdef HAVE_SYSEXITS_H #include <sysexits.h> diff --git a/src/plugins/clamd/libclamd/clamd-plugin.c b/src/plugins/clamd/libclamd/clamd-plugin.c @@ -55,7 +55,7 @@ #include "statusbar.h" #include "alertpanel.h" #include "clamd-plugin.h" -#include "claws_io.h" +#include "file-utils.h" #ifndef UNIX_PATH_MAX #define UNIX_PATH_MAX 108 diff --git a/src/plugins/dillo/dillo_viewer.c b/src/plugins/dillo/dillo_viewer.c @@ -35,6 +35,7 @@ #include "common/claws.h" #include "common/version.h" #include "plugin.h" +#include "file-utils.h" #include "utils.h" #include "mimeview.h" #include "addr_compl.h" diff --git a/src/plugins/fancy/fancy_prefs.c b/src/plugins/fancy/fancy_prefs.c @@ -30,6 +30,7 @@ #include "claws.h" #include "plugin.h" #include "gtkutils.h" +#include "file-utils.h" #include "utils.h" #include "prefs.h" #include "prefs_common.h" diff --git a/src/plugins/fancy/fancy_viewer.c b/src/plugins/fancy/fancy_viewer.c @@ -28,7 +28,7 @@ #include <fancy_viewer.h> #include <fancy_prefs.h> #include <alertpanel.h> -#include <claws_io.h> +#include <file-utils.h> #include <printing.h> #include <webkit/webkithittestresult.h> diff --git a/src/plugins/libravatar/libravatar_cache.c b/src/plugins/libravatar/libravatar_cache.c @@ -19,6 +19,7 @@ #include <sys/stat.h> #include "libravatar_cache.h" +#include "file-utils.h" #include "utils.h" gchar *libravatar_cache_init(const char *dirs[], gint start, gint end) diff --git a/src/plugins/libravatar/libravatar_image.c b/src/plugins/libravatar/libravatar_image.c @@ -27,7 +27,7 @@ #include <common/claws.h> #include <prefs_common.h> -#include <claws_io.h> +#include <file-utils.h> #include "libravatar.h" #include "libravatar_prefs.h" diff --git a/src/plugins/libravatar/libravatar_missing.c b/src/plugins/libravatar/libravatar_missing.c @@ -21,7 +21,7 @@ #include "libravatar_missing.h" #include "libravatar_prefs.h" #include "utils.h" -#include "claws_io.h" +#include "file-utils.h" /** * Loads the hash table of md5sum → time from the given filename. diff --git a/src/plugins/mailmbox/mailimf.c b/src/plugins/mailmbox/mailimf.c @@ -39,7 +39,7 @@ #endif #include "mailimf.h" -#include "claws_io.h" +#include "file-utils.h" /* RFC 2822 diff --git a/src/plugins/mailmbox/mailimf_write.c b/src/plugins/mailmbox/mailimf_write.c @@ -43,7 +43,7 @@ #include <time.h> #include <string.h> #include <ctype.h> -#include "claws_io.h" +#include "file-utils.h" #define MAX_MAIL_COL 72 diff --git a/src/plugins/mailmbox/mailmbox.c b/src/plugins/mailmbox/mailmbox.c @@ -58,8 +58,8 @@ #include "mmapstring.h" #include "mailmbox_parse.h" #include "maillock.h" +#include "file-utils.h" #include "utils.h" -#include "claws_io.h" /* http://www.qmail.org/qmail-manual-html/man5/mbox.html diff --git a/src/plugins/mailmbox/mailmbox_folder.c b/src/plugins/mailmbox/mailmbox_folder.c @@ -56,7 +56,7 @@ #include "mailmbox.h" #include "mailmbox_folder.h" #include "mailmbox_parse.h" -#include "claws_io.h" +#include "file-utils.h" #define MAILMBOX_CACHE_DIR "mailmboxcache" diff --git a/src/plugins/newmail/newmail.c b/src/plugins/newmail/newmail.c @@ -31,7 +31,7 @@ #include <inttypes.h> #include "plugin.h" -#include "claws_io.h" +#include "file-utils.h" #define LOG_NAME "NewLog" #define DEFAULT_DIR "Mail" diff --git a/src/plugins/pdf_viewer/poppler_viewer.c b/src/plugins/pdf_viewer/poppler_viewer.c @@ -31,6 +31,7 @@ #include "gtk/inputdialog.h" #include "mimeview.h" #include "summaryview.h" +#include "file-utils.h" #ifndef POPPLER_WITH_GDK #include "stdbool.h" #endif diff --git a/src/plugins/perl/perl_plugin.c b/src/plugins/perl/perl_plugin.c @@ -45,7 +45,7 @@ #include "common/log.h" #include "common/plugin.h" #include "common/tags.h" -#include "claws_io.h" +#include "file-utils.h" #include <EXTERN.h> #include <perl.h> diff --git a/src/plugins/pgpcore/pgp_utils.c b/src/plugins/pgpcore/pgp_utils.c @@ -30,7 +30,7 @@ #include "pgp_utils.h" #include "codeconv.h" -#include "claws_io.h" +#include "file-utils.h" gchar *fp_read_noconv(FILE *fp) { diff --git a/src/plugins/pgpcore/sgpgme.c b/src/plugins/pgpcore/sgpgme.c @@ -59,7 +59,7 @@ #include "account.h" #include "select-keys.h" #include "claws.h" -#include "claws_io.h" +#include "file-utils.h" static void sgpgme_disable_all(void) { diff --git a/src/plugins/pgpinline/pgpinline.c b/src/plugins/pgpinline/pgpinline.c @@ -28,7 +28,7 @@ #include <glib/gi18n.h> #include <errno.h> #include <gpgme.h> -#include <claws_io.h> +#include <file-utils.h> #include "utils.h" #include "privacy.h" diff --git a/src/plugins/pgpmime/pgpmime.c b/src/plugins/pgpmime/pgpmime.c @@ -42,7 +42,7 @@ #include <plugins/pgpcore/pgp_utils.h> #include "prefs_common.h" -#include "claws_io.h" +#include "file-utils.h" typedef struct _PrivacyDataPGP PrivacyDataPGP; diff --git a/src/plugins/python/python_plugin.c b/src/plugins/python/python_plugin.c @@ -39,7 +39,7 @@ #include "python-shell.h" #include "python-hooks.h" #include "clawsmailmodule.h" -#include "claws_io.h" +#include "file-utils.h" #define PYTHON_SCRIPTS_BASE_DIR "python-scripts" #define PYTHON_SCRIPTS_MAIN_DIR "main" diff --git a/src/plugins/rssyl/opml_export.c b/src/plugins/rssyl/opml_export.c @@ -32,7 +32,7 @@ #include <log.h> #include <folder.h> #include <common/utils.h> -#include <claws_io.h> +#include <file-utils.h> /* Local includes */ #include "libfeed/date.h" diff --git a/src/plugins/rssyl/rssyl.c b/src/plugins/rssyl/rssyl.c @@ -33,7 +33,6 @@ #include <folder.h> #include <procmsg.h> #include <localfolder.h> -#include <common/utils.h> #include <main.h> #include <mh.h> #include <xml.h> @@ -41,6 +40,7 @@ #include <prefs_common.h> #include <prefs_toolbar.h> #include <utils.h> +#include <file-utils.h> /* Local includes */ #include "libfeed/feeditem.h" diff --git a/src/plugins/rssyl/rssyl_add_item.c b/src/plugins/rssyl/rssyl_add_item.c @@ -34,7 +34,7 @@ #include <codeconv.h> #include <procmsg.h> #include <common/utils.h> -#include <claws_io.h> +#include <file-utils.h> /* Local includes */ #include "libfeed/date.h" diff --git a/src/plugins/rssyl/rssyl_deleted.c b/src/plugins/rssyl/rssyl_deleted.c @@ -31,7 +31,7 @@ /* Claws Mail includes */ #include <codeconv.h> #include <common/utils.h> -#include <claws_io.h> +#include <file-utils.h> /* Local includes */ #include "rssyl.h" diff --git a/src/plugins/rssyl/rssyl_update_format.c b/src/plugins/rssyl/rssyl_update_format.c @@ -38,6 +38,7 @@ #include "rssyl.h" #include "rssyl_feed.h" #include "strutils.h" +#include "file-utils.h" struct _RUpdateFormatCtx { FolderItem *o_prev; diff --git a/src/plugins/smime/smime.c b/src/plugins/smime/smime.c @@ -43,7 +43,7 @@ #include "prefs_common.h" #include "procmime.h" #include "plugin.h" -#include "claws_io.h" +#include "file-utils.h" typedef struct _PrivacyDataPGP PrivacyDataPGP; diff --git a/src/plugins/spam_report/spam_report.c b/src/plugins/spam_report/spam_report.c @@ -35,6 +35,7 @@ #include "password.h" #include "plugin.h" #include "prefs_common.h" +#include "file-utils.h" #include "utils.h" #include "spam_report_prefs.h" #include "statusbar.h" diff --git a/src/plugins/spamassassin/libspamc.c b/src/plugins/spamassassin/libspamc.c @@ -70,6 +70,7 @@ #endif /* must load *after* errno.h, Bug 6697 */ +#include "file-utils.h" #include "utils.h" /* RedHat 5.2 doesn't define Shutdown 2nd Parameter Constants */ diff --git a/src/plugins/spamassassin/spamassassin.c b/src/plugins/spamassassin/spamassassin.c @@ -51,7 +51,7 @@ #include "prefs_common.h" #include "alertpanel.h" #include "addr_compl.h" -#include "claws_io.h" +#include "file-utils.h" #ifdef HAVE_SYSEXITS_H #include <sysexits.h> diff --git a/src/plugins/tnef_parse/tnef_parse.c b/src/plugins/tnef_parse/tnef_parse.c @@ -48,7 +48,7 @@ #include "plugin.h" #include "procmime.h" #include "utils.h" -#include "claws_io.h" +#include "file-utils.h" #include "tnef_dump.h" diff --git a/src/plugins/vcalendar/vcal_folder.c b/src/plugins/vcalendar/vcal_folder.c @@ -37,6 +37,7 @@ #include <ctype.h> #include "account.h" +#include "file-utils.h" #include "utils.h" #include "procmsg.h" #include "procheader.h" diff --git a/src/plugins/vcalendar/vcal_manager.c b/src/plugins/vcalendar/vcal_manager.c @@ -49,6 +49,7 @@ #include <time.h> #include "folder.h" #include "quoted-printable.h" +#include "file-utils.h" #include "utils.h" #include "defs.h" diff --git a/src/plugins/vcalendar/vcal_meeting_gtk.c b/src/plugins/vcalendar/vcal_meeting_gtk.c @@ -54,7 +54,7 @@ #include "gtkutils.h" #include "log.h" #include "utils.h" -#include "claws_io.h" +#include "file-utils.h" struct _VCalMeeting { diff --git a/src/plugins/vcalendar/vcalendar.c b/src/plugins/vcalendar/vcalendar.c @@ -36,6 +36,7 @@ #include "folder.h" #include "folder_item_prefs.h" #include "mimeview.h" +#include "file-utils.h" #include "utils.h" #include "vcalendar.h" #include "vcal_manager.h" @@ -54,7 +55,6 @@ #include "statusbar.h" #include "timing.h" #include "inc.h" -#include "claws_io.h" MimeViewerFactory vcal_viewer_factory; diff --git a/src/pop.c b/src/pop.c @@ -40,7 +40,7 @@ #include "partial_download.h" #include "log.h" #include "hooks.h" -#include "claws_io.h" +#include "file-utils.h" static gint pop3_greeting_recv (Pop3Session *session, const gchar *msg); diff --git a/src/prefs_account.c b/src/prefs_account.c @@ -65,7 +65,7 @@ #include "inputdialog.h" #include "ssl_certificate.h" #include "passwordstore.h" -#include "claws_io.h" +#include "file-utils.h" static gboolean cancelled; static gboolean new_account; diff --git a/src/prefs_actions.c b/src/prefs_actions.c @@ -51,7 +51,7 @@ #include "prefs_filtering_action.h" #include "matcher_parser.h" #include "prefs_toolbar.h" -#include "claws_io.h" +#include "file-utils.h" enum { PREFS_ACTIONS_STRING, /*!< string pointer managed by list store, diff --git a/src/prefs_common.c b/src/prefs_common.c @@ -61,7 +61,7 @@ #include "prefswindow.h" #include "colorlabel.h" #include "passwordstore.h" -#include "claws_io.h" +#include "file-utils.h" #ifndef USE_ALT_ADDRBOOK #include "addrcustomattr.h" diff --git a/src/prefs_customheader.c b/src/prefs_customheader.c @@ -48,7 +48,7 @@ #include "alertpanel.h" #include "filesel.h" #include "combobox.h" -#include "claws_io.h" +#include "file-utils.h" enum { CUSTHDR_STRING, /*!< display string managed by list store */ diff --git a/src/prefs_display_header.c b/src/prefs_display_header.c @@ -41,7 +41,7 @@ #include "displayheader.h" #include "utils.h" #include "gtkutils.h" -#include "claws_io.h" +#include "file-utils.h" enum { PREFS_HDR_HEADER, diff --git a/src/prefs_gtk.c b/src/prefs_gtk.c @@ -41,7 +41,7 @@ #include "gtkutils.h" #include "password.h" #include "codeconv.h" -#include "claws_io.h" +#include "file-utils.h" #define CL(x) (((gulong) (x) >> (gulong) 8) & 0xFFUL) #define RGB_FROM_GDK_COLOR(c) \ diff --git a/src/prefs_themes.c b/src/prefs_themes.c @@ -48,7 +48,7 @@ #include "compose.h" #include "alertpanel.h" #include "addr_compl.h" -#include "claws_io.h" +#include "file-utils.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) diff --git a/src/procheader.c b/src/procheader.c @@ -41,7 +41,7 @@ #include "hooks.h" #include "utils.h" #include "defs.h" -#include "claws_io.h" +#include "file-utils.h" #define BUFFSIZE 8192 diff --git a/src/procmime.c b/src/procmime.c @@ -52,7 +52,7 @@ #include "timing.h" #include "privacy.h" #include "account.h" -#include "claws_io.h" +#include "file-utils.h" static GHashTable *procmime_get_mime_type_table (void); static MimeInfo *procmime_scan_file_short(const gchar *filename); diff --git a/src/procmsg.c b/src/procmsg.c @@ -49,7 +49,7 @@ #include "timing.h" #include "inc.h" #include "privacy.h" -#include "claws_io.h" +#include "file-utils.h" extern SessionStats session_stats; diff --git a/src/quote_fmt_parse.y b/src/quote_fmt_parse.y @@ -37,7 +37,7 @@ #include "quote_fmt.h" #include "quote_fmt_lex.h" #include "account.h" -#include "claws_io.h" +#include "file-utils.h" /* decl */ /* diff --git a/src/send_message.c b/src/send_message.c @@ -56,7 +56,7 @@ #include "inc.h" #include "log.h" #include "passwordstore.h" -#include "claws_io.h" +#include "file-utils.h" typedef struct _SendProgressDialog SendProgressDialog; diff --git a/src/sourcewindow.c b/src/sourcewindow.c @@ -30,7 +30,7 @@ #include "utils.h" #include "gtkutils.h" #include "prefs_common.h" -#include "claws_io.h" +#include "file-utils.h" static void source_window_size_alloc_cb (GtkWidget *widget, GtkAllocation *allocation); diff --git a/src/summaryview.c b/src/summaryview.c @@ -46,6 +46,7 @@ #include "prefs_filtering.h" #include "account.h" #include "compose.h" +#include "file-utils.h" #include "utils.h" #include "gtkutils.h" #include "stock_pixmap.h" diff --git a/src/textview.c b/src/textview.c @@ -69,7 +69,7 @@ #include "folder_item_prefs.h" #include "hooks.h" #include "avatars.h" -#include "claws_io.h" +#include "file-utils.h" static GdkColor quote_colors[3] = { {(gulong)0, (gushort)0, (gushort)0, (gushort)0}, diff --git a/src/vcard.c b/src/vcard.c @@ -40,7 +40,7 @@ #include "utils.h" #include "codeconv.h" #include "quoted-printable.h" -#include "claws_io.h" +#include "file-utils.h" #define GNOMECARD_DIR ".gnome" #define GNOMECARD_FILE "GnomeCard" diff --git a/src/wizard.c b/src/wizard.c @@ -34,6 +34,7 @@ #include <string.h> #include <ctype.h> +#include "file-utils.h" #include "utils.h" #include "gtk/menu.h" #include "plugin.h"