diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-20 09:34:06 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-20 09:34:06 -0400 |
commit | 84f01a67bdaef4dbff787caa4b076ed60e257c51 (patch) | |
tree | 0d264e5a6232071a8277c59216f85aac64583459 /sway/log.c | |
parent | 579fe70ed92ce65d5a761ebdbb6c458b5f919687 (diff) | |
parent | f8787ce69e35be4569aa76a2e35f540b20ed40a4 (diff) |
Merge pull request #75 from minus7/ipc
i3 IPC
Diffstat (limited to 'sway/log.c')
-rw-r--r-- | sway/log.c | 33 |
1 files changed, 32 insertions, 1 deletions
@@ -1,10 +1,13 @@ #include "log.h" +#include "sway.h" #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <signal.h> +#include <errno.h> +#include <string.h> int colored = 1; int v = 0; @@ -40,7 +43,7 @@ void sway_abort(const char *format, ...) { vfprintf(stderr, format, args); va_end(args); fprintf(stderr, "\n"); - exit(1); + sway_terminate(); } void sway_log(int verbosity, const char* format, ...) { @@ -66,6 +69,34 @@ void sway_log(int verbosity, const char* format, ...) { } } +void sway_log_errno(int verbosity, char* format, ...) { + if (verbosity <= v) { + int c = verbosity; + if (c > sizeof(verbosity_colors) / sizeof(char *)) { + c = sizeof(verbosity_colors) / sizeof(char *) - 1; + } + + if (colored) { + fprintf(stderr, verbosity_colors[c]); + } + + va_list args; + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); + + fprintf(stderr, ": "); + char error[256]; + strerror_r(errno, error, sizeof(error)); + fprintf(stderr, error); + + if (colored) { + fprintf(stderr, "\x1B[0m"); + } + fprintf(stderr, "\n"); + } +} + bool sway_assert(bool condition, const char* format, ...) { if (condition) { return true; |