Backed out 2 changesets (bug 903746) for causing non-unified build bustages on nsIPri...
[gecko.git] / third_party / sipcc / cpr_string.h
blobde6b1cc8a0ec87dc0546926e4583ea9b3f533fab
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/. */
5 #ifndef _CPR_STRING_H_
6 #define _CPR_STRING_H_
8 #include <stdarg.h>
10 #include "cpr_types.h"
11 #include "cpr_strings.h"
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
17 /**
18 * sstrncpy
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.
36 unsigned long
37 sstrncpy(char *dst, const char *src, unsigned long max);
40 /**
41 * sstrncat
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.
58 char *
59 sstrncat(char *s1, const char *s2, unsigned long max);
63 * flex_string
65 #define FLEX_STRING_CHUNK_SIZE 256
67 typedef struct {
68 char *buffer;
69 size_t buffer_length;
70 size_t string_length;
71 } flex_string;
74 * flex_string_init
76 * Not thread-safe
78 void flex_string_init(flex_string *fs);
81 * flex_string_free
83 * Not thread-safe
85 void flex_string_free(flex_string *fs);
88 * flex_string_check_alloc
90 * Allocate enough chunks to hold the new minimum size.
92 * Not thread-safe
94 void flex_string_check_alloc(flex_string *fs, size_t new_min_length);
97 * flex_string_append
99 * Not thread-safe
101 void flex_string_append(flex_string *fs, const char *more);
104 * flex_string_sprintf
106 * Not thread-safe
108 void flex_string_vsprintf(flex_string *fs, const char *format, va_list original_ap);
111 * flex_string_sprintf
113 * Not thread-safe
115 void flex_string_sprintf(flex_string *fs, const char *format, ...);
118 /* From cpr_linux_string.h */
119 /* cpr_strdup
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
132 char *
133 cpr_strdup(const char *str);
135 #ifdef __cplusplus
137 #endif
139 #endif