ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-UUlib/uulib/fptools.h
Revision: 1.17
Committed: Sat Sep 24 06:25:44 2022 UTC (20 months, 1 week ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.16: +0 -2 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
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    
14     #ifndef FPTOOLS_H__
15     #define FPTOOLS_H__
16    
17 root 1.7 #include <string.h>
18 root 1.16 #include <stdint.h>
19 root 1.7
20 root 1.1 typedef signed char schar;
21     typedef unsigned char uchar;
22    
23 root 1.11 #include "ecb.h"
24    
25 root 1.1 #ifndef TOOLEXPORT
26     #define TOOLEXPORT
27     #endif
28    
29     #ifdef __cplusplus
30     extern "C" {
31     #endif
32 root 1.4
33 root 1.12 #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 root 1.7
45 root 1.12 #if HAVE_FERROR_UNLOCKED
46     # define FP_ferror(s) ferror_unlocked (s)
47 root 1.7 #else
48 root 1.12 # define FP_ferror(s) ferror (s)
49 root 1.7 #endif
50    
51 root 1.15 #if HAVE_FLOCKFILE
52     # define FP_flockfile(s) flockfile (s)
53     #else
54     # define FP_flockfile(s) ((void *)0)
55     #endif
56    
57 root 1.7 #define FP_strstr(a,b) strstr (a, b)
58 root 1.15 #define FP_strerror(a) strerror (a)
59 root 1.5
60 root 1.12 void TOOLEXPORT FP_free (void *);
61     char * TOOLEXPORT FP_strdup (char *);
62     char * TOOLEXPORT FP_strncpy (char *, char *, int);
63 root 1.13 void * TOOLEXPORT FP_memdup (const void *, int);
64 root 1.12 int TOOLEXPORT FP_stricmp (const char *, const char *);
65     int TOOLEXPORT FP_strnicmp (const char *, const char *, int);
66 root 1.14 char * TOOLEXPORT FP_strrstr (const char *, const char *);
67 root 1.12 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 root 1.13 char * TOOLEXPORT FP_strrchr (const char *, int);
73 root 1.12 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 root 1.1
78 root 1.13 /* 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 root 1.8 #if 0 /* API differs too much between systems to make those replacements */
83 root 1.7 #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 root 1.8 #endif
95 root 1.7
96 root 1.16 /* 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 root 1.1 #ifdef __cplusplus
116     }
117     #endif
118     #endif
119 root 1.5