Skip to content

Commit cd095eb

Browse files
committed
Use plist_new_unix_date API when available
1 parent c915351 commit cd095eb

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

configure.ac

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,23 @@ AM_CONDITIONAL(WIN32, test x$win32 = xtrue)
9393

9494
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>])
9595

96+
CACHED_CFLAGS="$CFLAGS"
97+
CFLAGS+=" $libplist_CFLAGS"
98+
99+
# check if libplist has plist_new_unix_date()
100+
AC_CACHE_CHECK(for plist_new_unix_date, ac_cv_plist_unix_date,
101+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
102+
#include <plist/plist.h>
103+
]], [[
104+
plist_new_unix_date(0);
105+
return 0;
106+
]])],[ac_cv_plist_unix_date=yes],[ac_cv_plist_unix_date=no]))
107+
if test "$ac_cv_plist_unix_date" = "yes"; then
108+
AC_DEFINE(HAVE_PLIST_UNIX_DATE, 1, [Define if libplist has new unix date API (>= 2.7.0)])
109+
fi
110+
111+
CFLAGS="$CACHED_CFLAGS"
112+
96113
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")
97114

98115
if test "x$enable_static" = "xyes" -a "x$enable_shared" = "xno"; then

src/opack.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,18 @@ static void opack_encode_node(plist_t node, struct char_buf* cbuf)
140140
}
141141
} break;
142142
case PLIST_DATE: {
143+
#ifdef HAVE_PLIST_UNIX_DATE
144+
int64_t sec = 0;
145+
plist_get_unix_date_val(node, &sec);
146+
sec -= MAC_EPOCH;
147+
double dval = (double)sec;
148+
#else
143149
int32_t sec = 0;
144150
int32_t usec = 0;
145151
plist_get_date_val(node, &sec, &usec);
146152
time_t tsec = sec;
147-
tsec -= MAC_EPOCH;
148153
double dval = (double)tsec + ((double)usec / 1000000);
154+
#endif
149155
uint8_t blen = 0x06;
150156
char_buf_append(cbuf, 1, &blen);
151157
uint64_t u64val = 0;
@@ -272,10 +278,14 @@ static int opack_decode_obj(unsigned char** p, unsigned char* end, plist_t* plis
272278
(*p)++;
273279
double value = *(double*)*p;
274280
time_t sec = (time_t)value;
281+
#ifdef HAVE_PLIST_UNIX_DATE
282+
*plist_out = plist_new_unix_date(sec + MAC_EPOCH);
283+
#else
275284
value -= sec;
276285
uint32_t usec = value * 1000000;
277-
(*p)+=8;
278286
*plist_out = plist_new_date(sec, usec);
287+
#endif
288+
(*p)+=8;
279289
} else if (type >= 0x08 && type <= 0x36) {
280290
/* numerical type */
281291
(*p)++;

0 commit comments

Comments
 (0)