summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2025-05-16 11:38:20 +0200
committerGravatar Nikias Bassen2025-05-16 11:38:20 +0200
commitcd095eb9b66bb3925c7a55b763cbe81bba5d55d9 (patch)
treee69f10786f1a453f85285c22e1d804dc8c958fd5
parentc915351cb322d041afabc04f780eb35142cdaea5 (diff)
downloadlibimobiledevice-glue-cd095eb9b66bb3925c7a55b763cbe81bba5d55d9.tar.gz
libimobiledevice-glue-cd095eb9b66bb3925c7a55b763cbe81bba5d55d9.tar.bz2
Use plist_new_unix_date API when available
-rw-r--r--configure.ac17
-rw-r--r--src/opack.c14
2 files changed, 29 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index 0c26ea6..013b093 100644
--- a/configure.ac
+++ b/configure.ac
@@ -93,6 +93,23 @@ AM_CONDITIONAL(WIN32, test x$win32 = xtrue)
AC_CHECK_MEMBER(struct dirent.d_type, AC_DEFINE(HAVE_DIRENT_D_TYPE, 1, [define if struct dirent has member d_type]),, [#include <dirent.h>])
+CACHED_CFLAGS="$CFLAGS"
+CFLAGS+=" $libplist_CFLAGS"
+
+# check if libplist has plist_new_unix_date()
+AC_CACHE_CHECK(for plist_new_unix_date, ac_cv_plist_unix_date,
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #include <plist/plist.h>
+ ]], [[
+ plist_new_unix_date(0);
+ return 0;
+ ]])],[ac_cv_plist_unix_date=yes],[ac_cv_plist_unix_date=no]))
+if test "$ac_cv_plist_unix_date" = "yes"; then
+ AC_DEFINE(HAVE_PLIST_UNIX_DATE, 1, [Define if libplist has new unix date API (>= 2.7.0)])
+fi
+
+CFLAGS="$CACHED_CFLAGS"
+
AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wmissing-declarations -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default -Wno-unused-parameter -fsigned-char -fvisibility=hidden")
if test "x$enable_static" = "xyes" -a "x$enable_shared" = "xno"; then
diff --git a/src/opack.c b/src/opack.c
index 8a9264a..e0fe9cb 100644
--- a/src/opack.c
+++ b/src/opack.c
@@ -140,12 +140,18 @@ static void opack_encode_node(plist_t node, struct char_buf* cbuf)
}
} break;
case PLIST_DATE: {
+#ifdef HAVE_PLIST_UNIX_DATE
+ int64_t sec = 0;
+ plist_get_unix_date_val(node, &sec);
+ sec -= MAC_EPOCH;
+ double dval = (double)sec;
+#else
int32_t sec = 0;
int32_t usec = 0;
plist_get_date_val(node, &sec, &usec);
time_t tsec = sec;
- tsec -= MAC_EPOCH;
double dval = (double)tsec + ((double)usec / 1000000);
+#endif
uint8_t blen = 0x06;
char_buf_append(cbuf, 1, &blen);
uint64_t u64val = 0;
@@ -272,10 +278,14 @@ static int opack_decode_obj(unsigned char** p, unsigned char* end, plist_t* plis
(*p)++;
double value = *(double*)*p;
time_t sec = (time_t)value;
+#ifdef HAVE_PLIST_UNIX_DATE
+ *plist_out = plist_new_unix_date(sec + MAC_EPOCH);
+#else
value -= sec;
uint32_t usec = value * 1000000;
- (*p)+=8;
*plist_out = plist_new_date(sec, usec);
+#endif
+ (*p)+=8;
} else if (type >= 0x08 && type <= 0x36) {
/* numerical type */
(*p)++;