line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/* |
2
|
|
|
|
|
|
|
* fptools.c, some helper functions for getcgi.c and uu(en|de)view |
3
|
|
|
|
|
|
|
* |
4
|
|
|
|
|
|
|
* Distributed under the terms of the GNU General Public License. |
5
|
|
|
|
|
|
|
* Use and be happy. |
6
|
|
|
|
|
|
|
*/ |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
/* |
9
|
|
|
|
|
|
|
* Some handy, nonstandard functions. Note that the original may |
10
|
|
|
|
|
|
|
* be both faster and better. ``better'', if your compiler allows |
11
|
|
|
|
|
|
|
* cleaner use of such functions by proper use of ``const''. |
12
|
|
|
|
|
|
|
* |
13
|
|
|
|
|
|
|
* $Id$ |
14
|
|
|
|
|
|
|
*/ |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#ifndef FPTOOLS_H__ |
17
|
|
|
|
|
|
|
#define FPTOOLS_H__ |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#include |
20
|
|
|
|
|
|
|
#include |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
typedef signed char schar; |
23
|
|
|
|
|
|
|
typedef unsigned char uchar; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#include "ecb.h" |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#ifndef TOOLEXPORT |
28
|
|
|
|
|
|
|
#define TOOLEXPORT |
29
|
|
|
|
|
|
|
#endif |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#ifdef __cplusplus |
32
|
|
|
|
|
|
|
extern "C" { |
33
|
|
|
|
|
|
|
#endif |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#if HAVE_GETC_UNLOCKED |
36
|
|
|
|
|
|
|
# define FP_getc(s) getc_unlocked (s) |
37
|
|
|
|
|
|
|
#else |
38
|
|
|
|
|
|
|
# define FP_getc(s) getc (s) |
39
|
|
|
|
|
|
|
#endif |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
#if HAVE_FEOF_UNLOCKED |
42
|
|
|
|
|
|
|
# define FP_feof(s) feof_unlocked (s) |
43
|
|
|
|
|
|
|
#else |
44
|
|
|
|
|
|
|
# define FP_feof(s) feof (s) |
45
|
|
|
|
|
|
|
#endif |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
#if HAVE_FERROR_UNLOCKED |
48
|
|
|
|
|
|
|
# define FP_ferror(s) ferror_unlocked (s) |
49
|
|
|
|
|
|
|
#else |
50
|
|
|
|
|
|
|
# define FP_ferror(s) ferror (s) |
51
|
|
|
|
|
|
|
#endif |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#if HAVE_FLOCKFILE |
54
|
|
|
|
|
|
|
# define FP_flockfile(s) flockfile (s) |
55
|
|
|
|
|
|
|
#else |
56
|
|
|
|
|
|
|
# define FP_flockfile(s) ((void *)0) |
57
|
|
|
|
|
|
|
#endif |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#define FP_strstr(a,b) strstr (a, b) |
60
|
|
|
|
|
|
|
#define FP_strerror(a) strerror (a) |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
void TOOLEXPORT FP_free (void *); |
63
|
|
|
|
|
|
|
char * TOOLEXPORT FP_strdup (char *); |
64
|
|
|
|
|
|
|
char * TOOLEXPORT FP_strncpy (char *, char *, int); |
65
|
|
|
|
|
|
|
void * TOOLEXPORT FP_memdup (const void *, int); |
66
|
|
|
|
|
|
|
int TOOLEXPORT FP_stricmp (const char *, const char *); |
67
|
|
|
|
|
|
|
int TOOLEXPORT FP_strnicmp (const char *, const char *, int); |
68
|
|
|
|
|
|
|
char * TOOLEXPORT FP_strrstr (const char *, const char *); |
69
|
|
|
|
|
|
|
char * TOOLEXPORT FP_stoupper (char *); |
70
|
|
|
|
|
|
|
char * TOOLEXPORT FP_stolower (char *); |
71
|
|
|
|
|
|
|
int TOOLEXPORT FP_strmatch (char *, char *); |
72
|
|
|
|
|
|
|
char * TOOLEXPORT FP_stristr (char *, char *); |
73
|
|
|
|
|
|
|
char * TOOLEXPORT FP_strirstr (char *, char *); |
74
|
|
|
|
|
|
|
char * TOOLEXPORT FP_strrchr (const char *, int); |
75
|
|
|
|
|
|
|
char * TOOLEXPORT FP_fgets (char *, int, FILE *); |
76
|
|
|
|
|
|
|
char * TOOLEXPORT FP_strpbrk (char *, char *); |
77
|
|
|
|
|
|
|
char * TOOLEXPORT FP_strtok (char *, char *); |
78
|
|
|
|
|
|
|
char * TOOLEXPORT FP_cutdir (char *); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
/* like stgricmp, but only works when one of the strings is printable ascii */ |
81
|
|
|
|
|
|
|
/* not containing any of these characters: @`[\]^:_{|}~ */ |
82
|
|
|
|
|
|
|
int TOOLEXPORT FP_strnicmp_fast (const char *, const char *, int); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
#if 0 /* API differs too much between systems to make those replacements */ |
85
|
|
|
|
|
|
|
#if HAVE_STRCASECMP |
86
|
|
|
|
|
|
|
# define FP_stricmp(a,b) strcasecmp (a, b) |
87
|
|
|
|
|
|
|
#endif |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
#if HAVE_STRNCASECMP |
90
|
|
|
|
|
|
|
# define FP_strnicmp(a,b,l) strncasecmp (a, b, l) |
91
|
|
|
|
|
|
|
#endif |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#if HAVE_STRCASESTR |
94
|
|
|
|
|
|
|
# define FP_stristr(a,b) strcasestr (a, b) |
95
|
|
|
|
|
|
|
#endif |
96
|
|
|
|
|
|
|
#endif |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
/* this hashes in the final 0 octet to avoid a branch - might or might not be worth it */ |
99
|
|
|
|
|
|
|
/* this also means that this function distinguishes between NULL and "" */ |
100
|
|
|
|
|
|
|
static uint32_t |
101
|
0
|
|
|
|
|
|
fnv1a (const char *str) |
102
|
|
|
|
|
|
|
{ |
103
|
0
|
|
|
|
|
|
uint32_t hash = 0x811C9DC5, c; |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
if (str) |
106
|
|
|
|
|
|
|
for (;;) |
107
|
|
|
|
|
|
|
{ |
108
|
0
|
|
|
|
|
|
c = *str++; |
109
|
0
|
|
|
|
|
|
hash = (hash ^ c) * 16777619; |
110
|
0
|
0
|
|
|
|
|
if (!c) |
111
|
0
|
|
|
|
|
|
break; |
112
|
0
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
return hash; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
#ifdef __cplusplus |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
#endif |
120
|
|
|
|
|
|
|
#endif |
121
|
|
|
|
|
|
|
|