1 |
root |
1.1 |
/* |
2 |
|
|
* fptools.c, some helper functions for getcgi.c and uu(en|de)view |
3 |
|
|
* |
4 |
root |
1.2 |
* Distributed under the terms of the GNU General Public License. |
5 |
|
|
* Use and be happy. |
6 |
root |
1.1 |
*/ |
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 |
root |
1.7 |
* $Id$ |
14 |
root |
1.1 |
*/ |
15 |
|
|
|
16 |
|
|
#ifndef FPTOOLS_H__ |
17 |
|
|
#define FPTOOLS_H__ |
18 |
|
|
|
19 |
root |
1.7 |
#include <string.h> |
20 |
root |
1.16 |
#include <stdint.h> |
21 |
root |
1.7 |
|
22 |
root |
1.1 |
typedef signed char schar; |
23 |
|
|
typedef unsigned char uchar; |
24 |
|
|
|
25 |
root |
1.11 |
#include "ecb.h" |
26 |
|
|
|
27 |
root |
1.1 |
#ifndef TOOLEXPORT |
28 |
|
|
#define TOOLEXPORT |
29 |
|
|
#endif |
30 |
|
|
|
31 |
|
|
#ifdef __cplusplus |
32 |
|
|
extern "C" { |
33 |
|
|
#endif |
34 |
root |
1.4 |
|
35 |
root |
1.12 |
#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 |
root |
1.7 |
|
47 |
root |
1.12 |
#if HAVE_FERROR_UNLOCKED |
48 |
|
|
# define FP_ferror(s) ferror_unlocked (s) |
49 |
root |
1.7 |
#else |
50 |
root |
1.12 |
# define FP_ferror(s) ferror (s) |
51 |
root |
1.7 |
#endif |
52 |
|
|
|
53 |
root |
1.15 |
#if HAVE_FLOCKFILE |
54 |
|
|
# define FP_flockfile(s) flockfile (s) |
55 |
|
|
#else |
56 |
|
|
# define FP_flockfile(s) ((void *)0) |
57 |
|
|
#endif |
58 |
|
|
|
59 |
root |
1.7 |
#define FP_strstr(a,b) strstr (a, b) |
60 |
root |
1.15 |
#define FP_strerror(a) strerror (a) |
61 |
root |
1.5 |
|
62 |
root |
1.12 |
void TOOLEXPORT FP_free (void *); |
63 |
|
|
char * TOOLEXPORT FP_strdup (char *); |
64 |
|
|
char * TOOLEXPORT FP_strncpy (char *, char *, int); |
65 |
root |
1.13 |
void * TOOLEXPORT FP_memdup (const void *, int); |
66 |
root |
1.12 |
int TOOLEXPORT FP_stricmp (const char *, const char *); |
67 |
|
|
int TOOLEXPORT FP_strnicmp (const char *, const char *, int); |
68 |
root |
1.14 |
char * TOOLEXPORT FP_strrstr (const char *, const char *); |
69 |
root |
1.12 |
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 |
root |
1.13 |
char * TOOLEXPORT FP_strrchr (const char *, int); |
75 |
root |
1.12 |
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 |
root |
1.1 |
|
80 |
root |
1.13 |
/* 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 |
root |
1.8 |
#if 0 /* API differs too much between systems to make those replacements */ |
85 |
root |
1.7 |
#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 |
root |
1.8 |
#endif |
97 |
root |
1.7 |
|
98 |
root |
1.16 |
/* 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 |
|
|
fnv1a (const char *str) |
102 |
|
|
{ |
103 |
|
|
uint32_t hash = 0x811C9DC5, c; |
104 |
|
|
|
105 |
|
|
if (str) |
106 |
|
|
for (;;) |
107 |
|
|
{ |
108 |
|
|
c = *str++; |
109 |
|
|
hash = (hash ^ c) * 16777619; |
110 |
|
|
if (!c) |
111 |
|
|
break; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
return hash; |
115 |
|
|
} |
116 |
|
|
|
117 |
root |
1.1 |
#ifdef __cplusplus |
118 |
|
|
} |
119 |
|
|
#endif |
120 |
|
|
#endif |
121 |
root |
1.5 |
|