Welcome to little lamb

Code » limb » master » tree

[master] / src / liblimb / djbunix.h / open_parsed_name.c

/* 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 <limb/djbunix.h>
#include <limb/u16.h>

int
open_parsed_name(const char *name, open_fn open)
{
    /* is this a file descriptor via +fd */
    if (*name == '+') {
        ++name;
        /* another '+' would mean file name starts with a '+' */
        if (*name != '+') {
            u16 u;
            if (!u16_scan0(&u, name))
                return -1;
            return u;
        }
    }

    return open(name);
}