core/file: Add cache_file_write() function
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
9db9df619f
commit
0344a2088d
|
@ -260,3 +260,10 @@ int file_writef(struct file *file, const char *fmt, ...)
|
|||
REPORT_ERRNO(file->f_name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int cache_file_write(struct cache_file *file, const void *data, size_t len)
|
||||
{
|
||||
if (fwrite(data, len, 1, file->cf_file) == 1)
|
||||
return len;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -135,4 +135,10 @@ int file_readf(struct file *, const char *, ...);
|
|||
*/
|
||||
int file_writef(struct file *, const char *, ...);
|
||||
|
||||
/*
|
||||
* Write binary data to a cache file similar to fwrite(3).
|
||||
* Returns the number of bytes successfully written.
|
||||
*/
|
||||
int cache_file_write(struct cache_file *, const void *, size_t);
|
||||
|
||||
#endif /* OCARINA_CORE_FILE_H */
|
||||
|
|
|
@ -166,6 +166,7 @@ static void test_cache()
|
|||
test_equal(cache_file_open(&file, OPEN_WRITE), (bool)false);
|
||||
|
||||
test_equal(cache_file_exists(&file), (bool)false);
|
||||
test_equal(cache_file_write(&file, "abcde", 5), 5);
|
||||
cache_file_close(&file);
|
||||
test_equal((void *)file.cf_file, NULL);
|
||||
test_equal(cache_file_exists(&file), (bool)true);
|
||||
|
|
Loading…
Reference in New Issue