Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/futil/src/futil.c

    r04e520e ra188131  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4747static char buf[BUF_SIZE];
    4848
     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 */
     56errno_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 */
     74void futil_destroy(futil_t *futil)
     75{
     76        free(futil);
     77}
     78
    4979/** Copy file.
    5080 *
     81 * @param futil File utility instance
    5182 * @param srcp Source path
    5283 * @param dstp Destination path
     
    5485 * @return EOK on success, EIO on I/O error
    5586 */
    56 errno_t futil_copy_file(const char *srcp, const char *destp)
     87errno_t futil_copy_file(futil_t *futil, const char *srcp, const char *destp)
    5788{
    5889        int sf, df;
     
    6192        aoff64_t posr = 0, posw = 0;
    6293
    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);
    6496
    6597        rc = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ, &sf);
     
    99131/** Copy contents of srcdir (recursively) into destdir.
    100132 *
     133 * @param futil File utility instance
    101134 * @param srcdir Source directory
    102135 * @param destdir Destination directory
     
    104137 * @return EOK on success, ENOMEM if out of memory, EIO on I/O error
    105138 */
    106 errno_t futil_rcopy_contents(const char *srcdir, const char *destdir)
     139errno_t futil_rcopy_contents(futil_t *futil, const char *srcdir,
     140    const char *destdir)
    107141{
    108142        DIR *dir;
     
    128162
    129163                if (s.is_file) {
    130                         rc = futil_copy_file(srcp, destp);
     164                        rc = futil_copy_file(futil, srcp, destp);
    131165                        if (rc != EOK)
    132166                                return EIO;
    133167                } 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);
    135170                        rc = vfs_link_path(destp, KIND_DIRECTORY, NULL);
    136171                        if (rc != EOK)
    137172                                return EIO;
    138                         rc = futil_rcopy_contents(srcp, destp);
     173                        rc = futil_rcopy_contents(futil, srcp, destp);
    139174                        if (rc != EOK)
    140175                                return EIO;
     
    151186/** Return file contents as a heap-allocated block of bytes.
    152187 *
     188 * @param futil File utility instance
    153189 * @param srcp File path
    154190 * @param rdata Place to store pointer to data
     
    158194 *         I/O error, ENOMEM if out of memory
    159195 */
    160 errno_t futil_get_file(const char *srcp, void **rdata, size_t *rsize)
     196errno_t futil_get_file(futil_t *futil, const char *srcp, void **rdata,
     197    size_t *rsize)
    161198{
    162199        int sf;
Note: See TracChangeset for help on using the changeset viewer.