1*b4d5e3c9Sratchov /* $OpenBSD: utils.h,v 1.4 2024/12/22 14:17:45 ratchov Exp $ */ 210ba9548Sratchov /* 310ba9548Sratchov * Copyright (c) 2003-2012 Alexandre Ratchov <alex@caoua.org> 410ba9548Sratchov * 510ba9548Sratchov * Permission to use, copy, modify, and distribute this software for any 610ba9548Sratchov * purpose with or without fee is hereby granted, provided that the above 710ba9548Sratchov * copyright notice and this permission notice appear in all copies. 810ba9548Sratchov * 910ba9548Sratchov * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1010ba9548Sratchov * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1110ba9548Sratchov * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1210ba9548Sratchov * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1310ba9548Sratchov * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1410ba9548Sratchov * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1510ba9548Sratchov * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1610ba9548Sratchov */ 1710ba9548Sratchov 1810ba9548Sratchov #ifndef UTILS_H 1910ba9548Sratchov #define UTILS_H 2010ba9548Sratchov 2110ba9548Sratchov #include <stddef.h> 2210ba9548Sratchov 23*b4d5e3c9Sratchov #define logx(n, ...) \ 24*b4d5e3c9Sratchov do { \ 25*b4d5e3c9Sratchov if (log_level >= (n)) \ 26*b4d5e3c9Sratchov log_do(__VA_ARGS__); \ 27*b4d5e3c9Sratchov } while (0) 28*b4d5e3c9Sratchov 2910ba9548Sratchov void panic(void); 3010ba9548Sratchov void log_flush(void); 31*b4d5e3c9Sratchov void log_do(const char *, ...) __attribute__((__format__ (printf, 1, 2))); 3210ba9548Sratchov 3310ba9548Sratchov void *xmalloc(size_t); 3410ba9548Sratchov char *xstrdup(char *); 35d2b3dcecSratchov void xfree(void *); 3610ba9548Sratchov 3710ba9548Sratchov /* 3810ba9548Sratchov * Log levels: 3910ba9548Sratchov * 4010ba9548Sratchov * 0 - fatal errors: bugs, asserts, internal errors. 4110ba9548Sratchov * 1 - warnings: bugs in clients, failed allocations, non-fatal errors. 4210ba9548Sratchov * 2 - misc information (hardware parameters, incoming clients) 4310ba9548Sratchov * 3 - structural changes (eg. new streams, new parameters ...) 4410ba9548Sratchov * 4 - data blocks and messages 4510ba9548Sratchov */ 4610ba9548Sratchov extern unsigned int log_level; 4710ba9548Sratchov extern unsigned int log_sync; 4810ba9548Sratchov 4910ba9548Sratchov #endif 50