… | |
… | |
8 | /* |
8 | /* |
9 | * Some handy, nonstandard functions. Note that the original may |
9 | * Some handy, nonstandard functions. Note that the original may |
10 | * be both faster and better. ``better'', if your compiler allows |
10 | * be both faster and better. ``better'', if your compiler allows |
11 | * cleaner use of such functions by proper use of ``const''. |
11 | * cleaner use of such functions by proper use of ``const''. |
12 | * |
12 | * |
13 | * $Id: fptools.h,v 1.15 2020/12/12 03:55:00 root Exp $ |
13 | * $Id: fptools.h,v 1.16 2020/12/12 10:48:39 root Exp $ |
14 | */ |
14 | */ |
15 | |
15 | |
16 | #ifndef FPTOOLS_H__ |
16 | #ifndef FPTOOLS_H__ |
17 | #define FPTOOLS_H__ |
17 | #define FPTOOLS_H__ |
18 | |
18 | |
19 | #include <string.h> |
19 | #include <string.h> |
|
|
20 | #include <stdint.h> |
20 | |
21 | |
21 | typedef signed char schar; |
22 | typedef signed char schar; |
22 | typedef unsigned char uchar; |
23 | typedef unsigned char uchar; |
23 | |
24 | |
24 | #include "ecb.h" |
25 | #include "ecb.h" |
… | |
… | |
92 | #if HAVE_STRCASESTR |
93 | #if HAVE_STRCASESTR |
93 | # define FP_stristr(a,b) strcasestr (a, b) |
94 | # define FP_stristr(a,b) strcasestr (a, b) |
94 | #endif |
95 | #endif |
95 | #endif |
96 | #endif |
96 | |
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 | 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 | |
97 | #ifdef __cplusplus |
117 | #ifdef __cplusplus |
98 | } |
118 | } |
99 | #endif |
119 | #endif |
100 | #endif |
120 | #endif |
101 | |
121 | |