Changes in uspace/lib/futil/src/futil.c [629b480:5df2570] in mainline
- File:
-
- 1 edited
-
uspace/lib/futil/src/futil.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/futil/src/futil.c
r629b480 r5df2570 1 1 /* 2 * Copyright (c) 202 5Jiri Svoboda2 * Copyright (c) 2026 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 179 179 futil->cb->create_dir(futil->cb_arg, destp); 180 180 rc = vfs_link_path(destp, KIND_DIRECTORY, NULL); 181 if (rc != EOK )181 if (rc != EOK && rc != EEXIST) 182 182 goto error; 183 183 rc = futil_rcopy_contents(futil, srcp, destp); … … 199 199 } 200 200 201 /** Return file contents as a heap-allocated block of bytes.202 *203 * @param futil File utility instance204 * @param srcp File path205 * @param rdata Place to store pointer to data206 * @param rsize Place to store size of data207 *208 * @return EOK on success, ENOENT if failed to open file, EIO on other209 * I/O error, ENOMEM if out of memory210 */211 errno_t futil_get_file(futil_t *futil, const char *srcp, void **rdata,212 size_t *rsize)213 {214 int sf;215 size_t nr;216 errno_t rc;217 size_t fsize;218 char *data;219 vfs_stat_t st;220 221 rc = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ, &sf);222 if (rc != EOK)223 return ENOENT;224 225 if (vfs_stat(sf, &st) != EOK) {226 vfs_put(sf);227 return EIO;228 }229 230 fsize = st.size;231 232 data = calloc(fsize, 1);233 if (data == NULL) {234 vfs_put(sf);235 return ENOMEM;236 }237 238 rc = vfs_read(sf, (aoff64_t []) { 0 }, data, fsize, &nr);239 if (rc != EOK || nr != fsize) {240 vfs_put(sf);241 free(data);242 return EIO;243 }244 245 (void) vfs_put(sf);246 *rdata = data;247 *rsize = fsize;248 249 return EOK;250 }251 252 201 /** @} 253 202 */
Note:
See TracChangeset
for help on using the changeset viewer.
