summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libstddjb/sarealpath.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/libstddjb/sarealpath.c b/src/libstddjb/sarealpath.c
index 0e316b2..8c994c4 100644
--- a/src/libstddjb/sarealpath.c
+++ b/src/libstddjb/sarealpath.c
@@ -1,5 +1,6 @@
/* ISC license. */
+#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <skalibs/stralloc.h>
@@ -9,9 +10,20 @@ int sarealpath (stralloc *sa, char const *path)
{
if (sa->s)
{
- if (!stralloc_readyplus(sa, 128)) return -1 ;
+#ifdef PATH_MAX
+ 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 ;
+ if (!stralloc_cats(sa, p) || !stralloc_0(sa))
+ {
+ free(p) ;
+ return -1 ;
+ }
+ free(p) ;
+#endif
}
else
{