From 658ff717c6b46b2963d48cace7c94f396f44963c Mon Sep 17 00:00:00 2001 From: Andrew Dunham Date: Sun, 14 Nov 2021 02:06:56 -0500 Subject: [PATCH] gfunc: fix build error on macOS --- configure.ac | 5 +++++ gfunc.c | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index fa477377..a25306a4 100644 --- a/configure.ac +++ b/configure.ac @@ -122,6 +122,11 @@ if test ${sysconfdir} = '${prefix}/etc'; then sysconfdir='/etc' fi +# fix macOS build error +AC_CHECK_SIZEOF(off_t) +AC_CHECK_SIZEOF(long long) +AC_CHECK_SIZEOF(long) + AC_CONFIG_FILES([GNUmakefile po/GNUmakefile rdup.h diff --git a/gfunc.c b/gfunc.c index a7755465..619c13b0 100644 --- a/gfunc.c +++ b/gfunc.c @@ -14,6 +14,15 @@ #define SHA1_DIGEST_SIZE 20 #endif /* HAVE_LIBNETTLE */ +/* see https://github.com/miekg/rdup/pull/47 for why this is necessary */ +#if SIZEOF_OFF_T == SIZEOF_LONG_LONG +#define OFF_T_FORMAT "lld" +#elif SIZEOF_OFF_T == SIZEOF_LONG +#define OFF_T_FORMAT "ld" +#else +#error Unknown sizeof(off_t) +#endif + extern gboolean opt_removed; extern gboolean opt_modified; extern gboolean opt_skip; @@ -293,11 +302,11 @@ static void entry_print_data(FILE * out, char n, struct rdup *e) } /* links */ if (S_ISLNK(e->f_mode) || e->f_lnk == 1) { - fprintf(out, "%jd", e->f_size); + fprintf(out, "%" OFF_T_FORMAT, e->f_size); break; } - fprintf(out, "%jd", e->f_size); + fprintf(out, "%" OFF_T_FORMAT, e->f_size); break; case 'H': /* sha1 hash */ if (S_ISREG(e->f_mode)) {