From 933e986a9207d2b61c5119e18603b44b924e7226 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 7 Dec 2017 15:49:02 +0000 Subject: Finally implement sarealpath() over realpath(). Prettier atomic_symlink(). --- src/libstddjb/sarealpath.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/libstddjb/sarealpath.c (limited to 'src/libstddjb/sarealpath.c') diff --git a/src/libstddjb/sarealpath.c b/src/libstddjb/sarealpath.c new file mode 100644 index 0000000..0cf1825 --- /dev/null +++ b/src/libstddjb/sarealpath.c @@ -0,0 +1,26 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include + +int sarealpath (stralloc *sa, char const *path) +{ + if (sa->s) + { + if (!stralloc_readyplus(sa, PATH_MAX)) return -1 ; + if (!realpath(path, sa->s + sa->len)) return -1 ; + sa->len += strlen(sa->s + sa->len) ; + } + else + { + char *p = realpath(path, 0) ; + if (!p) return -1 ; + sa->s = p ; + sa->len = strlen(p) ; + sa->a = sa->len + 1 ; + } + return 0 ; +} -- cgit v1.2.3