summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2020-04-29 22:01:35 -0400
committermidipix <writeonce@midipix.org>2020-05-23 05:59:02 +0000
commit845037353c2db876f004f024b5b50cc18cb70a7a (patch)
tree34f413ee1d2f997ea3592303f9d7c77f0df1e83e
parente407b8dc73e1bb9c2f5cad4dedf255ca431b1f06 (diff)
downloadtpax-845037353c2db876f004f024b5b50cc18cb70a7a.tar.bz2
tpax-845037353c2db876f004f024b5b50cc18cb70a7a.tar.xz
helper interfaces: tpax_stat_compare(): initial implementation.
-rw-r--r--include/tpax/tpax.h1
-rw-r--r--project/common.mk1
-rw-r--r--src/helper/tpax_stat_compare.c41
3 files changed, 43 insertions, 0 deletions
diff --git a/include/tpax/tpax.h b/include/tpax/tpax.h
index 5281ea1..c39f721 100644
--- a/include/tpax/tpax.h
+++ b/include/tpax/tpax.h
@@ -148,6 +148,7 @@ tpax_api int tpax_set_driver_fdctx (struct tpax_driver_ctx *, const struct
/* helper api */
tpax_api int tpax_path_copy (char *, const char *, size_t, uint32_t, size_t *);
+tpax_api int tpax_stat_compare (const struct stat *, const struct stat *);
/* utility api */
tpax_api int tpax_main (char **, char **,
diff --git a/project/common.mk b/project/common.mk
index ca6bc81..14d6ec8 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -3,6 +3,7 @@ API_SRCS = \
src/driver/tpax_driver_ctx.c \
src/driver/tpax_unit_ctx.c \
src/helper/tpax_path_copy.c \
+ src/helper/tpax_stat_compare.c \
src/logic/tpax_init_ustar_header.c \
src/output/tpax_output_error.c \
src/skin/tpax_skin_default.c \
diff --git a/src/helper/tpax_stat_compare.c b/src/helper/tpax_stat_compare.c
new file mode 100644
index 0000000..afbe2f4
--- /dev/null
+++ b/src/helper/tpax_stat_compare.c
@@ -0,0 +1,41 @@
+/******************************************************/
+/* tpax: a topological pax implementation */
+/* Copyright (C) 2020 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
+/******************************************************/
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/stat.h>
+
+#include <tpax/tpax.h>
+#include "tpax_driver_impl.h"
+
+#define TPAX_STAT_COMPARE(member) \
+ if (src -> member - dst -> member) \
+ return (src -> member > dst -> member) \
+ ? (1) : (-1)
+
+int tpax_stat_compare(
+ const struct stat * src,
+ const struct stat * dst)
+{
+ TPAX_STAT_COMPARE(st_dev);
+ TPAX_STAT_COMPARE(st_ino);
+
+ TPAX_STAT_COMPARE(st_mode);
+ TPAX_STAT_COMPARE(st_uid);
+ TPAX_STAT_COMPARE(st_gid);
+
+ TPAX_STAT_COMPARE(st_rdev);
+ TPAX_STAT_COMPARE(st_size);
+ TPAX_STAT_COMPARE(st_blksize);
+ TPAX_STAT_COMPARE(st_blocks);
+
+ TPAX_STAT_COMPARE(st_mtim.tv_sec);
+ TPAX_STAT_COMPARE(st_mtim.tv_nsec);
+
+ return 0;
+}