Skip to content

Commit 01950bf

Browse files
committed
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 <sidcha.dev@gmail.com>
1 parent 82eeb9b commit 01950bf

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/logger.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,18 @@ static const char *log_level_names[LOG_MAX_LEVEL] = {
5959

6060
static inline void logger_log_set_color(logger_t *ctx, const char *color)
6161
{
62+
#if !defined(__BARE_METAL__)
6263
size_t ret, len;
6364

6465
if (ctx->flags & LOGGER_FLAG_NO_COLORS)
6566
return;
66-
6767
if (ctx->file && isatty(fileno(ctx->file))) {
6868
len = strnlen(color, 8);
6969
ret = write(fileno(ctx->file), color, len);
7070
assert(ret == len);
7171
ARG_UNUSED(ret); /* squash warning in Release builds */
7272
}
73+
#endif
7374
}
7475

7576
static const char *get_tstamp()

src/utils.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,29 @@ int add_iso8601_utc_datetime(char *buf, size_t size)
148148
return strftime(buf, size, "%Y-%m-%dT%H:%M:%SZ", &timeinfo);
149149
}
150150

151+
#elif defined(__BARE_METAL__)
152+
153+
struct timeval {
154+
long tv_sec; // seconds since epoch
155+
long tv_usec; // microseconds
156+
};
157+
158+
struct timezone {
159+
int tz_minuteswest; // minutes west of UTC
160+
int tz_dsttime; // daylight saving time flag
161+
};
162+
163+
int gettimeofday(struct timeval * tp, struct timezone * tzp)
164+
{
165+
tp->tv_sec = 0;
166+
tp->tv_usec = 0;
167+
return 0;
168+
}
169+
170+
int add_iso8601_utc_datetime(char* buf, size_t size) {
171+
return 0;
172+
}
173+
151174
#else
152175

153176
#error Platform test failed

0 commit comments

Comments
 (0)