… | |
… | |
7 | |
7 | |
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 | * |
|
|
13 | * $Id: fptools.h,v 1.3.2.5 2004/04/18 19:55:46 root Exp $ |
|
|
14 | */ |
12 | */ |
15 | |
13 | |
16 | #ifndef __FPTOOLS_H__ |
14 | #ifndef FPTOOLS_H__ |
17 | #define __FPTOOLS_H__ |
15 | #define FPTOOLS_H__ |
18 | |
16 | |
19 | #ifndef _ANSI_ARGS_ |
17 | #include <string.h> |
20 | #ifdef PROTOTYPES |
18 | #include <stdint.h> |
21 | #define _ANSI_ARGS_(c) c |
19 | |
22 | #else |
20 | typedef signed char schar; |
23 | #define _ANSI_ARGS_(c) () |
21 | typedef unsigned char uchar; |
24 | #endif |
22 | |
25 | #endif |
23 | #include "ecb.h" |
26 | |
24 | |
27 | #ifndef TOOLEXPORT |
25 | #ifndef TOOLEXPORT |
28 | #define TOOLEXPORT |
26 | #define TOOLEXPORT |
29 | #endif |
27 | #endif |
30 | |
28 | |
31 | #ifdef __cplusplus |
29 | #ifdef __cplusplus |
32 | extern "C" { |
30 | extern "C" { |
33 | #endif |
31 | #endif |
34 | |
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 | |
35 | void TOOLEXPORT _FP_free _ANSI_ARGS_((void *)); |
60 | void TOOLEXPORT FP_free (void *); |
36 | char * TOOLEXPORT _FP_strdup _ANSI_ARGS_((char *)); |
61 | char * TOOLEXPORT FP_strdup (char *); |
37 | char * TOOLEXPORT _FP_strncpy _ANSI_ARGS_((char *, char *, int)); |
62 | char * TOOLEXPORT FP_strncpy (char *, char *, int); |
38 | void * TOOLEXPORT _FP_memdup _ANSI_ARGS_((void *, int)); |
63 | void * TOOLEXPORT FP_memdup (const void *, int); |
39 | int TOOLEXPORT _FP_stricmp _ANSI_ARGS_((char *, char *)); |
64 | int TOOLEXPORT FP_stricmp (const char *, const char *); |
40 | int TOOLEXPORT _FP_strnicmp _ANSI_ARGS_((char *, char *, int)); |
65 | int TOOLEXPORT FP_strnicmp (const char *, const char *, int); |
41 | char * TOOLEXPORT _FP_strrstr _ANSI_ARGS_((char *, char *)); |
66 | char * TOOLEXPORT FP_strrstr (const char *, const char *); |
42 | char * TOOLEXPORT _FP_stoupper _ANSI_ARGS_((char *)); |
67 | char * TOOLEXPORT FP_stoupper (char *); |
43 | char * TOOLEXPORT _FP_stolower _ANSI_ARGS_((char *)); |
68 | char * TOOLEXPORT FP_stolower (char *); |
44 | int TOOLEXPORT _FP_strmatch _ANSI_ARGS_((char *, char *)); |
69 | int TOOLEXPORT FP_strmatch (char *, char *); |
45 | char * TOOLEXPORT _FP_strstr _ANSI_ARGS_((char *, char *)); |
|
|
46 | char * TOOLEXPORT _FP_stristr _ANSI_ARGS_((char *, char *)); |
70 | char * TOOLEXPORT FP_stristr (char *, char *); |
47 | char * TOOLEXPORT _FP_strirstr _ANSI_ARGS_((char *, char *)); |
71 | char * TOOLEXPORT FP_strirstr (char *, char *); |
48 | char * TOOLEXPORT _FP_strrchr _ANSI_ARGS_((char *, int)); |
72 | char * TOOLEXPORT FP_strrchr (const char *, int); |
49 | char * TOOLEXPORT _FP_fgets _ANSI_ARGS_((char *, int, FILE *)); |
73 | char * TOOLEXPORT FP_fgets (char *, int, FILE *); |
50 | char * TOOLEXPORT _FP_strpbrk _ANSI_ARGS_((char *, char *)); |
74 | char * TOOLEXPORT FP_strpbrk (char *, char *); |
51 | char * TOOLEXPORT _FP_strtok _ANSI_ARGS_((char *, char *)); |
75 | char * TOOLEXPORT FP_strtok (char *, char *); |
52 | char * TOOLEXPORT _FP_cutdir _ANSI_ARGS_((char *)); |
76 | char * TOOLEXPORT FP_cutdir (char *); |
53 | char * TOOLEXPORT _FP_strerror _ANSI_ARGS_((int)); |
77 | |
54 | char * TOOLEXPORT _FP_tempnam _ANSI_ARGS_((char *, char *)); |
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 | } |
55 | |
114 | |
56 | #ifdef __cplusplus |
115 | #ifdef __cplusplus |
57 | } |
116 | } |
58 | #endif |
117 | #endif |
59 | #endif |
118 | #endif |
|
|
119 | |