2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2018 Colin Leroy and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "claws-features.h"
30 gboolean prefs_common_get_flush_metadata(void);
32 /* FIXME make static once every file I/O is done using claws_* wrappers */
33 int safe_fclose(FILE *fp)
38 if (fflush(fp) != 0) {
41 if (prefs_common_get_flush_metadata() && fsync(fileno(fp)) != 0) {
51 #if HAVE_FGETS_UNLOCKED
53 /* Open a file and locks it once
54 * so subsequent I/O is faster
56 FILE *claws_fopen(const char *file, const char *mode)
58 FILE *fp = fopen(file, mode);
65 FILE *claws_fdopen(int fd, const char *mode)
67 FILE *fp = fdopen(fd, mode);
74 /* Unlocks and close a file pointer
77 int claws_fclose(FILE *fp)
83 /* Unlock, then safe-close a file pointer
84 * Safe close is done using fflush + fsync
85 * if the according preference says so.
87 int claws_safe_fclose(FILE *fp)
90 return safe_fclose(fp);