DPDK 22.11.5
rte_string_fns.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2019 Intel Corporation
3 */
4
11#ifndef _RTE_STRING_FNS_H_
12#define _RTE_STRING_FNS_H_
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#include <stdio.h>
19#include <string.h>
20
21#include <rte_common.h>
22
49int
50rte_strsplit(char *string, int stringlen,
51 char **tokens, int maxtokens, char delim);
52
58static inline size_t
59rte_strlcpy(char *dst, const char *src, size_t size)
60{
61 return (size_t)snprintf(dst, size, "%s", src);
62}
63
69static inline size_t
70rte_strlcat(char *dst, const char *src, size_t size)
71{
72 size_t l = strnlen(dst, size);
73 if (l < size)
74 return l + rte_strlcpy(&dst[l], src, size - l);
75 return l + strlen(src);
76}
77
78/* pull in a strlcpy function */
79#ifdef RTE_EXEC_ENV_FREEBSD
80#ifndef __BSD_VISIBLE /* non-standard functions are hidden */
81#define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
82#define strlcat(dst, src, size) rte_strlcat(dst, src, size)
83#endif
84
85#else /* non-BSD platforms */
86#ifdef RTE_USE_LIBBSD
87#include <bsd/string.h>
88
89#else /* no BSD header files, create own */
90#define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
91#define strlcat(dst, src, size) rte_strlcat(dst, src, size)
92
93#endif /* RTE_USE_LIBBSD */
94#endif /* FREEBSD */
95
115ssize_t
116rte_strscpy(char *dst, const char *src, size_t dsize);
117
118#ifdef __cplusplus
119}
120#endif
121
122#endif /* RTE_STRING_FNS_H */
ssize_t rte_strscpy(char *dst, const char *src, size_t dsize)
int rte_strsplit(char *string, int stringlen, char **tokens, int maxtokens, char delim)