From 3534b428629be185e096be99e3bd5fdfe32d5544 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 18 Sep 2014 18:55:44 +0000 Subject: initial commit with rc for skalibs-2.0.0.0 --- src/libstddjb/sagetcwd.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/libstddjb/sagetcwd.c (limited to 'src/libstddjb/sagetcwd.c') diff --git a/src/libstddjb/sagetcwd.c b/src/libstddjb/sagetcwd.c new file mode 100644 index 0000000..d8c5dea --- /dev/null +++ b/src/libstddjb/sagetcwd.c @@ -0,0 +1,27 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include + +int sagetcwd (stralloc *sa) +{ + unsigned int 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 += str_len(sa->s + sa->len) ; + return 0 ; + +err: + if (wasnull) stralloc_free(sa) ; + return -1 ; +} -- cgit 1.4.1