#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#endif
}
+#if !defined(TIME_MAX)
+#define TIME_MAX (((time_t)0 < (time_t)-1) ? (time_t)~0 : \
+ sizeof(time_t) == sizeof(long long) ? (time_t)LLONG_MAX : \
+ sizeof(time_t) == sizeof(long) ? (time_t)LONG_MAX : \
+ sizeof(time_t) == sizeof(int) ? (time_t)INT_MAX : \
+ sizeof(time_t) == sizeof(short) ? (time_t)SHRT_MAX : \
+ 1 /* I give up */)
+#endif
+#if !defined(TIME_MIN)
+#define TIME_MIN (((time_t)0 < (time_t)-1) ? (time_t)0 : \
+ sizeof(time_t) == sizeof(long long) ? (time_t)LLONG_MIN : \
+ sizeof(time_t) == sizeof(long) ? (time_t)LONG_MIN : \
+ sizeof(time_t) == sizeof(int) ? (time_t)INT_MIN : \
+ sizeof(time_t) == sizeof(short) ? (time_t)SHRT_MIN : \
+ -1 /* I give up */)
+#endif
+
#endif
static size_t mtree_strnlen(const char *, size_t);
#endif
-/*
- * There's no standard for TIME_T_MAX/TIME_T_MIN. So we compute them
- * here. TODO: Move this to configure time, but be careful
- * about cross-compile environments.
- */
-static int64_t
-get_time_t_max(void)
-{
-#if defined(TIME_T_MAX)
- return TIME_T_MAX;
-#else
- /* ISO C allows time_t to be a floating-point type,
- but POSIX requires an integer type. The following
- should work on any system that follows the POSIX
- conventions. */
- if (((time_t)0) < ((time_t)-1)) {
- /* Time_t is unsigned */
- return (~(time_t)0);
- } else {
- /* Time_t is signed. */
- /* Assume it's the same as int64_t or int32_t */
- if (sizeof(time_t) == sizeof(int64_t)) {
- return (time_t)INT64_MAX;
- } else {
- return (time_t)INT32_MAX;
- }
- }
-#endif
-}
-
-static int64_t
-get_time_t_min(void)
-{
-#if defined(TIME_T_MIN)
- return TIME_T_MIN;
-#else
- if (((time_t)0) < ((time_t)-1)) {
- /* Time_t is unsigned */
- return (time_t)0;
- } else {
- /* Time_t is signed. */
- if (sizeof(time_t) == sizeof(int64_t)) {
- return (time_t)INT64_MIN;
- } else {
- return (time_t)INT32_MIN;
- }
- }
-#endif
-}
-
#ifdef HAVE_STRNLEN
#define mtree_strnlen(a,b) strnlen(a,b)
#else
}
if (strcmp(key, "time") == 0) {
int64_t m;
- int64_t my_time_t_max = get_time_t_max();
- int64_t my_time_t_min = get_time_t_min();
long ns = 0;
*parsed_kws |= MTREE_HAS_MTIME;
else
ns = (long)v;
}
- if (m > my_time_t_max)
- m = my_time_t_max;
- else if (m < my_time_t_min)
- m = my_time_t_min;
+ if (m > TIME_MAX)
+ m = TIME_MAX;
+ else if (m < TIME_MIN)
+ m = TIME_MIN;
archive_entry_set_mtime(entry, (time_t)m, ns);
return (ARCHIVE_OK);
}
static const size_t acl_limit = 131072; /* Longest textual ACL: 128kiB */
static const int64_t entry_limit = 0xfffffffffffffffLL; /* 2^60 bytes = 1 ExbiByte */
-/*
- * There's no standard for TIME_T_MAX. So we compute it
- * here. TODO: Move this to configure time, but be careful
- * about cross-compile environments.
- */
-static time_t
-get_time_t_max(void)
-{
-#if defined(TIME_T_MAX)
- return TIME_T_MAX;
-#else
- /* ISO C allows time_t to be a floating-point type,
- but POSIX requires an integer type. The following
- should work on any system that follows the POSIX
- conventions. */
- if (((time_t)0) < ((time_t)-1)) {
- /* Time_t is unsigned */
- return (~(time_t)0);
- } else {
- /* Time_t is signed. */
- /* Assume it's the same as int64_t or int32_t */
- if (sizeof(time_t) == sizeof(int64_t)) {
- return (time_t)INT64_MAX;
- } else {
- return (time_t)INT32_MAX;
- }
- }
-#endif
-}
-
int
archive_read_support_format_gnutar(struct archive *a)
{
int64_t t64 = tar_atol(header->mtime, sizeof(header->mtime));
time_t t = (time_t)t64;
if ((int64_t)t != t64) { /* time_t overflowed */
- t = get_time_t_max();
+ t = TIME_MAX;
}
archive_entry_set_mtime(entry, t, 0);
}