diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/sipcc/cpr_string.h | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/sipcc/cpr_string.h')
-rw-r--r-- | third_party/sipcc/cpr_string.h | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/third_party/sipcc/cpr_string.h b/third_party/sipcc/cpr_string.h new file mode 100644 index 0000000000..de6b1cc8a0 --- /dev/null +++ b/third_party/sipcc/cpr_string.h @@ -0,0 +1,139 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef _CPR_STRING_H_ +#define _CPR_STRING_H_ + +#include <stdarg.h> + +#include "cpr_types.h" +#include "cpr_strings.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * sstrncpy + * + * @brief The CPR wrapper for strncpy + * + * This is Cisco's *safe* version of strncpy. The string will always + * be NUL terminated (which is not ANSI compliant). + * + * @param[in] dst - The destination string + * @param[in] src - The source + * @param[in] max - maximum length in octets to concatenate + * + * @return Pointer to the @b end of the string + * + * @note Modified to be explicitly safe for all inputs. + * Also return the number of characters copied excluding the + * NUL terminator vs. the original string s1. This simplifies + * code where sstrncat functions follow. + */ +unsigned long +sstrncpy(char *dst, const char *src, unsigned long max); + + +/** + * sstrncat + * + * @brief The CPR wrapper for strncat + * + * This is Cisco's *safe* version of strncat. The string will always + * be NUL terminated (which is not ANSI compliant). + * + * @param[in] s1 - first string + * @param[in] s2 - second string + * @param[in] max - maximum length in octets to concatenate + * + * @return Pointer to the @b end of the string + * + * @note Modified to be explicitly safe for all inputs. + * Also return the end vs. the beginning of the string s1 + * which is useful for multiple sstrncat calls. + */ +char * +sstrncat(char *s1, const char *s2, unsigned long max); + + +/* + * flex_string + */ +#define FLEX_STRING_CHUNK_SIZE 256 + +typedef struct { + char *buffer; + size_t buffer_length; + size_t string_length; +} flex_string; + +/* + * flex_string_init + * + * Not thread-safe + */ +void flex_string_init(flex_string *fs); + +/* + * flex_string_free + * + * Not thread-safe + */ +void flex_string_free(flex_string *fs); + +/* + * flex_string_check_alloc + * + * Allocate enough chunks to hold the new minimum size. + * + * Not thread-safe + */ +void flex_string_check_alloc(flex_string *fs, size_t new_min_length); + +/* + * flex_string_append + * + * Not thread-safe + */ +void flex_string_append(flex_string *fs, const char *more); + +/* + * flex_string_sprintf + * + * Not thread-safe + */ +void flex_string_vsprintf(flex_string *fs, const char *format, va_list original_ap); + +/* + * flex_string_sprintf + * + * Not thread-safe + */ +void flex_string_sprintf(flex_string *fs, const char *format, ...); + + +/* From cpr_linux_string.h */ +/* cpr_strdup + * + * @brief The CPR wrapper for strdup + + * The cpr_strdup shall return a pointer to a new string, which is a duplicate + * of the string pointed to by "str" argument. A null pointer is returned if the + * new string cannot be created. + * + * @param[in] str - The string that needs to be duplicated + * + * @return The duplicated string or NULL in case of no memory + * + */ +char * +cpr_strdup(const char *str); + +#ifdef __cplusplus +} +#endif + +#endif |