diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2019-10-20 03:04:05 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2019-10-20 03:04:05 +0000 |
commit | 56c1fdfaf3d415b920aa98ab9d8f7ba2a5509708 (patch) | |
tree | fb5f198694530e12841cd6ac5850c9e44dbc545d | |
parent | e7ea3358ef627675fbd4669516617688a7e3dd94 (diff) | |
download | skalibs-56c1fdfaf3d415b920aa98ab9d8f7ba2a5509708.tar.xz |
Real fix for undefined PATH_MAX
-rw-r--r-- | src/libstddjb/sarealpath.c | 14 |
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 { |