Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / vsftpd / filestr.c
blob5a975a2e43b31344a882adc962298b16cec24e6b
1 /*
2 * Part of Very Secure FTPd
3 * Licence: GPL v2
4 * Author: Chris Evans
5 * filestr.c
7 * This file contains extensions to the string/buffer API, to load a file
8 * into a buffer.
9 */
11 #include "filestr.h"
12 /* Get access to "private" functions */
13 #define VSFTP_STRING_HELPER
14 #include "str.h"
15 #include "sysutil.h"
16 #include "secbuf.h"
17 #include "utility.h"
19 int
20 str_fileread(struct mystr* p_str, const char* p_filename, unsigned int maxsize)
22 int fd;
23 int retval = 0;
24 filesize_t size;
25 char* p_sec_buf = 0;
26 struct vsf_sysutil_statbuf* p_stat = 0;
27 /* In case we fail, make sure we return an empty string */
28 str_empty(p_str);
29 fd = vsf_sysutil_open_file(p_filename, kVSFSysUtilOpenReadOnly);
30 if (vsf_sysutil_retval_is_error(fd))
32 return fd;
34 vsf_sysutil_fstat(fd, &p_stat);
35 if (vsf_sysutil_statbuf_is_regfile(p_stat))
37 size = vsf_sysutil_statbuf_get_size(p_stat);
38 if (size > maxsize)
40 size = maxsize;
42 vsf_secbuf_alloc(&p_sec_buf, (unsigned int) size);
44 retval = vsf_sysutil_read_loop(fd, p_sec_buf, (unsigned int) size);
45 if (vsf_sysutil_retval_is_error(retval))
47 goto free_out;
49 else if ((unsigned int) retval != size)
51 die("read size mismatch");
53 str_alloc_memchunk(p_str, p_sec_buf, size);
55 free_out:
56 vsf_sysutil_free(p_stat);
57 vsf_secbuf_free(&p_sec_buf);
58 vsf_sysutil_close(fd);
59 return retval;