mytar.c

mail@pastecode.io avatar
unknown
plain_text
2 months ago
949 B
2
Indexable
Never
#include <stdio.h>
#include <stdlib.h>
#include "create.h"
#include "read.h"
#define BLOCK_SIZE 512

void write_field(int fd, char *field, unsigned field_size);

int main(int argc, char *argv[]){
    char *tar_file;
    char *path;
    int tar_fd;
    int i;

    if(argc < 3){
        perror("usage | mytar [ctxvS]f tarfile [ path [] ]: ");
        exit(EXIT_FAILURE);
    }
    else{
        if(parse_options(argv[1]) != 0){
            perror("usage | mytar [ctxvS]f tarfile [ path []]: ");
            exit(EXIT_FAILURE);
        }

        tar_file = argv[2];
    }

    tar_fd = create_archive(tar_file);

    if(create_option == 1){
        for(i = 3; i < argc; i++){
            path = argv[i];
            archive_file(tar_fd, "", path);
        }

        write_field(tar_fd, NULL, BLOCK_SIZE);
        write_field(tar_fd, NULL, BLOCK_SIZE);
    }
    else{
        while(read_file(tar_fd) != 0);
    }

    close(tar_fd);

    return 0;
}
Leave a Comment