aboutsummaryrefslogtreecommitdiff
path: root/src/tar.c
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2021-08-23 07:41:55 -0300
committerEuAndreh <eu@euandre.org>2021-08-23 07:41:55 -0300
commit35cead0b83da84c037bcf79ce112cb5e59f56b10 (patch)
treec897348af5bf2cad5e122840ba95a198386eff5c /src/tar.c
parentTODOs.md: Extend description of #task-4e40832e-78cf-fc21-cbf9-2fe00fd3828d (diff)
downloadgistatic-35cead0b83da84c037bcf79ce112cb5e59f56b10.tar.gz
gistatic-35cead0b83da84c037bcf79ce112cb5e59f56b10.tar.xz
src/: Move logerr* functions to src/logerr.{c,h}; forward tarballs_fd to src/tar.c
Diffstat (limited to 'src/tar.c')
-rw-r--r--src/tar.c84
1 files changed, 82 insertions, 2 deletions
diff --git a/src/tar.c b/src/tar.c
index 0afcb28..cc8eaa0 100644
--- a/src/tar.c
+++ b/src/tar.c
@@ -1,5 +1,26 @@
#include "config.h"
#include "tar.h"
+#include "logerr.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdbool.h>
+
+/*
+
+About the ustar format:
+- name[100] can only contain 100 bytes, while PATH_MAX's minimum value is 256
+ for `_POSIX_PATH_MAX`, and 1024 for _XOPEN_PATH_MAX. Wait! Actually there is
+ a "prefix" field, which is probably what I'm looking for;
+- characters are encoded in ISO/IEC 646:1991 [0] instead of UTF-8, even though
+ it requires the file names to be conformant to the POSIX filename
+ restrictions;
+
+[0]: https://en.wikipedia.org/wiki/ISO/IEC_646
+
+*/
/*
* Implementation of the "ustar archive tape" (tar) format, conformant to the
@@ -8,9 +29,68 @@
* [0]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html#tag_20_92_13_06
*/
-int tarball_write_from_directory(const char *const directory_path) {
+
+static void logerr(
+ const char *const s,
+ const char *const msg,
+ const int lineno
+) {
+ logerr_file(s, msg, __FILE__, lineno);
+}
+
+static void logerrs(
+ const char *const pre,
+ const char *const mid,
+ const char *const post,
+ const char *const msg,
+ const int lineno
+) {
+ logerrs_file(pre, mid, post, msg, __FILE__, lineno);
+}
+
+static void logerrl(
+ const char *const pre,
+ const size_t mid,
+ const char *const post,
+ const char *const msg,
+ const int lineno
+) {
+ logerrl_file(pre, mid, post, msg, __FILE__, lineno);
+}
+
+
+struct TarEntry {
+ // What size the spec says?
+ unsigned int begin;
+};
+
+// static int tar_write(FILE *const fd, 
+
+int tarball_write_from_directory(
+ FILE *const fd,
+ const char *const directory_path
+) {
+ int ret = 0;
+ struct TarEntry *entry = NULL;
(void)directory_path;
- return 0;
+ (void)fd;
+
+ if (!(entry = malloc(sizeof(struct TarEntry)))) {
+ logerrl("malloc(", sizeof(struct TarEntry), ")",
+ strerror(errno), __LINE__);
+ ret = -1;
+ goto cleanup;
+ }
+
+ if (false) {
+ logerrs("", "", "", "", 0);
+ logerr("", "", 0);
+ }
+
+
+cleanup:
+ free(entry);
+ return ret;
}
#ifdef TEST