mirror of
https://github.com/swaywm/sway.git
synced 2026-04-29 06:46:22 -04:00
Implement sway_log_errno using _sway_log to reduce code duplication
This commit is contained in:
parent
8f67903909
commit
a32f4adec4
2 changed files with 5 additions and 29 deletions
28
common/log.c
28
common/log.c
|
|
@ -8,8 +8,6 @@
|
|||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stringop.h>
|
||||
|
||||
int colored = 1;
|
||||
|
|
@ -90,32 +88,6 @@ void _sway_log(const char *filename, int line, log_importance_t verbosity, const
|
|||
}
|
||||
}
|
||||
|
||||
void sway_log_errno(log_importance_t verbosity, char* format, ...) {
|
||||
if (verbosity <= v) {
|
||||
unsigned int c = verbosity;
|
||||
if (c > sizeof(verbosity_colors) / sizeof(char *) - 1) {
|
||||
c = sizeof(verbosity_colors) / sizeof(char *) - 1;
|
||||
}
|
||||
|
||||
if (colored && isatty(STDERR_FILENO)) {
|
||||
fprintf(stderr, "%s", verbosity_colors[c]);
|
||||
}
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vfprintf(stderr, format, args);
|
||||
va_end(args);
|
||||
|
||||
fprintf(stderr, ": ");
|
||||
fprintf(stderr, "%s", strerror(errno));
|
||||
|
||||
if (colored && isatty(STDERR_FILENO)) {
|
||||
fprintf(stderr, "\x1B[0m");
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
bool _sway_assert(bool condition, const char* format, ...) {
|
||||
if (condition) {
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue