Changes in uspace/lib/futil/src/futil.c [a188131:04e520e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/futil/src/futil.c
ra188131 r04e520e 1 1 /* 2 * Copyright (c) 202 5Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 47 47 static char buf[BUF_SIZE]; 48 48 49 /** Create file utility instance.50 *51 * @param cb Callback functions52 * @param arg Argument to callback functions53 * @param rfutil Place to store pointer to new file utility instance54 * @return EOK on succcess, ENOMEM if out of memory.55 */56 errno_t futil_create(futil_cb_t *cb, void *arg, futil_t **rfutil)57 {58 futil_t *futil;59 60 futil = calloc(1, sizeof(futil_t));61 if (futil == NULL)62 return ENOMEM;63 64 futil->cb = cb;65 futil->cb_arg = arg;66 *rfutil = futil;67 return EOK;68 }69 70 /** Destroy file utility instance.71 *72 * @param futil File utility instance73 */74 void futil_destroy(futil_t *futil)75 {76 free(futil);77 }78 79 49 /** Copy file. 80 50 * 81 * @param futil File utility instance82 51 * @param srcp Source path 83 52 * @param dstp Destination path … … 85 54 * @return EOK on success, EIO on I/O error 86 55 */ 87 errno_t futil_copy_file( futil_t *futil,const char *srcp, const char *destp)56 errno_t futil_copy_file(const char *srcp, const char *destp) 88 57 { 89 58 int sf, df; … … 92 61 aoff64_t posr = 0, posw = 0; 93 62 94 if (futil->cb != NULL && futil->cb->copy_file != NULL) 95 futil->cb->copy_file(futil->cb_arg, srcp, destp); 63 printf("Copy '%s' to '%s'.\n", srcp, destp); 96 64 97 65 rc = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ, &sf); … … 131 99 /** Copy contents of srcdir (recursively) into destdir. 132 100 * 133 * @param futil File utility instance134 101 * @param srcdir Source directory 135 102 * @param destdir Destination directory … … 137 104 * @return EOK on success, ENOMEM if out of memory, EIO on I/O error 138 105 */ 139 errno_t futil_rcopy_contents(futil_t *futil, const char *srcdir, 140 const char *destdir) 106 errno_t futil_rcopy_contents(const char *srcdir, const char *destdir) 141 107 { 142 108 DIR *dir; … … 162 128 163 129 if (s.is_file) { 164 rc = futil_copy_file( futil,srcp, destp);130 rc = futil_copy_file(srcp, destp); 165 131 if (rc != EOK) 166 132 return EIO; 167 133 } else if (s.is_directory) { 168 if (futil->cb != NULL && futil->cb->create_dir != NULL) 169 futil->cb->create_dir(futil->cb_arg, destp); 134 printf("Create directory '%s'\n", destp); 170 135 rc = vfs_link_path(destp, KIND_DIRECTORY, NULL); 171 136 if (rc != EOK) 172 137 return EIO; 173 rc = futil_rcopy_contents( futil,srcp, destp);138 rc = futil_rcopy_contents(srcp, destp); 174 139 if (rc != EOK) 175 140 return EIO; … … 186 151 /** Return file contents as a heap-allocated block of bytes. 187 152 * 188 * @param futil File utility instance189 153 * @param srcp File path 190 154 * @param rdata Place to store pointer to data … … 194 158 * I/O error, ENOMEM if out of memory 195 159 */ 196 errno_t futil_get_file(futil_t *futil, const char *srcp, void **rdata, 197 size_t *rsize) 160 errno_t futil_get_file(const char *srcp, void **rdata, size_t *rsize) 198 161 { 199 162 int sf;
Note:
See TracChangeset
for help on using the changeset viewer.