1 #ifndef XMLRPC_C_STRING_INT_H_INCLUDED
2 #define XMLRPC_C_STRING_INT_H_INCLUDED
3
4
5 #include <stdarg.h>
6 #include <string.h>
7
8 #include "xmlrpc_config.h"
9 #include "xmlrpc-c/c_util.h"
10 #include "bool.h"
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 /*
17 XMLRPC_UTIL_EXPORTED marks a symbol in this file that is exported from
18 libxmlrpc_util.
19
20 XMLRPC_BUILDING_UTIL says this compilation is part of libxmlrpc_util, as
21 opposed to something that _uses_ libxmlrpc_util.
22 */
23 #ifdef XMLRPC_BUILDING_UTIL
24 #define XMLRPC_UTIL_EXPORTED XMLRPC_DLLEXPORT
25 #else
26 #define XMLRPC_UTIL_EXPORTED
27 #endif
28
29 XMLRPC_UTIL_EXPORTED
30 bool
31 xmlrpc_strnomem(const char * const string);
32
33 XMLRPC_UTIL_EXPORTED
34 const char *
35 xmlrpc_strnomemval(void);
36
37 XMLRPC_UTIL_EXPORTED
38 void
39 xmlrpc_vasprintf(const char ** const retvalP,
40 const char * const fmt,
41 va_list varargs);
42
43 XMLRPC_UTIL_EXPORTED
44 void XMLRPC_PRINTF_ATTR(2,3)
45 xmlrpc_asprintf(const char ** const retvalP, const char * const fmt, ...);
46
47 XMLRPC_UTIL_EXPORTED
48 const char *
49 xmlrpc_strdupsol(const char * const string);
50
51 XMLRPC_UTIL_EXPORTED
52 void
53 xmlrpc_strfree(const char * const string);
54
55 XMLRPC_UTIL_EXPORTED
56 const char *
57 xmlrpc_strdupnull(const char * const string);
58
59 XMLRPC_UTIL_EXPORTED
60 void
61 xmlrpc_strfreenull(const char * const string);
62
63 static __inline__ bool
xmlrpc_streq(const char * const a,const char * const b)64 xmlrpc_streq(const char * const a,
65 const char * const b) {
66 return (strcmp(a, b) == 0);
67 }
68
69 static __inline__ bool
xmlrpc_memeq(const void * const a,const void * const b,size_t const size)70 xmlrpc_memeq(const void * const a,
71 const void * const b,
72 size_t const size) {
73
74 return (memcmp(a, b, size) == 0);
75 }
76
77 /* strcasecmp doesn't exist on some systems without _BSD_SOURCE, so
78 xmlrpc_strcaseeq() can't either.
79 */
80 #ifdef _BSD_SOURCE
81
82 static __inline__ bool
xmlrpc_strcaseeq(const char * const a,const char * const b)83 xmlrpc_strcaseeq(const char * const a,
84 const char * const b) {
85 #if HAVE_STRCASECMP
86 return (strcasecmp(a, b) == 0);
87 #elif HAVE__STRICMP
88 return (_stricmp(a, b) == 0);
89 #elif HAVE_STRICMP
90 return (stricmp(a, b) == 0);
91 #else
92 #error "This platform has no known case-independent string compare fn"
93 #endif
94 }
95 #endif
96
97 static __inline__ bool
xmlrpc_strneq(const char * const a,const char * const b,size_t const len)98 xmlrpc_strneq(const char * const a,
99 const char * const b,
100 size_t const len) {
101 return (strncmp(a, b, len) == 0);
102 }
103
104 XMLRPC_UTIL_EXPORTED
105 const char *
106 xmlrpc_makePrintable(const char * const input);
107
108 XMLRPC_UTIL_EXPORTED
109 const char *
110 xmlrpc_makePrintable_lp(const char * const input,
111 size_t const inputLength);
112
113 XMLRPC_UTIL_EXPORTED
114 const char *
115 xmlrpc_makePrintableChar(char const input);
116
117 /*----------------------------------------------------------------*/
118 /* Standard string functions with destination array size checking */
119 /*----------------------------------------------------------------*/
120 #define STRSCPY(A,B) \
121 (strncpy((A), (B), sizeof(A)), *((A)+sizeof(A)-1) = '\0')
122 #define STRSCMP(A,B) \
123 (strncmp((A), (B), sizeof(A)))
124 #define STRSCAT(A,B) \
125 (strncat((A), (B), sizeof(A)-strlen(A)-1))
126
127 #define MEMSSET(a,b) (memset(a, b, sizeof(*a)))
128
129 #define MEMSCPY(a,b) (memcpy(a, b, sizeof(*a)))
130
131 #define MEMSZERO(a) (MEMSSET(a, 0))
132
133 /* We could do this, but it works only in GNU C
134 #define SSPRINTF(TARGET, REST...) \
135 (snprintf(TARGET, sizeof(TARGET) , ## REST))
136
137 Or this, but it works only in C99 compilers, which leaves out MSVC
138 before 2005 and can't handle the zero variable argument case except
139 by an MSVC extension:
140
141 #define SSPRINTF(TARGET, ...) \
142 (snprintf(TARGET, sizeof(TARGET) , __VA_ARGS__))
143
144 */
145 #ifdef __cplusplus
146 }
147 #endif
148
149 #endif
150