1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
8 * String-related functions as replacement for libc equivalents
11 #ifndef _RTE_STRING_FNS_H_
12 #define _RTE_STRING_FNS_H_
22 * Takes string "string" parameter and splits it at character "delim"
23 * up to maxtokens-1 times - to give "maxtokens" resulting tokens. Like
24 * strtok or strsep functions, this modifies its input string, by replacing
25 * instances of "delim" with '\\0'. All resultant tokens are returned in the
26 * "tokens" array which must have enough entries to hold "maxtokens".
29 * The input string to be split into tokens
32 * The max length of the input buffer
35 * The array to hold the pointers to the tokens in the string
38 * The number of elements in the tokens array. At most, maxtokens-1 splits
39 * of the string will be done.
42 * The character on which the split of the data will be done
45 * The number of tokens in the tokens array.
48 rte_strsplit(char *string, int stringlen,
49 char **tokens, int maxtokens, char delim);
53 * DPDK-specific version of strlcpy for systems without
54 * libc or libbsd copies of the function
57 rte_strlcpy(char *dst, const char *src, size_t size)
59 return (size_t)snprintf(dst, size, "%s", src);
62 /* pull in a strlcpy function */
63 #ifdef RTE_EXEC_ENV_BSDAPP
64 #ifndef __BSD_VISIBLE /* non-standard functions are hidden */
65 #define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
68 #else /* non-BSD platforms */
70 #include <bsd/string.h>
72 #else /* no BSD header files, create own */
73 #define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
75 #endif /* RTE_USE_LIBBSD */
79 * Copy string src to buffer dst of size dsize.
80 * At most dsize-1 chars will be copied.
81 * Always NUL-terminates, unless (dsize == 0).
82 * Returns number of bytes copied (terminating NUL-byte excluded) on success ;
83 * negative errno on error.
86 * The destination string.
89 * The input string to be copied.
92 * Length in bytes of the destination buffer.
95 * The number of bytes copied on success
96 * -E2BIG if the destination buffer is too small.
99 rte_strscpy(char *dst, const char *src, size_t dsize);
105 #endif /* RTE_STRING_FNS_H */