diff options
author | Matias Elo <matias.elo@nokia.com> | 2024-06-05 13:51:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-05 13:51:39 +0300 |
commit | 616034b9c9c789923f7ebe7f1c6d014c4ce8a5d2 (patch) | |
tree | dd1b579c93404d2d98b78944bbdf8313ec499bee /platform/linux-generic/odp_string.c | |
parent | 8063101c4fac56e16c5a2bb9843f2fd9c5acbfd7 (diff) | |
parent | 87913e636da621d47a8d3bc91fbe131abc09c294 (diff) |
Merge ODP v1.45.0.0HEADv1.45.0.0_DPDK_22.11master
Merge ODP linux-generic v1.45.0.0 into linux-dpdk.
Diffstat (limited to 'platform/linux-generic/odp_string.c')
-rw-r--r-- | platform/linux-generic/odp_string.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/platform/linux-generic/odp_string.c b/platform/linux-generic/odp_string.c new file mode 100644 index 000000000..9ba56dee8 --- /dev/null +++ b/platform/linux-generic/odp_string.c @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 Nokia + */ + +#include <odp/api/hints.h> +#include <odp_string_internal.h> +#include <stdarg.h> +#include <stdio.h> +#include <string.h> + +ODP_PRINTF_FORMAT(3, 4) +int _odp_snprint(char *str, size_t size, const char *format, ...) +{ + va_list args; + int len; + + /* No space to print new characters */ + if (size < 1) + return 0; + + if (size < 2) { + str[0] = 0; + return 0; + } + + va_start(args, format); + len = vsnprintf(str, size, format, args); + va_end(args); + + /* Error. Ensure that string has the end mark */ + if (len < 0) { + str[0] = 0; + return 0; + } + + /* Print would have been longer. Return the number of characters printed. */ + if (len >= (int)size) + return (int)size - 1; + + return len; +} + +char *_odp_strcpy(char *restrict dst, const char *restrict src, size_t sz) +{ + if (!sz) + return dst; + + strncpy(dst, src, sz - 1); + dst[sz - 1] = 0; + return dst; +} |