DPDK  24.07.0
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
15 extern "C" {
16 #endif
17 
18 #include <ctype.h>
19 #include <stdio.h>
20 #include <string.h>
21 
22 #include <rte_common.h>
23 #include <rte_compat.h>
24 
51 int
52 rte_strsplit(char *string, int stringlen,
53  char **tokens, int maxtokens, char delim);
54 
60 static inline size_t
61 rte_strlcpy(char *dst, const char *src, size_t size)
62 {
63  return (size_t)snprintf(dst, size, "%s", src);
64 }
65 
71 static inline size_t
72 rte_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 /* pull in a strlcpy function */
81 #ifdef RTE_EXEC_ENV_FREEBSD
82 #ifndef __BSD_VISIBLE /* non-standard functions are hidden */
83 #define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
84 #define strlcat(dst, src, size) rte_strlcat(dst, src, size)
85 #endif
86 
87 #else /* non-BSD platforms */
88 #ifdef RTE_USE_LIBBSD
89 #include <bsd/string.h>
90 
91 #else /* no BSD header files, create own */
92 #define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
93 #define strlcat(dst, src, size) rte_strlcat(dst, src, size)
94 
95 #endif /* RTE_USE_LIBBSD */
96 #endif /* FREEBSD */
97 
117 ssize_t
118 rte_strscpy(char *dst, const char *src, size_t dsize);
119 
132 __rte_experimental
133 static inline const char *
135 {
136  const char *p = src;
137 
138  while (isspace(*p))
139  p++;
140 
141  return p;
142 }
143 
144 
145 #ifdef __cplusplus
146 }
147 #endif
148 
149 #endif /* RTE_STRING_FNS_H */
static __rte_experimental const char * rte_str_skip_leading_spaces(const char *src)
int rte_strsplit(char *string, int stringlen, char **tokens, int maxtokens, char delim)
ssize_t rte_strscpy(char *dst, const char *src, size_t dsize)