/* 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