#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#include <zzip/__string.h>
#include <zzip/__debug.h>
#include "unzzipcat-zip.h"
{
char* p = strrchr(name, '/');
if (p) {
- char* dir_name = strndup(name, p-name);
+ char* dir_name = _zzip_strndup(name, p-name);
makedirs(dir_name);
free (dir_name);
} else {
{
char* p = strrchr(name, '/');
if (p) {
- char* dir_name = strndup(name, p-name);
+ char* dir_name = _zzip_strndup(name, p-name);
makedirs(dir_name);
free (dir_name);
}
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#include <zzip/__string.h>
#include "unzzipcat-zip.h"
#ifdef ZZIP_HAVE_UNISTD_H
{
char* p = strrchr(name, '/');
if (p) {
- char* dir_name = strndup(name, p-name);
+ char* dir_name = _zzip_strndup(name, p-name);
makedirs(dir_name);
free (dir_name);
} else {
{
char* p = strrchr(name, '/');
if (p) {
- char* dir_name = strndup(name, p-name);
+ char* dir_name = _zzip_strndup(name, p-name);
makedirs(dir_name);
free (dir_name);
}
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#include <zzip/__string.h>
#include "unzzipcat-zip.h"
#ifdef ZZIP_HAVE_UNISTD_H
{
char* p = strrchr(name, '/');
if (p) {
- char* dir_name = strndup(name, p-name);
+ char* dir_name = _zzip_strndup(name, p-name);
makedirs(dir_name);
free (dir_name);
} else {
{
char* p = strrchr(name, '/');
if (p) {
- char* dir_name = strndup(name, p-name);
+ char* dir_name = _zzip_strndup(name, p-name);
makedirs(dir_name);
free (dir_name);
}
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#include <zzip/__string.h>
#include "unzzipcat-zip.h"
#ifdef ZZIP_HAVE_UNISTD_H
{
char* p = strrchr(name, '/');
if (p) {
- char* dir_name = strndup(name, p-name);
+ char* dir_name = _zzip_strndup(name, p-name);
makedirs(dir_name);
free (dir_name);
} else {
{
char* p = strrchr(name, '/');
if (p) {
- char* dir_name = strndup(name, p-name);
+ char* dir_name = _zzip_strndup(name, p-name);
makedirs(dir_name);
free (dir_name);
}
zzip_HEADERS = $(libzzip_la_headers) \
$(libzzipmmapped_la_headers) \
$(libzzipfseeko_la_headers)
-noinst_HEADERS = __debug.h __hints.h __mmap.h __dirent.h __fnmatch.h
+noinst_HEADERS = __debug.h __hints.h __mmap.h __dirent.h __fnmatch.h __string.h
#
VERSION_INFO=@VERSION_INFO@
RELEASE_INFO=@RELEASE_INFO@
$(libzzipmmapped_la_headers) \
$(libzzipfseeko_la_headers)
-noinst_HEADERS = __debug.h __hints.h __mmap.h __dirent.h __fnmatch.h
+noinst_HEADERS = __debug.h __hints.h __mmap.h __dirent.h __fnmatch.h __string.h
#
libzzip_la_SOURCES = \
zip.c \
--- /dev/null
+#ifndef __ZZIP_INTERNAL_STRING_H
+#define __ZZIP_INTERNAL_STRING_H
+
+#ifdef __linux__
+#define _GNU_SOURCE _glibc_developers_are_idiots_to_call_strndup_gnu_specific_
+#endif
+
+#include <zzip/conf.h>
+
+#if defined ZZIP_HAVE_STRING_H
+#include <string.h>
+#elif defined ZZIP_HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
+
+#if defined ZZIP_HAVE_STRNDUP || defined strndup
+#define _zzip_strndup strndup
+#else
+
+/* if your system does not have strndup: */
+zzip__new__ static char *
+_zzip_strndup(char const *p, size_t maxlen)
+{
+ if (p == NULL)
+ {
+ return p;
+ } else
+ {
+ size_t len = strnlen(p, maxlen);
+ char* r = malloc(len + 1);
+ if (r == NULL)
+ return NULL; /* errno = ENOMEM */
+ r[len] = '\0';
+ return memcpy(r, p, len);
+ }
+}
+#endif
+
+#if defined ZZIP_HAVE_STRCASECMP || defined strcasecmp
+#define _zzip_strcasecmp strcasecmp
+#else
+
+/* if your system does not have strcasecmp: */
+static int
+_zzip_strcasecmp(char *__zzip_restrict a, char *_zzip_restrict b)
+{
+ if (! a)
+ return (b) ? 1 : 0;
+ if (! b)
+ return -1;
+ while (1)
+ {
+ int v = tolower(*a) - tolower(*b);
+ if (v)
+ return v;
+ if (! *a)
+ return 1;
+ if (! *b)
+ return -1;
+ a++;
+ b++;
+ }
+}
+#endif
+
+#endif
#include <zzip/__debug.h>
#include <zzip/__mmap.h>
#include <zzip/__fnmatch.h>
+#include <zzip/__string.h>
#include <stdlib.h>
#include <sys/stat.h>
}
/* ====================================================================== */
-
/* helper functions */
-#ifdef ZZIP_HAVE_STRNDUP
-#define _zzip_strndup strndup
-#else
-
-/* if your system does not have strndup: */
-zzip__new__ static char *
-_zzip_strndup(char *p, size_t maxlen)
-{
- if (! p)
- return 0;
- ___ zzip_byte_t *r = malloc(maxlen + 1);
- if (! r)
- return r;
- strncpy(r, p, maxlen);
- r[maxlen] = '\0';
- return r;
- ____;
-}
-#endif
-
-#if defined ZZIP_HAVE_STRCASECMP || defined strcasecmp
-#define _zzip_strcasecmp strcasecmp
-#else
-
-/* if your system does not have strcasecmp: */
-static int
-_zzip_strcasecmp(char *__zzip_restrict a, char *_zzip_restrict b)
-{
- if (! a)
- return (b) ? 1 : 0;
- if (! b)
- return -1;
- while (1)
- {
- int v = tolower(*a) - tolower(*b);
- if (v)
- return v;
- if (! *a)
- return 1;
- if (! *b)
- return -1;
- a++;
- b++;
- }
-}
-#endif
/** helper functions for (mmapped) zip access api
*