Welcome to little lamb

Code » limb » master » tree

[master] / src / liblimb / direntry.h / opendirat.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/direntry.h>

DIR *
opendirat(int bfd, const char *name)
{
    int fd = open2_at(bfd, name, O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NONBLOCK);
    if (fd < 0)
        return NULL;

    DIR *dir = fdopendir(fd);
    if (!dir)
        fd_close(fd);

    return dir;
}