2 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: string.h,v 1.12.18.6 2007/09/13 05:04:01 each Exp $ */
21 #define ISC_STRING_H 1
25 #include <isc/formatcheck.h>
28 #include <isc/platform.h>
29 #include <isc/types.h>
33 #ifdef ISC_PLATFORM_HAVESTRINGSH
37 #define ISC_STRING_MAGIC 0x5e
42 isc_string_touint64(char *source, char **endp, int base);
44 * Convert the string pointed to by 'source' to isc_uint64_t.
46 * On successful conversion 'endp' points to the first character
47 * after conversion is complete.
51 * If base is 0 the base is computed from the string type.
53 * On error 'endp' points to 'source'.
57 isc_string_copy(char *target, size_t size, const char *source);
59 * Copy the string pointed to by 'source' to 'target' which is a
60 * pointer to a string of at least 'size' bytes.
63 * 'target' is a pointer to a char[] of at least 'size' bytes.
64 * 'size' an integer > 0.
65 * 'source' == NULL or points to a NUL terminated string.
68 * If result == ISC_R_SUCCESS
69 * 'target' will be a NUL terminated string of no more
70 * than 'size' bytes (including NUL).
72 * If result == ISC_R_NOSPACE
73 * 'target' is undefined.
76 * ISC_R_SUCCESS -- 'source' was successfully copied to 'target'.
77 * ISC_R_NOSPACE -- 'source' could not be copied since 'target'
82 isc_string_copy_truncate(char *target, size_t size, const char *source);
84 * Copy the string pointed to by 'source' to 'target' which is a
85 * pointer to a string of at least 'size' bytes.
88 * 'target' is a pointer to a char[] of at least 'size' bytes.
89 * 'size' an integer > 0.
90 * 'source' == NULL or points to a NUL terminated string.
93 * 'target' will be a NUL terminated string of no more
94 * than 'size' bytes (including NUL).
98 isc_string_append(char *target, size_t size, const char *source);
100 * Append the string pointed to by 'source' to 'target' which is a
101 * pointer to a NUL terminated string of at least 'size' bytes.
104 * 'target' is a pointer to a NUL terminated char[] of at
105 * least 'size' bytes.
106 * 'size' an integer > 0.
107 * 'source' == NULL or points to a NUL terminated string.
110 * If result == ISC_R_SUCCESS
111 * 'target' will be a NUL terminated string of no more
112 * than 'size' bytes (including NUL).
114 * If result == ISC_R_NOSPACE
115 * 'target' is undefined.
118 * ISC_R_SUCCESS -- 'source' was successfully appended to 'target'.
119 * ISC_R_NOSPACE -- 'source' could not be appended since 'target'
124 isc_string_append_truncate(char *target, size_t size, const char *source);
126 * Append the string pointed to by 'source' to 'target' which is a
127 * pointer to a NUL terminated string of at least 'size' bytes.
130 * 'target' is a pointer to a NUL terminated char[] of at
131 * least 'size' bytes.
132 * 'size' an integer > 0.
133 * 'source' == NULL or points to a NUL terminated string.
136 * 'target' will be a NUL terminated string of no more
137 * than 'size' bytes (including NUL).
141 isc_string_printf(char *target, size_t size, const char *format, ...)
142 ISC_FORMAT_PRINTF(3, 4);
144 * Print 'format' to 'target' which is a pointer to a string of at least
148 * 'target' is a pointer to a char[] of at least 'size' bytes.
149 * 'size' an integer > 0.
150 * 'format' == NULL or points to a NUL terminated string.
153 * If result == ISC_R_SUCCESS
154 * 'target' will be a NUL terminated string of no more
155 * than 'size' bytes (including NUL).
157 * If result == ISC_R_NOSPACE
158 * 'target' is undefined.
161 * ISC_R_SUCCESS -- 'format' was successfully printed to 'target'.
162 * ISC_R_NOSPACE -- 'format' could not be printed to 'target' since it
167 isc_string_printf_truncate(char *target, size_t size, const char *format, ...)
168 ISC_FORMAT_PRINTF(3, 4);
170 * Print 'format' to 'target' which is a pointer to a string of at least
174 * 'target' is a pointer to a char[] of at least 'size' bytes.
175 * 'size' an integer > 0.
176 * 'format' == NULL or points to a NUL terminated string.
179 * 'target' will be a NUL terminated string of no more
180 * than 'size' bytes (including NUL).
185 isc_string_regiondup(isc_mem_t *mctx, const isc_region_t *source);
187 * Copy the region pointed to by r to a NUL terminated string
188 * allocated from the memory context pointed to by mctx.
190 * The result should be deallocated using isc_mem_free()
193 * 'mctx' is a point to a valid memory context.
194 * 'source' is a pointer to a valid region.
197 * a pointer to a NUL terminated string or
198 * NULL if memory for the copy could not be allocated
203 isc_string_separate(char **stringp, const char *delim);
205 #ifdef ISC_PLATFORM_NEEDSTRSEP
206 #define strsep isc_string_separate
209 #ifdef ISC_PLATFORM_NEEDMEMMOVE
210 #define memmove(a,b,c) bcopy(b,a,c)
214 isc_string_strlcpy(char *dst, const char *src, size_t size);
217 #ifdef ISC_PLATFORM_NEEDSTRLCPY
218 #define strlcpy isc_string_strlcpy
223 isc_string_strlcat(char *dst, const char *src, size_t size);
225 #ifdef ISC_PLATFORM_NEEDSTRLCAT
226 #define strlcat isc_string_strlcat
231 #endif /* ISC_STRING_H */