Annotation of embedaddon/dhcp/includes/isc-dhcp/string.h, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
! 3: * Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
! 4: *
! 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.
! 8: *
! 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.
! 16: */
! 17:
! 18: /* $Id: string.h,v 1.2 2007-11-16 11:04:11 shane Exp $ */
! 19:
! 20: #ifndef ISC_STRING_H
! 21: #define ISC_STRING_H 1
! 22:
! 23: /*! \file isc/string.h */
! 24:
! 25: #include <isc-dhcp/formatcheck.h>
! 26: #include <isc-dhcp/int.h>
! 27: #include <isc-dhcp/lang.h>
! 28: /*#include <isc-dhcp/platform.h>*/
! 29: #include <isc-dhcp/types.h>
! 30: #include <isc-dhcp/result.h>
! 31:
! 32: #include <string.h>
! 33:
! 34: #ifdef ISC_PLATFORM_HAVESTRINGSH
! 35: #include <strings.h>
! 36: #endif
! 37:
! 38: #define ISC_STRING_MAGIC 0x5e
! 39:
! 40: ISC_LANG_BEGINDECLS
! 41:
! 42: isc_uint64_t
! 43: isc_string_touint64(char *source, char **endp, int base);
! 44: /*%<
! 45: * Convert the string pointed to by 'source' to isc_uint64_t.
! 46: *
! 47: * On successful conversion 'endp' points to the first character
! 48: * after conversion is complete.
! 49: *
! 50: * 'base': 0 or 2..36
! 51: *
! 52: * If base is 0 the base is computed from the string type.
! 53: *
! 54: * On error 'endp' points to 'source'.
! 55: */
! 56:
! 57: isc_result_t
! 58: isc_string_copy(char *target, size_t size, const char *source);
! 59: /*
! 60: * Copy the string pointed to by 'source' to 'target' which is a
! 61: * pointer to a string of at least 'size' bytes.
! 62: *
! 63: * Requires:
! 64: * 'target' is a pointer to a char[] of at least 'size' bytes.
! 65: * 'size' an integer > 0.
! 66: * 'source' == NULL or points to a NUL terminated string.
! 67: *
! 68: * Ensures:
! 69: * If result == ISC_R_SUCCESS
! 70: * 'target' will be a NUL terminated string of no more
! 71: * than 'size' bytes (including NUL).
! 72: *
! 73: * If result == ISC_R_NOSPACE
! 74: * 'target' is undefined.
! 75: *
! 76: * Returns:
! 77: * ISC_R_SUCCESS -- 'source' was successfully copied to 'target'.
! 78: * ISC_R_NOSPACE -- 'source' could not be copied since 'target'
! 79: * is too small.
! 80: */
! 81:
! 82: void
! 83: isc_string_copy_truncate(char *target, size_t size, const char *source);
! 84: /*
! 85: * Copy the string pointed to by 'source' to 'target' which is a
! 86: * pointer to a string of at least 'size' bytes.
! 87: *
! 88: * Requires:
! 89: * 'target' is a pointer to a char[] of at least 'size' bytes.
! 90: * 'size' an integer > 0.
! 91: * 'source' == NULL or points to a NUL terminated string.
! 92: *
! 93: * Ensures:
! 94: * 'target' will be a NUL terminated string of no more
! 95: * than 'size' bytes (including NUL).
! 96: */
! 97:
! 98: isc_result_t
! 99: isc_string_append(char *target, size_t size, const char *source);
! 100: /*
! 101: * Append the string pointed to by 'source' to 'target' which is a
! 102: * pointer to a NUL terminated string of at least 'size' bytes.
! 103: *
! 104: * Requires:
! 105: * 'target' is a pointer to a NUL terminated char[] of at
! 106: * least 'size' bytes.
! 107: * 'size' an integer > 0.
! 108: * 'source' == NULL or points to a NUL terminated string.
! 109: *
! 110: * Ensures:
! 111: * If result == ISC_R_SUCCESS
! 112: * 'target' will be a NUL terminated string of no more
! 113: * than 'size' bytes (including NUL).
! 114: *
! 115: * If result == ISC_R_NOSPACE
! 116: * 'target' is undefined.
! 117: *
! 118: * Returns:
! 119: * ISC_R_SUCCESS -- 'source' was successfully appended to 'target'.
! 120: * ISC_R_NOSPACE -- 'source' could not be appended since 'target'
! 121: * is too small.
! 122: */
! 123:
! 124: void
! 125: isc_string_append_truncate(char *target, size_t size, const char *source);
! 126: /*
! 127: * Append the string pointed to by 'source' to 'target' which is a
! 128: * pointer to a NUL terminated string of at least 'size' bytes.
! 129: *
! 130: * Requires:
! 131: * 'target' is a pointer to a NUL terminated char[] of at
! 132: * least 'size' bytes.
! 133: * 'size' an integer > 0.
! 134: * 'source' == NULL or points to a NUL terminated string.
! 135: *
! 136: * Ensures:
! 137: * 'target' will be a NUL terminated string of no more
! 138: * than 'size' bytes (including NUL).
! 139: */
! 140:
! 141: isc_result_t
! 142: isc_string_printf(char *target, size_t size, const char *format, ...)
! 143: ISC_FORMAT_PRINTF(3, 4);
! 144: /*
! 145: * Print 'format' to 'target' which is a pointer to a string of at least
! 146: * 'size' bytes.
! 147: *
! 148: * Requires:
! 149: * 'target' is a pointer to a char[] of at least 'size' bytes.
! 150: * 'size' an integer > 0.
! 151: * 'format' == NULL or points to a NUL terminated string.
! 152: *
! 153: * Ensures:
! 154: * If result == ISC_R_SUCCESS
! 155: * 'target' will be a NUL terminated string of no more
! 156: * than 'size' bytes (including NUL).
! 157: *
! 158: * If result == ISC_R_NOSPACE
! 159: * 'target' is undefined.
! 160: *
! 161: * Returns:
! 162: * ISC_R_SUCCESS -- 'format' was successfully printed to 'target'.
! 163: * ISC_R_NOSPACE -- 'format' could not be printed to 'target' since it
! 164: * is too small.
! 165: */
! 166:
! 167: void
! 168: isc_string_printf_truncate(char *target, size_t size, const char *format, ...)
! 169: ISC_FORMAT_PRINTF(3, 4);
! 170: /*
! 171: * Print 'format' to 'target' which is a pointer to a string of at least
! 172: * 'size' bytes.
! 173: *
! 174: * Requires:
! 175: * 'target' is a pointer to a char[] of at least 'size' bytes.
! 176: * 'size' an integer > 0.
! 177: * 'format' == NULL or points to a NUL terminated string.
! 178: *
! 179: * Ensures:
! 180: * 'target' will be a NUL terminated string of no more
! 181: * than 'size' bytes (including NUL).
! 182: */
! 183:
! 184:
! 185: /*
! 186: char *
! 187: isc_string_regiondup(isc_mem_t *mctx, const isc_region_t *source);
! 188: */
! 189: /*
! 190: * Copy the region pointed to by r to a NUL terminated string
! 191: * allocated from the memory context pointed to by mctx.
! 192: *
! 193: * The result should be deallocated using isc_mem_free()
! 194: *
! 195: * Requires:
! 196: * 'mctx' is a point to a valid memory context.
! 197: * 'source' is a pointer to a valid region.
! 198: *
! 199: * Returns:
! 200: * a pointer to a NUL terminated string or
! 201: * NULL if memory for the copy could not be allocated
! 202: *
! 203: */
! 204:
! 205: char *
! 206: isc_string_separate(char **stringp, const char *delim);
! 207:
! 208: #ifdef ISC_PLATFORM_NEEDSTRSEP
! 209: #define strsep isc_string_separate
! 210: #endif
! 211:
! 212: #ifdef ISC_PLATFORM_NEEDMEMMOVE
! 213: #define memmove(a,b,c) bcopy(b,a,c)
! 214: #endif
! 215:
! 216: size_t
! 217: isc_string_strlcpy(char *dst, const char *src, size_t size);
! 218:
! 219:
! 220: #ifdef ISC_PLATFORM_NEEDSTRLCPY
! 221: #define strlcpy isc_string_strlcpy
! 222: #endif
! 223:
! 224:
! 225: size_t
! 226: isc_string_strlcat(char *dst, const char *src, size_t size);
! 227:
! 228: #ifdef ISC_PLATFORM_NEEDSTRLCAT
! 229: #define strlcat isc_string_strlcat
! 230: #endif
! 231:
! 232: ISC_LANG_ENDDECLS
! 233:
! 234: #endif /* ISC_STRING_H */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>