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 |
|
14 |
#ifndef FPTOOLS_H__ |
15 |
#define FPTOOLS_H__ |
16 |
|
17 |
#include <string.h> |
18 |
#include <stdint.h> |
19 |
|
20 |
typedef signed char schar; |
21 |
typedef unsigned char uchar; |
22 |
|
23 |
#include "ecb.h" |
24 |
|
25 |
#ifndef TOOLEXPORT |
26 |
#define TOOLEXPORT |
27 |
#endif |
28 |
|
29 |
#ifdef __cplusplus |
30 |
extern "C" { |
31 |
#endif |
32 |
|
33 |
#if HAVE_GETC_UNLOCKED |
34 |
# define FP_getc(s) getc_unlocked (s) |
35 |
#else |
36 |
# define FP_getc(s) getc (s) |
37 |
#endif |
38 |
|
39 |
#if HAVE_FEOF_UNLOCKED |
40 |
# define FP_feof(s) feof_unlocked (s) |
41 |
#else |
42 |
# define FP_feof(s) feof (s) |
43 |
#endif |
44 |
|
45 |
#if HAVE_FERROR_UNLOCKED |
46 |
# define FP_ferror(s) ferror_unlocked (s) |
47 |
#else |
48 |
# define FP_ferror(s) ferror (s) |
49 |
#endif |
50 |
|
51 |
#if HAVE_FLOCKFILE |
52 |
# define FP_flockfile(s) flockfile (s) |
53 |
#else |
54 |
# define FP_flockfile(s) ((void *)0) |
55 |
#endif |
56 |
|
57 |
#define FP_strstr(a,b) strstr (a, b) |
58 |
#define FP_strerror(a) strerror (a) |
59 |
|
60 |
void TOOLEXPORT FP_free (void *); |
61 |
char * TOOLEXPORT FP_strdup (char *); |
62 |
char * TOOLEXPORT FP_strncpy (char *, char *, int); |
63 |
void * TOOLEXPORT FP_memdup (const void *, int); |
64 |
int TOOLEXPORT FP_stricmp (const char *, const char *); |
65 |
int TOOLEXPORT FP_strnicmp (const char *, const char *, int); |
66 |
char * TOOLEXPORT FP_strrstr (const char *, const char *); |
67 |
char * TOOLEXPORT FP_stoupper (char *); |
68 |
char * TOOLEXPORT FP_stolower (char *); |
69 |
int TOOLEXPORT FP_strmatch (char *, char *); |
70 |
char * TOOLEXPORT FP_stristr (char *, char *); |
71 |
char * TOOLEXPORT FP_strirstr (char *, char *); |
72 |
char * TOOLEXPORT FP_strrchr (const char *, int); |
73 |
char * TOOLEXPORT FP_fgets (char *, int, FILE *); |
74 |
char * TOOLEXPORT FP_strpbrk (char *, char *); |
75 |
char * TOOLEXPORT FP_strtok (char *, char *); |
76 |
char * TOOLEXPORT FP_cutdir (char *); |
77 |
|
78 |
/* like stgricmp, but only works when one of the strings is printable ascii */ |
79 |
/* not containing any of these characters: @`[\]^:_{|}~ */ |
80 |
int TOOLEXPORT FP_strnicmp_fast (const char *, const char *, int); |
81 |
|
82 |
#if 0 /* API differs too much between systems to make those replacements */ |
83 |
#if HAVE_STRCASECMP |
84 |
# define FP_stricmp(a,b) strcasecmp (a, b) |
85 |
#endif |
86 |
|
87 |
#if HAVE_STRNCASECMP |
88 |
# define FP_strnicmp(a,b,l) strncasecmp (a, b, l) |
89 |
#endif |
90 |
|
91 |
#if HAVE_STRCASESTR |
92 |
# define FP_stristr(a,b) strcasestr (a, b) |
93 |
#endif |
94 |
#endif |
95 |
|
96 |
/* this hashes in the final 0 octet to avoid a branch - might or might not be worth it */ |
97 |
/* this also means that this function distinguishes between NULL and "" */ |
98 |
static uint32_t |
99 |
fnv1a (const char *str) |
100 |
{ |
101 |
uint32_t hash = 0x811C9DC5, c; |
102 |
|
103 |
if (str) |
104 |
for (;;) |
105 |
{ |
106 |
c = *str++; |
107 |
hash = (hash ^ c) * 16777619; |
108 |
if (!c) |
109 |
break; |
110 |
} |
111 |
|
112 |
return hash; |
113 |
} |
114 |
|
115 |
#ifdef __cplusplus |
116 |
} |
117 |
#endif |
118 |
#endif |
119 |
|