Closed ryandesign closed 6 years ago
So the question is: how should it look like?
Solaris has problems as well:
===>
Dear Guido,
We are reported that in some versions of Solaris, both of strndup and strnlen are not included. Thus we changed __string.h as follows in TeX Live:
--- __string.h.orig Tue Feb 06 05:00:56 2018
+++ __string.h Wed Feb 28 08:54:17 2018
@@ -18,6 +18,18 @@
#define _zzip_strndup strndup
#else
+#if defined(sun) || defined(__sun)
+static size_t my_strnlen(const char* str, size_t maxlen)
+{
+ char *p = memchr(str, 0, maxlen);
+ if (p == NULL)
+ return maxlen;
+ else
+ return (p - str);
+}
+#define strnlen(x,y) my_strnlen((x),(y))
+#endif /* sun || __sun */
+
/* if your system does not have strndup: */
zzip__new__ static char *
_zzip_strndup(char const *p, size_t maxlen)
I would like to suggest using the same strategy as gnuplot does. In configure.ac
they use
AC_CHECK_FUNCS(... strndup strnlen ...)
and then
#ifndef HAVE_STRNDUP
char *strndup __PROTO((const char * str, size_t n));
#endif
#ifndef HAVE_STRNLEN
size_t strnlen __PROTO((const char *str, size_t n));
#endif
and
#ifndef HAVE_STRNLEN
size_t
strnlen(const char *str, size_t n)
{
const char * stop = (char *)memchr(str, '\0', n);
return stop ? stop - str : n;
}
#endif
#ifndef HAVE_STRNDUP
char *
strndup(const char * str, size_t n)
{
char * ret = NULL;
size_t len = strnlen(str, n);
ret = (char *) malloc(len + 1);
if (ret == NULL) return NULL;
ret[len] = '\0';
return (char *)memcpy(ret, str, len);
}
#endif
The patch looks great, I have edited it slightly. Please check.
I now tested on Mac OS X 10.6, Sun OS 5.10 and 11. It seems OK on those. (@kencu: you can try to remove the SL fixes once v0.13.69 gets released.)
Compiling on MSYS2 (mentioned in #2) failed for other reasons (#6). MinGW-packages stayed at version 0.13.62, so I could not check how they might have fixed the problem.
done.
libzzip 0.13.68 fails to build on older systems, such as Mac OS X 10.6 Snow Leopard and earlier, that do not have the
strnlen
function:See #2 for prior discussion of this issue.