diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-21 18:16:47 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-21 18:16:47 +0200 |
| commit | 3f37f1c9bf64866de90ec418adcfe31b634231c2 (patch) | |
| tree | 79c12d6255f54ec1049b0b5863c8d6662345518e /src/archive.c | |
| parent | 0fa3308034c7776b6c078e493f3b758f0a0bf7e6 (diff) | |
| download | tar-3f37f1c9bf64866de90ec418adcfe31b634231c2.tar.gz tar-3f37f1c9bf64866de90ec418adcfe31b634231c2.tar.bz2 tar-3f37f1c9bf64866de90ec418adcfe31b634231c2.zip | |
Added archive_write, archive_read draft
Diffstat (limited to 'src/archive.c')
| -rw-r--r-- | src/archive.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/archive.c b/src/archive.c new file mode 100644 index 0000000..11457d6 --- /dev/null +++ b/src/archive.c @@ -0,0 +1,73 @@ +#include "tar.h" + +int archive_write(char *archive_file_name, char **files) +{ + int fd; + char file_name[PATH_MAX]; + struct stat root_statbuf; + + if (archive_file_name == NULL) + fd = STDOUT_FILENO; + else + { + fd = open(archive_file_name, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (fd == -1) + { + perror("achive_write"); + return -1; + } + } + for (; *files != NULL; files++) + { + bzero(file_name, PATH_MAX); + strcpy(file_name, *files); + file_write(fd, file_name); + } + if (stat("/", &root_statbuf) == -1) + { + perror("achive_write"); + close(fd); + return -1; + } + if (record_write_blank(fd, 2 + (2 * root_statbuf.st_blksize) / RECORD_SIZE) == -1) + { + close(fd); + return -1; + } + if (fd != STDOUT_FILENO) + close(fd); + return 0; +} + +int archive_read(char *archive_file_name) +{ + int fd; + + if ((fd = open(archive_file_name, O_RDONLY)) == -1) + { + perror("achive_write"); + return -1; + } + + int ret; + char buf[RECORD_SIZE]; + t_header header; + int current_fd; + + while ((ret = read(fd, buf, RECORD_SIZE)) == RECORD_SIZE) + { + /* header_parse(&header, buf); */ + /* current_fd = open(header.file_name, O_WRONLY | O_CREAT | O_TRUNC, header. */ + // read content + // TODO + } + if (ret == -1) + { + perror(NULL); + return -1; + } + if (ret < RECORD_SIZE) + return -1; + close(fd); + return 0; +} |
