update lib/fs
This commit is contained in:
1 parent
be2e61d7bb
commit
fbdc1ae34e
2 files changed
+26
No files matched your search
@@ -48,6 +48,7 @@ int fs_stat_file(filecookie fcookie, struct file_stat *);
|
||||
|
||||
/* convenience routines */
|
||||
ssize_t fs_load_file(const char *path, void *ptr, size_t maxlen);
|
||||
ssize_t fs_load_file_mem(const char *path, void **ptr);
|
||||
|
||||
/* walk through a path string, removing duplicate path seperators, flattening . and .. references */
|
||||
void fs_normalize_path(char *path);
|
||||
|
||||
+25
@@ -396,6 +396,31 @@ ssize_t fs_load_file(const char *path, void *ptr, size_t maxlen)
|
||||
return err;
|
||||
}
|
||||
|
||||
ssize_t fs_load_file_mem(const char *path, void **ptr)
|
||||
{
|
||||
int err;
|
||||
filecookie cookie;
|
||||
|
||||
/* open the file */
|
||||
err = fs_open_file(path, &cookie);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
/* stat it for size, see how much we need to read */
|
||||
struct file_stat stat;
|
||||
fs_stat_file(cookie, &stat);
|
||||
|
||||
*ptr = malloc(stat.size);
|
||||
|
||||
if (!(*ptr)) return -1;
|
||||
|
||||
err = fs_read_file(cookie, *ptr, 0, stat.size);
|
||||
|
||||
fs_close_file(cookie);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static void test_normalize(const char *in)
|
||||
{
|
||||
char path[1024];
|
||||
|
||||
Reference in new issue
Block a user