Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/hal/macros.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
Expand All @@ -26,7 +27,15 @@
".balign 4\n" /* Word alignment */\
".section \".text\"\n") /* Restore section */

#define HAL_COLOR(seq) (isatty(STDERR_FILENO) ? (seq) : "")
/* isatty() sets errno (ENOTTY) when stderr is not a terminal, and the colour test runs before a message's
arguments are evaluated: keep errno, or every strerror(errno) logged to a file or pipe reads "Not a tty" */
static inline int hal_stderr_is_tty(void) {
int err = errno, tty = isatty(STDERR_FILENO);
errno = err;
return tty;
}

#define HAL_COLOR(seq) (hal_stderr_is_tty() ? (seq) : "")

#define HAL_DANGER(mod, x, ...) \
do { \
Expand Down