summaryrefslogtreecommitdiff
path: root/src/libstddjb/sarealpath.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-12-07 15:49:02 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-12-07 15:49:02 +0000
commit933e986a9207d2b61c5119e18603b44b924e7226 (patch)
treec670bc83141d6aebc70e31c11168e005a31e5180 /src/libstddjb/sarealpath.c
parent11f210ecaa0e085612058b459523fa2003578aa5 (diff)
downloadskalibs-933e986a9207d2b61c5119e18603b44b924e7226.tar.xz
Finally implement sarealpath() over realpath(). Prettier atomic_symlink().
Diffstat (limited to 'src/libstddjb/sarealpath.c')
-rw-r--r--src/libstddjb/sarealpath.c26
1 files changed, 26 insertions, 0 deletions
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 <string.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <skalibs/stralloc.h>
+#include <skalibs/djbunix.h>
+
+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 ;
+}