Welcome to little lamb

Code » limb » master » tree

[master] / src / liblimb / djbunix.h / sa_lsat.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 <errno.h>
#include <limb/direntry.h>
#include <limb/djbunix.h>
#include <limb/gccattributes.h>

static ssize_t
sa_scandir_name(stralloc *sa, direntry *de, int bfd gccattr_unused, void *mlen_)
{
    size_t *mlen = mlen_;
    size_t len = strlen(de->d_name);
    if (!stralloc_catb(sa, de->d_name, len + 1))
        return -1;
    if (mlen && len > *mlen)
        *mlen = len;
    return len;
}

int
sa_lsat(stralloc *sa, int fd, const char *name, size_t *mlen)
{
    if (mlen) *mlen = 0;
    return sa_scandirat(sa, fd, name, sa_scandir_name, mlen);
}