5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2007 Pekka Riikonen
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.
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.
20 /****h* silcutil/SILC File Util Interface
24 * The SILC File Util Interface is a small set of functions that provides a
25 * portable access method to the filesystem.
29 #ifndef SILCFILEUTIL_H
30 #define SILCFILEUTIL_H
34 /****f* silcutil/SilcFileUtilAPI/silc_file_open
38 * int silc_file_open(const char *filename, int flags);
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).
47 int silc_file_open(const char *filename, int flags);
49 /****f* silcutil/SilcFileUtilAPI/silc_file_open_mode
53 * int silc_file_open_mode(const char *filename, int flags, int mode);
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).
62 int silc_file_open_mode(const char *filename, int flags, int mode);
64 /****f* silcutil/SilcFileUtilAPI/silc_file_read
68 * int silc_file_read(int fd, unsigned char *buf, SilcUInt32 buf_len);
72 * Reads data from file descriptor `fd' to `buf'.
75 int silc_file_read(int fd, unsigned char *buf, SilcUInt32 buf_len);
77 /****f* silcutil/SilcFileUtilAPI/silc_file_write
81 * int silc_file_write(int fd, const char *buffer, SilcUInt32 len);
85 * Writes `buffer' of length of `len' to file descriptor `fd'.
88 int silc_file_write(int fd, const char *buffer, SilcUInt32 len);
90 /****f* silcutil/SilcFileUtilAPI/silc_file_close
94 * int silc_file_close(int fd);
98 * Closes file descriptor previously opened with silc_file_open().
101 int silc_file_close(int fd);
103 /****f* silcutil/SilcFileUtilAPI/silc_file_set_nonblock
107 * int silc_file_set_nonblock(int fd);
111 * Sets the file descriptor to non-blocking mode.
114 int silc_file_set_nonblock(int fd);
116 /****f* silcutil/SilcFileUtilAPI/silc_file_readfile
120 * char *silc_file_readfile(const char *filename, SilcUInt32 *return_len,
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
130 * If the `return_len' pointer is not NULL, it's filled with the length of
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.
138 char *silc_file_readfile(const char *filename, SilcUInt32 *return_len,
141 /****f* silcutil/SilcFileUtilAPI/silc_file_writefile
145 * int silc_file_writefile(const char *filename, const char *buffer,
150 * Writes a buffer to the file. If the file is created specific mode is
154 int silc_file_writefile(const char *filename, const char *buffer,
157 /****f* silcutil/SilcFileUtilAPI/silc_file_writefile_mode
161 * int silc_file_writefile_mode(const char *filename, const char *buffer,
162 * SilcUInt32 len, int mode);
166 * Writes a buffer to the file. If the file is created the specified `mode'
167 * is set to the file.
170 int silc_file_writefile_mode(const char *filename, const char *buffer,
171 SilcUInt32 len, int mode);
173 /****f* silcutil/SilcFileUtilAPI/silc_file_size
177 * SilcUInt64 silc_file_size(const char *filename);
181 * Returns the size of `filename'. Returns 0 on error.
184 SilcUInt64 silc_file_size(const char *filename);
186 #endif /* !SILCFILEUTIL_H */