• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Private string definitions for CUPS.
3  *
4  * Copyright © 2007-2018 by Apple Inc.
5  * Copyright © 1997-2006 by Easy Software Products.
6  *
7  * Licensed under Apache License v2.0.  See the file "LICENSE" for more
8  * information.
9  */
10 
11 #ifndef _CUPS_STRING_PRIVATE_H_
12 #  define _CUPS_STRING_PRIVATE_H_
13 
14 /*
15  * Include necessary headers...
16  */
17 
18 #  include "config.h"
19 #  include <stdio.h>
20 #  include <stdlib.h>
21 #  include <stdarg.h>
22 #  include <ctype.h>
23 #  include <errno.h>
24 #  include <locale.h>
25 #  include <time.h>
26 
27 #  include <cups/versioning.h>
28 
29 #  ifdef HAVE_STRING_H
30 #    include <string.h>
31 #  endif /* HAVE_STRING_H */
32 
33 #  ifdef HAVE_STRINGS_H
34 #    include <strings.h>
35 #  endif /* HAVE_STRINGS_H */
36 
37 #  ifdef HAVE_BSTRING_H
38 #    include <bstring.h>
39 #  endif /* HAVE_BSTRING_H */
40 
41 #  if defined(_WIN32) && !defined(__CUPS_SSIZE_T_DEFINED)
42 #    define __CUPS_SSIZE_T_DEFINED
43 #    include <stddef.h>
44 /* Windows does not support the ssize_t type, so map it to long... */
45 typedef long ssize_t;			/* @private@ */
46 #  endif /* _WIN32 && !__CUPS_SSIZE_T_DEFINED */
47 
48 
49 /*
50  * C++ magic...
51  */
52 
53 #  ifdef __cplusplus
54 extern "C" {
55 #  endif /* __cplusplus */
56 
57 
58 /*
59  * String pool structures...
60  */
61 
62 #  define _CUPS_STR_GUARD	0x12344321
63 
64 typedef struct _cups_sp_item_s		/**** String Pool Item ****/
65 {
66 #  ifdef DEBUG_GUARDS
67   unsigned int	guard;			/* Guard word */
68 #  endif /* DEBUG_GUARDS */
69   unsigned int	ref_count;		/* Reference count */
70   char		str[1];			/* String */
71 } _cups_sp_item_t;
72 
73 
74 /*
75  * Replacements for the ctype macros that are not affected by locale, since we
76  * really only care about testing for ASCII characters when parsing files, etc.
77  *
78  * The _CUPS_INLINE definition controls whether we get an inline function body,
79  * and external function body, or an external definition.
80  */
81 
82 #  if defined(__GNUC__) || __STDC_VERSION__ >= 199901L
83 #    define _CUPS_INLINE static inline
84 #  elif defined(_MSC_VER)
85 #    define _CUPS_INLINE static __inline
86 #  elif defined(_CUPS_STRING_C_)
87 #    define _CUPS_INLINE
88 #  endif /* __GNUC__ || __STDC_VERSION__ */
89 
90 #  ifdef _CUPS_INLINE
91 _CUPS_INLINE int			/* O - 1 on match, 0 otherwise */
_cups_isalnum(int ch)92 _cups_isalnum(int ch)			/* I - Character to test */
93 {
94   return ((ch >= '0' && ch <= '9') ||
95           (ch >= 'A' && ch <= 'Z') ||
96           (ch >= 'a' && ch <= 'z'));
97 }
98 
99 _CUPS_INLINE int			/* O - 1 on match, 0 otherwise */
_cups_isalpha(int ch)100 _cups_isalpha(int ch)			/* I - Character to test */
101 {
102   return ((ch >= 'A' && ch <= 'Z') ||
103           (ch >= 'a' && ch <= 'z'));
104 }
105 
106 _CUPS_INLINE int			/* O - 1 on match, 0 otherwise */
_cups_islower(int ch)107 _cups_islower(int ch)			/* I - Character to test */
108 {
109   return (ch >= 'a' && ch <= 'z');
110 }
111 
112 _CUPS_INLINE int			/* O - 1 on match, 0 otherwise */
_cups_isspace(int ch)113 _cups_isspace(int ch)			/* I - Character to test */
114 {
115   return (ch == ' ' || ch == '\f' || ch == '\n' || ch == '\r' || ch == '\t' ||
116           ch == '\v');
117 }
118 
119 _CUPS_INLINE int			/* O - 1 on match, 0 otherwise */
_cups_isupper(int ch)120 _cups_isupper(int ch)			/* I - Character to test */
121 {
122   return (ch >= 'A' && ch <= 'Z');
123 }
124 
125 _CUPS_INLINE int			/* O - Converted character */
_cups_tolower(int ch)126 _cups_tolower(int ch)			/* I - Character to convert */
127 {
128   return (_cups_isupper(ch) ? ch - 'A' + 'a' : ch);
129 }
130 
131 _CUPS_INLINE int			/* O - Converted character */
_cups_toupper(int ch)132 _cups_toupper(int ch)			/* I - Character to convert */
133 {
134   return (_cups_islower(ch) ? ch - 'a' + 'A' : ch);
135 }
136 #  else
137 extern int _cups_isalnum(int ch);
138 extern int _cups_isalpha(int ch);
139 extern int _cups_islower(int ch);
140 extern int _cups_isspace(int ch);
141 extern int _cups_isupper(int ch);
142 extern int _cups_tolower(int ch);
143 extern int _cups_toupper(int ch);
144 #  endif /* _CUPS_INLINE */
145 
146 
147 /*
148  * Prototypes...
149  */
150 
151 extern ssize_t	_cups_safe_vsnprintf(char *buffer, size_t bufsize, const char *format, va_list args) _CUPS_PRIVATE;
152 extern void	_cups_strcpy(char *dst, const char *src) _CUPS_PRIVATE;
153 
154 #  ifndef HAVE_STRDUP
155 extern char	*_cups_strdup(const char *) _CUPS_PRIVATE;
156 #    define strdup _cups_strdup
157 #  endif /* !HAVE_STRDUP */
158 
159 extern int	_cups_strcasecmp(const char *, const char *) _CUPS_PRIVATE;
160 
161 extern int	_cups_strncasecmp(const char *, const char *, size_t n) _CUPS_PRIVATE;
162 
163 #  ifndef HAVE_STRLCAT
164 extern size_t _cups_strlcat(char *, const char *, size_t) _CUPS_PRIVATE;
165 #    define strlcat _cups_strlcat
166 #  endif /* !HAVE_STRLCAT */
167 
168 #  ifndef HAVE_STRLCPY
169 extern size_t _cups_strlcpy(char *, const char *, size_t) _CUPS_PRIVATE;
170 #    define strlcpy _cups_strlcpy
171 #  endif /* !HAVE_STRLCPY */
172 
173 #  ifndef HAVE_SNPRINTF
174 extern int	_cups_snprintf(char *, size_t, const char *, ...) _CUPS_FORMAT(3, 4) _CUPS_PRIVATE;
175 #    define snprintf _cups_snprintf
176 #  endif /* !HAVE_SNPRINTF */
177 
178 #  ifndef HAVE_VSNPRINTF
179 extern int	_cups_vsnprintf(char *, size_t, const char *, va_list) _CUPS_PRIVATE;
180 #    define vsnprintf _cups_vsnprintf
181 #  endif /* !HAVE_VSNPRINTF */
182 
183 /*
184  * String pool functions...
185  */
186 
187 extern char	*_cupsStrAlloc(const char *s) _CUPS_PRIVATE;
188 extern void	_cupsStrFlush(void) _CUPS_PRIVATE;
189 extern void	_cupsStrFree(const char *s) _CUPS_PRIVATE;
190 extern char	*_cupsStrRetain(const char *s) _CUPS_PRIVATE;
191 extern size_t	_cupsStrStatistics(size_t *alloc_bytes, size_t *total_bytes) _CUPS_PRIVATE;
192 
193 
194 /*
195  * Floating point number functions...
196  */
197 
198 extern char	*_cupsStrFormatd(char *buf, char *bufend, double number,
199 		                 struct lconv *loc) _CUPS_PRIVATE;
200 extern double	_cupsStrScand(const char *buf, char **bufptr,
201 		              struct lconv *loc) _CUPS_PRIVATE;
202 
203 
204 /*
205  * Date function...
206  */
207 
208 extern char	*_cupsStrDate(char *buf, size_t bufsize, time_t timeval) _CUPS_PRIVATE;
209 
210 
211 /*
212  * C++ magic...
213  */
214 
215 #  ifdef __cplusplus
216 }
217 #  endif /* __cplusplus */
218 
219 #endif /* !_CUPS_STRING_H_ */
220