DPDK  18.11.11
rte_string_fns.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 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 <stdio.h>
19 #include <string.h>
20 
47 int
48 rte_strsplit(char *string, int stringlen,
49  char **tokens, int maxtokens, char delim);
50 
56 static inline size_t
57 rte_strlcpy(char *dst, const char *src, size_t size)
58 {
59  return (size_t)snprintf(dst, size, "%s", src);
60 }
61 
67 static inline size_t
68 rte_strlcat(char *dst, const char *src, size_t size)
69 {
70  size_t l = strnlen(dst, size);
71  if (l < size)
72  return l + rte_strlcpy(&dst[l], src, size - l);
73  return l + strlen(src);
74 }
75 
76 /* pull in a strlcpy function */
77 #ifdef RTE_EXEC_ENV_BSDAPP
78 #ifndef __BSD_VISIBLE /* non-standard functions are hidden */
79 #define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
80 #define strlcat(dst, src, size) rte_strlcat(dst, src, size)
81 #endif
82 
83 #else /* non-BSD platforms */
84 #ifdef RTE_USE_LIBBSD
85 #include <bsd/string.h>
86 
87 #else /* no BSD header files, create own */
88 #define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
89 #define strlcat(dst, src, size) rte_strlcat(dst, src, size)
90 
91 #endif /* RTE_USE_LIBBSD */
92 #endif /* BSDAPP */
93 
114 ssize_t
115 rte_strscpy(char *dst, const char *src, size_t dsize);
116 
117 #ifdef __cplusplus
118 }
119 #endif
120 
121 #endif /* RTE_STRING_FNS_H */
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)