/* 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 <unistd.h>
#include <limb/djbunix.h>
int
sa_readlinkat(stralloc *sa, int fd, const char * restrict file)
{
size_t len = 256;
ssize_t r;
for (;;) {
if (!stralloc_readyplus(sa, len))
return -1;
r = readlinkat(fd, file, sa->s + sa->len, len);
if (r < 0) return -1;
if ((size_t) r < len)
break;
len += 256;
}
sa->len += r;
return 0;
}