From e641699717e5e1a58da975ec7357baefb8526095 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 8 Mar 2017 22:03:13 +0100 Subject: make: fix compilation on android --- src/blogc-make/ctx.c | 39 ++++++++++++++++++++++----------------- src/blogc-make/ctx.h | 21 +++++++++++++++++---- src/blogc-make/rules.c | 6 +++--- 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/blogc-make/ctx.c b/src/blogc-make/ctx.c index 753aadf..636a39a 100644 --- a/src/blogc-make/ctx.c +++ b/src/blogc-make/ctx.c @@ -36,14 +36,13 @@ bm_filectx_new(bm_ctx_t *ctx, const char *filename) struct stat buf; if (0 != stat(f, &buf)) { - struct timespec ts; - ts.tv_sec = 0; - ts.tv_nsec = 0; - rv->timestamp = ts; + rv->tv_sec = 0; + rv->tv_nsec = 0; rv->readable = false; } else { - rv->timestamp = buf.st_mtim; + rv->tv_sec = buf.st_mtim_tv_sec; + rv->tv_nsec = buf.st_mtim_tv_nsec; rv->readable = true; } @@ -52,7 +51,7 @@ bm_filectx_new(bm_ctx_t *ctx, const char *filename) bool -bm_filectx_changed(bm_filectx_t *ctx, struct timespec *ts) +bm_filectx_changed(bm_filectx_t *ctx, time_t *tv_sec, long *tv_nsec) { if (ctx == NULL) return false; @@ -60,16 +59,20 @@ bm_filectx_changed(bm_filectx_t *ctx, struct timespec *ts) struct stat buf; if (0 == stat(ctx->path, &buf)) { - if (buf.st_mtim.tv_sec == ctx->timestamp.tv_sec) { - if (buf.st_mtim.tv_nsec > ctx->timestamp.tv_nsec) { - if (ts != NULL) - *ts = buf.st_mtim; + if (buf.st_mtim_tv_sec == ctx->tv_sec) { + if (buf.st_mtim_tv_nsec > ctx->tv_nsec) { + if (tv_sec != NULL) + *tv_sec = buf.st_mtim_tv_sec; + if (tv_nsec != NULL) + *tv_nsec = buf.st_mtim_tv_nsec; return true; } } - else if (buf.st_mtim.tv_sec > ctx->timestamp.tv_sec) { - if (ts != NULL) - *ts = buf.st_mtim; + else if (buf.st_mtim_tv_sec > ctx->tv_sec) { + if (tv_sec != NULL) + *tv_sec = buf.st_mtim_tv_sec; + if (tv_nsec != NULL) + *tv_nsec = buf.st_mtim_tv_nsec; return true; } } @@ -84,12 +87,14 @@ bm_filectx_reload(bm_filectx_t *ctx) if (ctx == NULL) return; - struct timespec ts; + time_t tv_sec; + long tv_nsec; - if (!bm_filectx_changed(ctx, &ts)) + if (!bm_filectx_changed(ctx, &tv_sec, &tv_nsec)) return; - ctx->timestamp = ts; + ctx->tv_sec = tv_sec; + ctx->tv_nsec = tv_nsec; ctx->readable = true; } @@ -222,7 +227,7 @@ bm_ctx_reload(bm_ctx_t *ctx) if (ctx == NULL || ctx->settings_fctx == NULL) return false; - if (bm_filectx_changed(ctx->settings_fctx, NULL)) { + if (bm_filectx_changed(ctx->settings_fctx, NULL, NULL)) { // reload everything! we could just reload settings_fctx, as this // would force rebuilding everything, but we need to know new/deleted // files diff --git a/src/blogc-make/ctx.h b/src/blogc-make/ctx.h index e36fa4c..67d0a7d 100644 --- a/src/blogc-make/ctx.h +++ b/src/blogc-make/ctx.h @@ -16,15 +16,28 @@ #include "../common/utils.h" #ifdef __APPLE__ -#ifndef st_mtim -#define st_mtim st_mtimespec +#define st_mtim_tv_sec st_mtimespec.tv_sec +#define st_mtim_tv_nsec st_mtimespec.tv_nsec #endif + +#ifdef __ANDROID__ +#define st_mtim_tv_sec st_mtime +#define st_mtim_tv_nsec st_mtime_nsec +#endif + +#ifndef st_mtim_tv_sec +#define st_mtim_tv_sec st_mtim.tv_sec #endif +#ifndef st_mtim_tv_nsec +#define st_mtim_tv_nsec st_mtim.tv_nsec +#endif + typedef struct { char *path; char *short_path; - struct timespec timestamp; + time_t tv_sec; + long tv_nsec; bool readable; } bm_filectx_t; @@ -50,7 +63,7 @@ typedef struct { } bm_ctx_t; bm_filectx_t* bm_filectx_new(bm_ctx_t *ctx, const char *filename); -bool bm_filectx_changed(bm_filectx_t *ctx, struct timespec *ts); +bool bm_filectx_changed(bm_filectx_t *ctx, time_t *tv_sec, long *tv_nsec); void bm_filectx_reload(bm_filectx_t *ctx); void bm_filectx_free(bm_filectx_t *fctx); bm_ctx_t* bm_ctx_new(bm_ctx_t *base, const char *settings_file, diff --git a/src/blogc-make/rules.c b/src/blogc-make/rules.c index ca4b376..52afb2d 100644 --- a/src/blogc-make/rules.c +++ b/src/blogc-make/rules.c @@ -790,13 +790,13 @@ bm_rule_need_rebuild(bc_slist_t *sources, bm_filectx_t *settings, rv = true; break; } - if (source->timestamp.tv_sec == output->timestamp.tv_sec) { - if (source->timestamp.tv_nsec > output->timestamp.tv_nsec) { + if (source->tv_sec == output->tv_sec) { + if (source->tv_nsec > output->tv_nsec) { rv = true; break; } } - else if (source->timestamp.tv_sec > output->timestamp.tv_sec) { + else if (source->tv_sec > output->tv_sec) { rv = true; break; } -- cgit v1.2.3-18-g5258