2 * Part of Very Secure FTPd
7 * This file contains extensions to the string/buffer API, to load a file
12 /* Get access to "private" functions */
13 #define VSFTP_STRING_HELPER
20 str_fileread(struct mystr
* p_str
, const char* p_filename
, unsigned int maxsize
)
26 struct vsf_sysutil_statbuf
* p_stat
= 0;
27 /* In case we fail, make sure we return an empty string */
29 fd
= vsf_sysutil_open_file(p_filename
, kVSFSysUtilOpenReadOnly
);
30 if (vsf_sysutil_retval_is_error(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
);
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
))
49 else if ((unsigned int) retval
!= size
)
51 die("read size mismatch");
53 str_alloc_memchunk(p_str
, p_sec_buf
, (unsigned int) size
);
56 vsf_sysutil_free(p_stat
);
57 vsf_secbuf_free(&p_sec_buf
);
58 vsf_sysutil_close(fd
);