extract.h

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.1 kB
3
Indexable
Never
#include "extract.h"
int extract_header(header *curr_header) {
    /*create file with correct permissions*/
    /*return file descriptor*/
    int fd;
    char *full_path;
    long mode;
    full_path = rebuild_name(curr_header);
    mode = strtol(curr_header->mode, NULL, 0);
    if (IS_DIR(mode)) {
        if (mkdir(full_path, mode) == -1) {
            perror("Mkdir");
            exit(EXIT_FAILURE);
        }
        return DIR_VAL;
    }

    if (IS_LNK(mode)) {
        if ((symlink(full_path, curr_header->linkname)) == -1) {
            perror("symlink");
            exit(EXIT_FAILURE);
        }
        return SYM_VAL;
    }

    if (IS_REG(mode)) {
        if ((fd = fopen(full_path, mode)) == -1) {
            perror("Fopen");
            exit(EXIT_FAILURE);
        }
    return fd;
    }
}


void write_contents(int target_fd, char block[BLOCK_SIZE], unsigned size) {
    if (size >= BLOCK_SIZE) {
        size = BLOCK_SIZE;
    }
    if (write(target_fd, block, size) == -1) {
        perror("Write");
        exit(EXIT_FAILURE);
    }
}
Leave a Comment