]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/string-private.h
Fix source file header text duplication text duplication.
[thirdparty/cups.git] / cups / string-private.h
CommitLineData
ef416fc2 1/*
554aa7b7 2 * Private string definitions for CUPS.
ef416fc2 3 *
59189c00 4 * Copyright 2007-2015 by Apple Inc.
554aa7b7 5 * Copyright 1997-2006 by Easy Software Products.
ef416fc2 6 *
554aa7b7
MS
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
57b7b66b 11 * missing or damaged, see the license at "http://www.cups.org/".
ef416fc2 12 *
554aa7b7 13 * This file is subject to the Apple OS-Developed Software exception.
ef416fc2 14 */
15
71e16022
MS
16#ifndef _CUPS_STRING_PRIVATE_H_
17# define _CUPS_STRING_PRIVATE_H_
ef416fc2 18
19/*
20 * Include necessary headers...
21 */
22
ef416fc2 23# include <stdio.h>
a74454a7 24# include <stdlib.h>
ef416fc2 25# include <stdarg.h>
26# include <ctype.h>
71e16022 27# include <errno.h>
757d2cad 28# include <locale.h>
554aa7b7 29# include <time.h>
ef416fc2 30
71e16022 31# include "config.h"
a74454a7 32
ef416fc2 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
21aa3f37
MS
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... */
49typedef long ssize_t; /* @private@ */
50# endif /* WIN32 && !__CUPS_SSIZE_T_DEFINED */
51
ef416fc2 52
ef416fc2 53/*
54 * C++ magic...
55 */
56
57# ifdef __cplusplus
58extern "C" {
59# endif /* __cplusplus */
60
61
4400e98d 62/*
63 * String pool structures...
64 */
65
745129be
MS
66# define _CUPS_STR_GUARD 0x12344321
67
4400e98d 68typedef struct _cups_sp_item_s /**** String Pool Item ****/
69{
745129be
MS
70# ifdef DEBUG_GUARDS
71 unsigned int guard; /* Guard word */
72# endif /* DEBUG_GUARDS */
4400e98d 73 unsigned int ref_count; /* Reference count */
426c6a59 74 char str[1]; /* String */
4400e98d 75} _cups_sp_item_t;
76
77
7cf5915e
MS
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.
7cf5915e
MS
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 */
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 */
104_cups_isalpha(int ch) /* I - Character to test */
105{
106 return ((ch >= 'A' && ch <= 'Z') ||
107 (ch >= 'a' && ch <= 'z'));
108}
109
2d0a0f48
MS
110_CUPS_INLINE int /* O - 1 on match, 0 otherwise */
111_cups_islower(int ch) /* I - Character to test */
112{
113 return (ch >= 'a' && ch <= 'z');
114}
115
7cf5915e
MS
116_CUPS_INLINE int /* O - 1 on match, 0 otherwise */
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 */
124_cups_isupper(int ch) /* I - Character to test */
125{
126 return (ch >= 'A' && ch <= 'Z');
127}
88f9aafc
MS
128
129_CUPS_INLINE int /* O - Converted character */
130_cups_tolower(int ch) /* I - Character to convert */
131{
132 return (_cups_isupper(ch) ? ch - 'A' + 'a' : ch);
133}
2d0a0f48
MS
134
135_CUPS_INLINE int /* O - Converted character */
136_cups_toupper(int ch) /* I - Character to convert */
137{
138 return (_cups_islower(ch) ? ch - 'a' + 'A' : ch);
139}
7cf5915e
MS
140# else
141extern int _cups_isalnum(int ch);
142extern int _cups_isalpha(int ch);
2d0a0f48 143extern int _cups_islower(int ch);
7cf5915e
MS
144extern int _cups_isspace(int ch);
145extern int _cups_isupper(int ch);
88f9aafc 146extern int _cups_tolower(int ch);
2d0a0f48 147extern int _cups_toupper(int ch);
7cf5915e
MS
148# endif /* _CUPS_INLINE */
149
150
ef416fc2 151/*
152 * Prototypes...
153 */
154
59189c00 155extern ssize_t _cups_safe_vsnprintf(char *, size_t, const char *, va_list);
ef416fc2 156extern void _cups_strcpy(char *dst, const char *src);
157
158# ifndef HAVE_STRDUP
159extern char *_cups_strdup(const char *);
160# define strdup _cups_strdup
161# endif /* !HAVE_STRDUP */
162
ef416fc2 163extern int _cups_strcasecmp(const char *, const char *);
ef416fc2 164
ef416fc2 165extern int _cups_strncasecmp(const char *, const char *, size_t n);
ef416fc2 166
167# ifndef HAVE_STRLCAT
168extern size_t _cups_strlcat(char *, const char *, size_t);
169# define strlcat _cups_strlcat
170# endif /* !HAVE_STRLCAT */
171
172# ifndef HAVE_STRLCPY
173extern size_t _cups_strlcpy(char *, const char *, size_t);
174# define strlcpy _cups_strlcpy
175# endif /* !HAVE_STRLCPY */
176
177# ifndef HAVE_SNPRINTF
178extern int _cups_snprintf(char *, size_t, const char *, ...)
85dda01c 179 __attribute__ ((__format__ (__printf__, 3, 4)));
ef416fc2 180# define snprintf _cups_snprintf
181# endif /* !HAVE_SNPRINTF */
182
183# ifndef HAVE_VSNPRINTF
184extern int _cups_vsnprintf(char *, size_t, const char *, va_list);
185# define vsnprintf _cups_vsnprintf
186# endif /* !HAVE_VSNPRINTF */
187
4400e98d 188/*
189 * String pool functions...
190 */
191
757d2cad 192extern char *_cupsStrAlloc(const char *s);
d6ae789d 193extern void _cupsStrFlush(void);
757d2cad 194extern void _cupsStrFree(const char *s);
e07d4801 195extern char *_cupsStrRetain(const char *s);
757d2cad 196extern size_t _cupsStrStatistics(size_t *alloc_bytes, size_t *total_bytes);
197
198
199/*
200 * Floating point number functions...
201 */
202
203extern char *_cupsStrFormatd(char *buf, char *bufend, double number,
204 struct lconv *loc);
205extern double _cupsStrScand(const char *buf, char **bufptr,
206 struct lconv *loc);
4400e98d 207
ef416fc2 208
554aa7b7
MS
209/*
210 * Date function...
211 */
212
213extern char *_cupsStrDate(char *buf, size_t bufsize, time_t timeval);
214
215
ef416fc2 216/*
217 * C++ magic...
218 */
219
220# ifdef __cplusplus
221}
222# endif /* __cplusplus */
223
224#endif /* !_CUPS_STRING_H_ */