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