/* 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/output.h>
#include "autoopt.h"
int
autoopt_parse_buffer_dest(const struct option *option, const char *arg, u8 *lvl)
{
int fd = parse_buffer_dest(lvl, &arg, strlen(arg));
if (fd < 0) {
char buf[2] = { option->shortopt, 0 };
if (*lvl == (u8) -1)
warn("invalid output level via --", option->longopt,
(*buf) ? "/-" : "", buf, ": ", arg);
else if (errno == EINVAL || errno == ERANGE)
warn("invalid file descriptor via --", option->longopt,
(*buf) ? "/-" : "", buf, ": ", arg);
else
warnusys("open ", ESC, arg, ESC, " via --", option->longopt,
(*buf) ? "/-" : "", buf);
return -1;
}
return fd;
}