DPDK 26.11.0-rc1
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#include <ctype.h>
15#include <stdio.h>
16#include <string.h>
17
18#include <rte_common.h>
19#include <rte_compat.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
51int
52rte_strsplit(char *string, int stringlen,
53 char **tokens, int maxtokens, char delim);
54
60static inline size_t
61rte_strlcpy(char *dst, const char *src, size_t size)
62{
63 return (size_t)snprintf(dst, size, "%s", src);
64}
65
71static inline size_t
72rte_strlcat(char *dst, const char *src, size_t size)
73{
74 size_t l = strnlen(dst, size);
75 if (l < size)
76 return l + rte_strlcpy(&dst[l], src, size - l);
77 return l + strlen(src);
78}
79
80#ifdef __cplusplus
81}
82#endif
83
84/* provide strlcpy/strlcat aliases where not natively available */
85#if !defined(RTE_HAS_STRLCPY) || \
86 (defined(RTE_EXEC_ENV_FREEBSD) && !defined(__BSD_VISIBLE)) || \
87 (defined(__GLIBC__) && !defined(__USE_MISC))
88#define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
89#define strlcat(dst, src, size) rte_strlcat(dst, src, size)
90#endif
91
92#ifdef __cplusplus
93extern "C" {
94#endif
95
115ssize_t
116rte_strscpy(char *dst, const char *src, size_t dsize);
117
130__rte_experimental
131static inline const char *
133{
134 const char *p = src;
135
136 while (isspace(*p))
137 p++;
138
139 return p;
140}
141
170__rte_experimental
171size_t
172rte_basename(const char *path, char *buf, size_t buflen);
173
174#ifdef __cplusplus
175}
176#endif
177
178#endif /* RTE_STRING_FNS_H */
__rte_experimental size_t rte_basename(const char *path, char *buf, size_t buflen)
static __rte_experimental const char * rte_str_skip_leading_spaces(const char *src)
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)