diff options
| author | Mattias Andrée <m@maandree.se> | 2025-02-09 15:04:27 +0100 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2025-02-09 15:04:27 +0100 |
| commit | ed004cba0e8d1d383def76f795b1e63ba0aaa89a (patch) | |
| tree | b12e5f23329f631b66c19b932551e4dff5aa477f /liblog_use_output.c | |
| download | liblog-ed004cba0e8d1d383def76f795b1e63ba0aaa89a.tar.gz liblog-ed004cba0e8d1d383def76f795b1e63ba0aaa89a.tar.bz2 liblog-ed004cba0e8d1d383def76f795b1e63ba0aaa89a.tar.xz | |
First commit (everything was written 2024)
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'liblog_use_output.c')
| -rw-r--r-- | liblog_use_output.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/liblog_use_output.c b/liblog_use_output.c new file mode 100644 index 0000000..3471722 --- /dev/null +++ b/liblog_use_output.c @@ -0,0 +1,54 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + +struct liblog_output * +liblog_use_output(struct liblog_context *ctx, const struct liblog_output *output) +{ + void *new; + + if (!ctx || !output) + goto einval; + + if (output->lowest_verbosity_unlimited && output->highest_verbosity_unlimited) + if (output->lowest_verbosity > output->highest_verbosity) + goto einval; + + if (output->sink_type == LIBLOG_STREAM) { + if (!output->sink.stream.stream) + goto einval; + } else if (output->sink_type != LIBLOG_SYSLOG && output->sink_type != LIBLOG_FILE) { + /* + * We do not want to validate syslog level, + * nor do we want to validate file descriptor, + * indeed the user may want to output to a negative + * file descriptor so that it only visible during + * system call tracing + */ + einval: + errno = EINVAL; + return NULL; + } + + if (ctx->noutputs > SIZE_MAX / sizeof(*ctx->outputs) - 1) + goto enomem; + new = realloc(ctx->outputs, (ctx->noutputs + 1) * sizeof(*ctx->outputs)); + if (!new) { + enomem: + errno = ENOMEM; + return NULL; + } + + memcpy(&ctx->outputs[ctx->noutputs], output, sizeof(*output)); + + if (!ctx->outputs[ctx->noutputs].prefixfmt) + ctx->outputs[ctx->noutputs].prefixfmt = DEFAULT_PREFIXFMT; + + return &ctx->outputs[ctx->noutputs++]; +} + +#else + +int main(void) {return 0;} /* TODO test */ + +#endif |
