Skip to content

Commit

Permalink
Add new __BARE_METAL__ target flag
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sidcha committed Nov 10, 2024
1 parent 82eeb9b commit 01950bf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
23 changes: 23 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 01950bf

Please sign in to comment.