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