/* This file is part of limb https://lila.oss/limb
* Copyright (C) 2023 Olivier Brunel jjk@jjacky.com */
/* SPDX-License-Identifier: GPL-2.0-only */
#include <errno.h>
#include <limb/buffer.h>
#include <limb/obuffer.h>
#include "autoopt.h"
static char buf[BUFFER_OUTSIZE];
buffer buffer_log_ = BUFFER_INIT(&fd_writev, -1, buf, sizeof(buf));
obuffer obuffer_log1_ = OBUFFER_INIT(&buffer_log_, OLVL_NORMAL);
obuffer obuffer_log2_ = OBUFFER_INIT(&buffer_log_, OLVL_NORMAL);
int
autoopt_log(const struct option *option, const char *arg)
{
if (buffer_log_.fd >= 0)
return (errno = EADDRINUSE, 0);
u8 lvl = OLVL_NORMAL;
int fd = autoopt_parse_buffer_dest(option, arg, &lvl);
if (fd < 0) return 0;
buffer_log_.fd = fd;
obuffer_setlevel(&obuffer_log1_, lvl);
obuffer_attach(&obuffer_log1_, obuffer_1);
obuffer_setlevel(&obuffer_log2_, lvl);
obuffer_attach(&obuffer_log2_, obuffer_2);
return 1;
}