From 01950bf322f8134ba81da66777b145d069825f7e Mon Sep 17 00:00:00 2001 From: Siddharth Chandrasekaran Date: Sun, 10 Nov 2024 17:39:35 +0100 Subject: [PATCH] Add new __BARE_METAL__ target flag This flag should be defined when c-utils is built for bare metal (embedded) targets. This change is not exhaustive; more code needs to be moved into this section as and when discovered. The idea was suggested in #28; this commit is just small variation to the proposed change there. Signed-off-by: Siddharth Chandrasekaran --- src/logger.c | 3 ++- src/utils.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/logger.c b/src/logger.c index e2f8418..2eb48e8 100644 --- a/src/logger.c +++ b/src/logger.c @@ -59,17 +59,18 @@ static const char *log_level_names[LOG_MAX_LEVEL] = { static inline void logger_log_set_color(logger_t *ctx, const char *color) { +#if !defined(__BARE_METAL__) size_t ret, len; if (ctx->flags & LOGGER_FLAG_NO_COLORS) return; - if (ctx->file && isatty(fileno(ctx->file))) { len = strnlen(color, 8); ret = write(fileno(ctx->file), color, len); assert(ret == len); ARG_UNUSED(ret); /* squash warning in Release builds */ } +#endif } static const char *get_tstamp() diff --git a/src/utils.c b/src/utils.c index 272cd38..dc103ac 100644 --- a/src/utils.c +++ b/src/utils.c @@ -148,6 +148,29 @@ int add_iso8601_utc_datetime(char *buf, size_t size) return strftime(buf, size, "%Y-%m-%dT%H:%M:%SZ", &timeinfo); } +#elif defined(__BARE_METAL__) + +struct timeval { + long tv_sec; // seconds since epoch + long tv_usec; // microseconds +}; + +struct timezone { + int tz_minuteswest; // minutes west of UTC + int tz_dsttime; // daylight saving time flag +}; + +int gettimeofday(struct timeval * tp, struct timezone * tzp) +{ + tp->tv_sec = 0; + tp->tv_usec = 0; + return 0; +} + +int add_iso8601_utc_datetime(char* buf, size_t size) { + return 0; +} + #else #error Platform test failed