blob: f5b7cb8703c8b66678775aef7271f4db410acf83 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#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
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))
/* 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
|