70887760e0dad3e455e44796b141950369fbc47d
[silc.git] / lib / silcutil / silcfileutil.h
1 /*
2
3   silcfileutil.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 1997 - 2007 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 /****h* silcutil/SILC File Util Interface
21  *
22  * DESCRIPTION
23  *
24  *    The SILC File Util Interface is a small set of functions that provides a
25  *    portable access method to the filesystem.
26  *
27  ***/
28
29 #ifndef SILCFILEUTIL_H
30 #define SILCFILEUTIL_H
31
32 /* Prototypes */
33
34 /****f* silcutil/SilcFileUtilAPI/silc_file_open
35  *
36  * SYNOPSIS
37  *
38  *    int silc_file_open(const char *filename, int flags);
39  *
40  * DESCRIPTION
41  *
42  *    Opens a file indicated by the filename `filename' with flags indicated
43  *    by `flags'.  The opening permission defaults to 0600.  The `flags'
44  *    are defined in open(2).
45  *
46  ***/
47 int silc_file_open(const char *filename, int flags);
48
49 /****f* silcutil/SilcFileUtilAPI/silc_file_open_mode
50  *
51  * SYNOPSIS
52  *
53  *    int silc_file_open_mode(const char *filename, int flags, int mode);
54  *
55  * DESCRIPTION
56  *
57  *    Opens a file indicated by the filename `filename' with flags indicated
58  *    by `flags'.  The argument `mode' specifies the permissions to use in
59  *    case a new file is created.  The `flags' are defined in open(2).
60  *
61  ***/
62 int silc_file_open_mode(const char *filename, int flags, int mode);
63
64 /****f* silcutil/SilcFileUtilAPI/silc_file_read
65  *
66  * SYNOPSIS
67  *
68  *    int silc_file_read(int fd, unsigned char *buf, SilcUInt32 buf_len);
69  *
70  * DESCRIPTION
71  *
72  *    Reads data from file descriptor `fd' to `buf'.
73  *
74  ***/
75 int silc_file_read(int fd, unsigned char *buf, SilcUInt32 buf_len);
76
77 /****f* silcutil/SilcFileUtilAPI/silc_file_write
78  *
79  * SYNOPSIS
80  *
81  *    int silc_file_write(int fd, const char *buffer, SilcUInt32 len);
82  *
83  * DESCRIPTION
84  *
85  *    Writes `buffer' of length of `len' to file descriptor `fd'.
86  *
87  ***/
88 int silc_file_write(int fd, const char *buffer, SilcUInt32 len);
89
90 /****f* silcutil/SilcFileUtilAPI/silc_file_close
91  *
92  * SYNOPSIS
93  *
94  *    int silc_file_close(int fd);
95  *
96  * DESCRIPTION
97  *
98  *    Closes file descriptor previously opened with silc_file_open().
99  *
100  ***/
101 int silc_file_close(int fd);
102
103 /****f* silcutil/SilcFileUtilAPI/silc_file_set_nonblock
104  *
105  * SYNOPSIS
106  *
107  *    int silc_file_set_nonblock(int fd);
108  *
109  * DESCRIPTION
110  *
111  *    Sets the file descriptor to non-blocking mode.
112  *
113  ***/
114 int silc_file_set_nonblock(int fd);
115
116 /****f* silcutil/SilcFileUtilAPI/silc_file_readfile
117  *
118  * SYNOPSIS
119  *
120  *    char *silc_file_readfile(const char *filename, SilcUInt32 *return_len,
121  *                             SilcStack stack);
122  *
123  * DESCRIPTION
124  *
125  *    Reads the content of `filename' to a buffer.  The allocated buffer is
126  *    returned.  This does not NULL terminate the buffer but EOF terminate
127  *    it.  The caller must replace the EOF with NULL if the buffer must be
128  *    NULL terminated.
129  *
130  *    If the `return_len' pointer is not NULL, it's filled with the length of
131  *    the file.
132  *
133  *    If `stack' is non-NULL the returned buffer is allocated from `stack'.
134  *    The allocation consumes `stack' so caller should push the stack before
135  *    calling this function and pop it later.
136  *
137  ***/
138 char *silc_file_readfile(const char *filename, SilcUInt32 *return_len,
139                          SilcStack stack);
140
141 /****f* silcutil/SilcFileUtilAPI/silc_file_writefile
142  *
143  * SYNOPSIS
144  *
145  *    int silc_file_writefile(const char *filename, const char *buffer,
146  *                            SilcUInt32 len);
147  *
148  * DESCRIPTION
149  *
150  *    Writes a buffer to the file.  If the file is created specific mode is
151  *    set to the file.
152  *
153  ***/
154 int silc_file_writefile(const char *filename, const char *buffer,
155                         SilcUInt32 len);
156
157 /****f* silcutil/SilcFileUtilAPI/silc_file_writefile_mode
158  *
159  * SYNOPSIS
160  *
161  *    int silc_file_writefile_mode(const char *filename, const char *buffer,
162  *                                 SilcUInt32 len, int mode);
163  *
164  * DESCRIPTION
165  *
166  *    Writes a buffer to the file.  If the file is created the specified `mode'
167  *    is set to the file.
168  *
169  ***/
170 int silc_file_writefile_mode(const char *filename, const char *buffer,
171                              SilcUInt32 len, int mode);
172
173 /****f* silcutil/SilcFileUtilAPI/silc_file_size
174  *
175  * SYNOPSIS
176  *
177  *    SilcUInt64 silc_file_size(const char *filename);
178  *
179  * DESCRIPTION
180  *
181  *    Returns the size of `filename'. Returns 0 on error.
182  *
183  ***/
184 SilcUInt64 silc_file_size(const char *filename);
185
186 #endif  /* !SILCFILEUTIL_H */