Add a memory-backed my_tmpfile() implementation.
[claws.git] / src / common / file-utils.h
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2018 Colin Leroy and the Claws Mail team
4  *
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.
9  *
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.
14  *
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/>.
17  */
18
19 #ifndef __CLAWS_IO_H__
20 #define __CLAWS_IO_H__
21
22 #ifdef HAVE_CONFIG_H
23 #  include "config.h"
24 #include "claws-features.h"
25 #endif
26
27 #include <stdio.h>
28 #include <glib.h>
29
30 #if HAVE_FGETS_UNLOCKED
31 #define claws_fgets fgets_unlocked
32 #define claws_fgetc fgetc_unlocked
33 #define claws_fputs fputs_unlocked
34 #define claws_fputc fputc_unlocked
35 #define claws_fread fread_unlocked
36 #define claws_fwrite fwrite_unlocked
37 #define claws_feof feof_unlocked
38 #define claws_ferror ferror_unlocked
39
40 FILE *claws_fopen               (const char *file,
41                                  const char *mode);
42 FILE *claws_fdopen              (int fd,
43                                  const char *mode);
44 int claws_fclose                (FILE *fp);
45 int claws_safe_fclose           (FILE *fp);
46
47 #else
48
49 #define claws_fgets fgets
50 #define claws_fgetc fgetc
51 #define claws_fputs fputs
52 #define claws_fputc fputc
53 #define claws_fread fread
54 #define claws_fwrite fwrite
55 #define claws_feof feof
56 #define claws_ferror ferror
57 #define claws_fopen g_fopen
58 #define claws_fdopen fdopen
59 #define claws_fclose fclose
60 #define claws_safe_fclose safe_fclose
61 #endif
62
63 int safe_fclose                 (FILE *fp);
64 int claws_unlink                (const char     *filename);
65
66 gint file_strip_crs             (const gchar    *file);
67 gint append_file                (const gchar    *src,
68                                  const gchar    *dest,
69                                  gboolean        keep_backup);
70 gint copy_file                  (const gchar    *src,
71                                  const gchar    *dest,
72                                  gboolean        keep_backup);
73 gint move_file                  (const gchar    *src,
74                                  const gchar    *dest,
75                                  gboolean        overwrite);
76 gint copy_file_part_to_fp       (FILE           *fp,
77                                  off_t           offset,
78                                  size_t          length,
79                                  FILE           *dest_fp);
80 gint copy_file_part             (FILE           *fp,
81                                  off_t           offset,
82                                  size_t          length,
83                                  const gchar    *dest);
84 gint canonicalize_file          (const gchar    *src,
85                                  const gchar    *dest);
86 gint canonicalize_file_replace  (const gchar    *file);
87 gint str_write_to_file          (const gchar    *str,
88                                  const gchar    *file);
89 gchar *file_read_to_str         (const gchar    *file);
90 gchar *file_read_to_str_no_recode(const gchar   *file);
91 gchar *file_read_stream_to_str  (FILE           *fp);
92 gchar *file_read_stream_to_str_no_recode(FILE   *fp);
93
94 gint rename_force               (const gchar    *oldpath,
95                                  const gchar    *newpath);
96 gint copy_dir                   (const gchar    *src,
97                                  const gchar    *dest);
98 gint change_file_mode_rw        (FILE           *fp,
99                                  const gchar    *file);
100 FILE *my_tmpfile                (void);
101 FILE *my_tmpfile_with_len       (size_t          len);
102 FILE *get_tmpfile_in_dir        (const gchar    *dir,
103                                  gchar         **filename);
104 FILE *str_open_as_stream        (const gchar    *str);
105 gint str_write_to_file          (const gchar    *str,
106                                  const gchar    *file);
107
108 #endif