From e1f3547e236671697c66e27ba02b6a151e59af04 Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 20 Jun 2020 11:08:06 +0200 Subject: Initial commit --- src/header.c | 3 +++ src/main.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/header.c create mode 100644 src/main.c (limited to 'src') diff --git a/src/header.c b/src/header.c new file mode 100644 index 0000000..a0cf2fb --- /dev/null +++ b/src/header.c @@ -0,0 +1,3 @@ +#include "tar.h" + +/* int header_write(int fd, */ diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..d6df9d7 --- /dev/null +++ b/src/main.c @@ -0,0 +1,52 @@ +#include "tar.h" + +int main(int argc, char **argv) +{ + int opt; + char *output_file_name = NULL; + + while ((opt = getopt(argc, argv, "cvtf:")) != -1) + { + switch (opt) + { + case 'c': + break; + case 'f': + output_file_name = optarg; + break; + case 'v': + break; + case 't': + break; + default: + return 1; + } + } + int fd = -1; + if (output_file_name == NULL) + fd = STDOUT_FILENO; + else + { + fd = open(output_file_name, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (fd == -1) + { + perror(NULL); + return 1; + } + } + + // pipe to fd + printf("out: %s\n", output_file_name); + char **files = argv + optind; + for (; *files != NULL; files++) + { + // stat file + // write header to pipe + // if dir + // recursion on files in dir + // else + // write content to pipe + printf("%s\n", *files); + } + return 0; +} -- cgit