str_fileread
source
filestr.c
line
18 - 53
概要
int str_fileread(struct mystr* p_str, const char* p_filename,
unsigned int maxsize);
* Read the contents of a file into a string buffer, up to a size limit of
* "maxsize"
ストリングバッファからファイルのコンテンツを"maxsizeする"のサイズ限界まで読み取ってください。
* p_str - destination buffer object to contain the file
ファイルを含む目的地バッファオブジェクト
* p_filename - the filename to try and read into the buffer
バッファの中に試みて、読み込むファイル名
* maxsize - the maximum amount of buffer we will fill. Larger files will
be truncated.
私たちがいっぱいにするつもりであるバッファの最大の量。 より大きいファイルは先端を切られるでしょう。
* An integer representing the success/failure of opening the file
* "p_filename". Zero indicates success. If successful, the file is read into
* the "p_str" string object. If not successful, "p_str" will point to an
* empty buffer.
「p_ファイル名」というファイルを開く成功/失敗を表す整数。
ゼロは成功を示します。
うまくいくなら、ファイルは「p_str」ストリングオブジェクトから読み取られます。
そうでなければ、うまくいって、「p_str」は空のバッファを示すでしょう。
function
18 int
19 str_fileread(struct mystr* p_str, const char* p_filename, unsigned int maxsize)
20 {
21 int fd;
22 int retval;
23 filesize_t size;
24 char* p_sec_buf = 0;
25 struct vsf_sysutil_statbuf* p_stat = 0;
26 /* In case we fail, make sure we return an empty string */
27 str_empty(p_str);
- ファイル読み込み
28 fd = vsf_sysutil_open_file(p_filename, kVSFSysUtilOpenReadOnly);
29 if (vsf_sysutil_retval_is_error(fd))
30 {
31 return fd;
32 }
- ファイルの付帯情報取得
vsf_sysutil_fstat(fd, &p_stat);
34 if (vsf_sysutil_statbuf_is_regfile(p_stat))
35 {
36 size = vsf_sysutil_statbuf_get_size(p_stat);
37 if (size > maxsize)
38 {
39 size = maxsize;
40 }
41 vsf_secbuf_alloc(&p_sec_buf, (unsigned int) size);
42
43 retval = vsf_sysutil_read_loop(fd, p_sec_buf, (unsigned int) size);
44 if (!vsf_sysutil_retval_is_error(retval) && (unsigned int) retval == size)
45 {
46 str_alloc_memchunk(p_str, p_sec_buf, size);
47 }
48 }
49 vsf_sysutil_free(p_stat);
50 vsf_secbuf_free(&p_sec_buf);
51 vsf_sysutil_close(fd);
52 return 0;
53 }
最終更新:2009年02月09日 21:14