blob: 90f9aae9929e1272108dda9e9a168c6a0b7890a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
/* ISC license. */
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <skalibs/stralloc.h>
#include <skalibs/djbunix.h>
int sagetcwd (stralloc *sa)
{
size_t n = 128 ;
int wasnull = !sa->s ;
for (;;)
{
if (!stralloc_readyplus(sa, n)) goto err ;
if (getcwd(sa->s + sa->len, n)) break ;
if (errno != ERANGE) goto err ;
n += 128 ;
}
sa->len += strlen(sa->s + sa->len) ;
return 0 ;
err:
if (wasnull) stralloc_free(sa) ;
return -1 ;
}
|