X-Git-Url: http://git.squeep.com/?p=reservoir_sample;a=blobdiff_plain;f=notify.c;fp=notify.c;h=78e7e44065034a21b46cb0e5a5c77530304bcf89;hp=0000000000000000000000000000000000000000;hb=694d004f3c2a521672d468a8bc77dc2b635ffd9f;hpb=6bd502bb5a3c61bb3b0cd76d613973346e8a5d90 diff --git a/notify.c b/notify.c new file mode 100644 index 0000000..78e7e44 --- /dev/null +++ b/notify.c @@ -0,0 +1,36 @@ +#include +#include +#include + +#include "notify.h" + +/* common messaging hook */ + +/* generic notifier */ +static +void notify_default_(unsigned int l, const char *fmt, ...) { + FILE *f = stderr; + va_list ap; + const char *level_names[] = { + "FATAL", + "ERROR", + "INFO", + "VERBOSE", + "DEBUG", + "DEBUG_LOCK", + }; + const size_t levels = sizeof level_names / sizeof *level_names; + + va_start(ap, fmt); + flockfile(f); + if (l < levels) { + fprintf(f, "%s", level_names[l]); + } else { + fprintf(f, "[%d] ", l); + } + vfprintf(f, fmt, ap); + funlockfile(f); + va_end(ap); +} + +notify_fn_t *notify __attribute__((format(printf, 2, 3))) = notify_default_;