summaryrefslogtreecommitdiff
path: root/src/libstddjb/sarealpath.c
diff options
context:
space:
mode:
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 ;
+}