aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-04-17 23:52:52 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-04-17 23:52:52 +0200
commit16a22bebb0bb4a28aec9ca76442af93462fc200e (patch)
treef6d84145553686ab0e9be451dcf0e2acb485cd9c
parent1fe3f86230a970b3974f16a6bc2e819fdaf55b58 (diff)
Remove some configure time sizeof checks
In libtar, the sizeof time_t checked when trying to store a time value. It is pointless using the preprocessor here, as we can simply do an if (sizeof(time_t) < ...) check and the compiler will take care optimizing away one or the other branch. After changing the libtar check and the corresponding unit tests, the sizeof check can be removed from configure.ac, along with other unused sizeof checks. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--configure.ac2
-rw-r--r--lib/tar/internal.h1
-rw-r--r--lib/tar/read_header.c16
-rw-r--r--tests/tar_gnu.c12
-rw-r--r--tests/tar_pax.c12
-rw-r--r--tests/tar_ustar.c12
-rw-r--r--tests/test.h1
7 files changed, 31 insertions, 25 deletions
diff --git a/configure.ac b/configure.ac
index 9da88e0..3804631 100644
--- a/configure.ac
+++ b/configure.ac
@@ -226,9 +226,7 @@ PKG_CHECK_MODULES(READLINE, [readline], [have_readline="yes"],
AM_CONDITIONAL([WITH_READLINE], [test "x$have_readline" = "xyes"])
##### additional checks #####
-AX_COMPILE_CHECK_SIZEOF(time_t)
AX_COMPILE_CHECK_SIZEOF(size_t)
-AX_COMPILE_CHECK_SIZEOF(short)
AX_COMPILE_CHECK_SIZEOF(int)
AX_COMPILE_CHECK_SIZEOF(long)
AX_COMPILE_CHECK_SIZEOF(long long)
diff --git a/lib/tar/internal.h b/lib/tar/internal.h
index 755d4eb..57746ae 100644
--- a/lib/tar/internal.h
+++ b/lib/tar/internal.h
@@ -13,6 +13,7 @@
#include <string.h>
#include <stdlib.h>
+#include <limits.h>
#include <ctype.h>
#include <stdio.h>
diff --git a/lib/tar/read_header.c b/lib/tar/read_header.c
index 0591879..2918d09 100644
--- a/lib/tar/read_header.c
+++ b/lib/tar/read_header.c
@@ -155,17 +155,17 @@ static int decode_header(const tar_header_t *hdr, unsigned int set_by_pax,
break;
}
-#if SIZEOF_TIME_T < 8
- if (out->mtime > (sqfs_s64)INT32_MAX) {
- out->sb.st_mtime = INT32_MAX;
- } else if (out->mtime < (sqfs_s64)INT32_MIN) {
- out->sb.st_mtime = INT32_MIN;
+ if (sizeof(time_t) * CHAR_BIT < 64) {
+ if (out->mtime > (sqfs_s64)INT32_MAX) {
+ out->sb.st_mtime = INT32_MAX;
+ } else if (out->mtime < (sqfs_s64)INT32_MIN) {
+ out->sb.st_mtime = INT32_MIN;
+ } else {
+ out->sb.st_mtime = out->mtime;
+ }
} else {
out->sb.st_mtime = out->mtime;
}
-#else
- out->sb.st_mtime = out->mtime;
-#endif
return 0;
}
diff --git a/tests/tar_gnu.c b/tests/tar_gnu.c
index 9d0b010..9746cb0 100644
--- a/tests/tar_gnu.c
+++ b/tests/tar_gnu.c
@@ -95,11 +95,13 @@ int main(void)
TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
TEST_EQUAL_UI(hdr.sb.st_size, 5);
-#if SIZEOF_TIME_T < 8
- TEST_EQUAL_UI(hdr.sb.st_mtime, INT32_MAX);
-#else
- TEST_EQUAL_UI(hdr.sb.st_mtime, 8589934592L);
-#endif
+
+ if (sizeof(time_t) * CHAR_BIT < 64) {
+ TEST_EQUAL_UI(hdr.sb.st_mtime, INT32_MAX);
+ } else {
+ TEST_EQUAL_UI(hdr.sb.st_mtime, 8589934592L);
+ }
+
TEST_EQUAL_UI(hdr.mtime, 8589934592L);
TEST_STR_EQUAL(hdr.name, "input.txt");
TEST_ASSERT(!hdr.unknown_record);
diff --git a/tests/tar_pax.c b/tests/tar_pax.c
index f2e4c5f..86dc186 100644
--- a/tests/tar_pax.c
+++ b/tests/tar_pax.c
@@ -78,11 +78,13 @@ int main(void)
TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
TEST_EQUAL_UI(hdr.sb.st_size, 5);
-#if SIZEOF_TIME_T < 8
- TEST_EQUAL_UI(hdr.sb.st_mtime, INT32_MAX);
-#else
- TEST_EQUAL_UI(hdr.sb.st_mtime, 8589934592L);
-#endif
+
+ if (sizeof(time_t) * CHAR_BIT < 64) {
+ TEST_EQUAL_UI(hdr.sb.st_mtime, INT32_MAX);
+ } else {
+ TEST_EQUAL_UI(hdr.sb.st_mtime, 8589934592L);
+ }
+
TEST_EQUAL_UI(hdr.mtime, 8589934592L);
TEST_STR_EQUAL(hdr.name, "input.txt");
TEST_ASSERT(!hdr.unknown_record);
diff --git a/tests/tar_ustar.c b/tests/tar_ustar.c
index 8d4c828..b794e30 100644
--- a/tests/tar_ustar.c
+++ b/tests/tar_ustar.c
@@ -110,11 +110,13 @@ int main(void)
TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
TEST_EQUAL_UI(hdr.sb.st_size, 5);
-#if SIZEOF_TIME_T < 8
- TEST_EQUAL_UI(hdr.sb.st_mtime, INT32_MAX);
-#else
- TEST_EQUAL_UI(hdr.sb.st_mtime, 8589934592L);
-#endif
+
+ if (sizeof(time_t) * CHAR_BIT < 64) {
+ TEST_EQUAL_UI(hdr.sb.st_mtime, INT32_MAX);
+ } else {
+ TEST_EQUAL_UI(hdr.sb.st_mtime, 8589934592L);
+ }
+
TEST_EQUAL_UI(hdr.mtime, 8589934592L);
TEST_STR_EQUAL(hdr.name, "input.txt");
TEST_ASSERT(!hdr.unknown_record);
diff --git a/tests/test.h b/tests/test.h
index 4e05dac..7d38fd0 100644
--- a/tests/test.h
+++ b/tests/test.h
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
#include <stdio.h>
#include <errno.h>