utils: add the etrace macro

Same as the existing trace but prints to stderr. And #include stdio so
we can use this file as-is instead of needing extra includes.

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/351>
This commit is contained in:
Peter Hutterer 2025-07-18 11:14:18 +10:00
parent 0831303a70
commit 297f95efac

View file

@ -29,6 +29,7 @@
#include "config.h"
#include <unistd.h>
#include <stdio.h>
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
#define ARRAY_FOR_EACH(_arr, _elem) \
@ -72,3 +73,10 @@
snprintf(buf_, sizeof(buf_), __VA_ARGS__); \
printf("\x1B[0;34m" "%s():%d - " "\x1B[0;31m" "%s" "\x1B[0m" "\n", __func__, __LINE__, buf_); \
} while (0)
#define etrace(...) \
do { \
char buf_[1024]; \
snprintf(buf_, sizeof(buf_), __VA_ARGS__); \
fprintf(stderr, "\x1B[0;34m" "%s():%d - " "\x1B[0;31m" "%s" "\x1B[0m" "\n", __func__, __LINE__, buf_); \
} while (0)