1*7b639200Sratchov /* $OpenBSD: utils.h,v 1.8 2024/12/20 07:35:56 ratchov Exp $ */ 287bc9f6aSratchov /* 387bc9f6aSratchov * Copyright (c) 2003-2012 Alexandre Ratchov <alex@caoua.org> 487bc9f6aSratchov * 587bc9f6aSratchov * Permission to use, copy, modify, and distribute this software for any 687bc9f6aSratchov * purpose with or without fee is hereby granted, provided that the above 787bc9f6aSratchov * copyright notice and this permission notice appear in all copies. 887bc9f6aSratchov * 987bc9f6aSratchov * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1087bc9f6aSratchov * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1187bc9f6aSratchov * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1287bc9f6aSratchov * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1387bc9f6aSratchov * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1487bc9f6aSratchov * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1587bc9f6aSratchov * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1687bc9f6aSratchov */ 1787bc9f6aSratchov 1887bc9f6aSratchov #ifndef UTILS_H 1987bc9f6aSratchov #define UTILS_H 2087bc9f6aSratchov 2190426fa6Sratchov #include <stddef.h> 2287bc9f6aSratchov 23*7b639200Sratchov #define logx(n, ...) \ 24*7b639200Sratchov do { \ 25*7b639200Sratchov if (log_level >= (n)) \ 26*7b639200Sratchov log_do(__VA_ARGS__); \ 27*7b639200Sratchov } while (0) 28*7b639200Sratchov 2987bc9f6aSratchov void panic(void); 3087bc9f6aSratchov void log_flush(void); 31*7b639200Sratchov void log_do(const char *, ...) __attribute__((__format__ (printf, 1, 2))); 3287bc9f6aSratchov 3387bc9f6aSratchov void *xmalloc(size_t); 3487bc9f6aSratchov char *xstrdup(char *); 3587bc9f6aSratchov void xfree(void *); 3687bc9f6aSratchov 3770d959fbSratchov /* 3870d959fbSratchov * Log levels: 3970d959fbSratchov * 4070d959fbSratchov * 0 - fatal errors: bugs, asserts, internal errors. 4170d959fbSratchov * 1 - warnings: bugs in clients, failed allocations, non-fatal errors. 4270d959fbSratchov * 2 - misc information (hardware parameters, incoming clients) 4370d959fbSratchov * 3 - structural changes (eg. new streams, new parameters ...) 4470d959fbSratchov * 4 - data blocks and messages 4570d959fbSratchov */ 4670d959fbSratchov extern unsigned int log_level; 4787bc9f6aSratchov extern unsigned int log_sync; 4887bc9f6aSratchov 4987bc9f6aSratchov #endif 50