1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 #include "cpr_types.h"
11 #include "cpr_strings.h"
20 * @brief The CPR wrapper for strncpy
22 * This is Cisco's *safe* version of strncpy. The string will always
23 * be NUL terminated (which is not ANSI compliant).
25 * @param[in] dst - The destination string
26 * @param[in] src - The source
27 * @param[in] max - maximum length in octets to concatenate
29 * @return Pointer to the @b end of the string
31 * @note Modified to be explicitly safe for all inputs.
32 * Also return the number of characters copied excluding the
33 * NUL terminator vs. the original string s1. This simplifies
34 * code where sstrncat functions follow.
37 sstrncpy(char *dst
, const char *src
, unsigned long max
);
43 * @brief The CPR wrapper for strncat
45 * This is Cisco's *safe* version of strncat. The string will always
46 * be NUL terminated (which is not ANSI compliant).
48 * @param[in] s1 - first string
49 * @param[in] s2 - second string
50 * @param[in] max - maximum length in octets to concatenate
52 * @return Pointer to the @b end of the string
54 * @note Modified to be explicitly safe for all inputs.
55 * Also return the end vs. the beginning of the string s1
56 * which is useful for multiple sstrncat calls.
59 sstrncat(char *s1
, const char *s2
, unsigned long max
);
65 #define FLEX_STRING_CHUNK_SIZE 256
78 void flex_string_init(flex_string
*fs
);
85 void flex_string_free(flex_string
*fs
);
88 * flex_string_check_alloc
90 * Allocate enough chunks to hold the new minimum size.
94 void flex_string_check_alloc(flex_string
*fs
, size_t new_min_length
);
101 void flex_string_append(flex_string
*fs
, const char *more
);
104 * flex_string_sprintf
108 void flex_string_vsprintf(flex_string
*fs
, const char *format
, va_list original_ap
);
111 * flex_string_sprintf
115 void flex_string_sprintf(flex_string
*fs
, const char *format
, ...);
118 /* From cpr_linux_string.h */
121 * @brief The CPR wrapper for strdup
123 * The cpr_strdup shall return a pointer to a new string, which is a duplicate
124 * of the string pointed to by "str" argument. A null pointer is returned if the
125 * new string cannot be created.
127 * @param[in] str - The string that needs to be duplicated
129 * @return The duplicated string or NULL in case of no memory
133 cpr_strdup(const char *str
);