commit 56c1fdfaf3d415b920aa98ab9d8f7ba2a5509708
parent e7ea3358ef627675fbd4669516617688a7e3dd94
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date: Sun, 20 Oct 2019 03:04:05 +0000
Real fix for undefined PATH_MAX
Diffstat:
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git 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
{