Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 18ad56a8 in mainline


Ignore:
Timestamp:
2018-06-07T15:45:56Z (2 years ago)
Author:
Martin Decky <martin@…>
Branches:
master
Children:
75701004
Parents:
24fda5e
Message:

more elegant way of keeping the state of the archive extraction

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/untar/main.c

    r24fda5e r18ad56a8  
    3737#include <untar.h>
    3838
    39 const char *filename;
     39typedef struct {
     40        const char *filename;
     41        FILE *file;
     42} tar_state_t;
    4043
    4144static int tar_open(tar_file_t *tar)
    4245{
    43         FILE *file = fopen(filename, "rb");
    44         if (file == NULL)
     46        tar_state_t *state = (tar_state_t *) tar->data;
     47
     48        state->file = fopen(state->filename, "rb");
     49        if (state->file == NULL)
    4550                return errno;
    4651
    47         tar->data = (void *) file;
    4852        return EOK;
    4953}
     
    5155static void tar_close(tar_file_t *tar)
    5256{
    53         FILE *file = (FILE *) tar->data;
    54         fclose(file);
     57        tar_state_t *state = (tar_state_t *) tar->data;
     58        fclose(state->file);
    5559}
    5660
    5761static size_t tar_read(tar_file_t *tar, void *data, size_t size)
    5862{
    59         FILE *file = (FILE *) tar->data;
    60         return fread(data, 1, size, file);
     63        tar_state_t *state = (tar_state_t *) tar->data;
     64        return fread(data, 1, size, state->file);
    6165}
    6266
     
    8185        }
    8286
    83         filename = argv[1];
     87        tar_state_t state;
     88        state.filename = argv[1];
     89
     90        tar.data = (void *) &state;
    8491        return untar(&tar);
    8592}
Note: See TracChangeset for help on using the changeset viewer.