"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.11.23/lib/isc/include/isc/string.h" (7 Sep 2020, 6077 Bytes) of package /linux/misc/dns/bind9/9.11.23/bind-9.11.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "string.h" see the Fossies "Dox" file reference documentation.

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