xref: /optee_os/lib/libutils/ext/include/string_ext.h (revision 1131d3c544b82fb869c78fb5e6d7b7b246cece19)
11bb92983SJerome Forissier /* SPDX-License-Identifier: BSD-2-Clause */
2b0104773SPascal Brand /*
3b0104773SPascal Brand  * Copyright (c) 2014, STMicroelectronics International N.V.
4b0104773SPascal Brand  */
5b0104773SPascal Brand 
6b0104773SPascal Brand /*
7b0104773SPascal Brand  * This file provides extensions for functions not defined in <string.h>
8b0104773SPascal Brand  */
9b0104773SPascal Brand 
10b0104773SPascal Brand #ifndef STRING_EXT_H
11b0104773SPascal Brand #define STRING_EXT_H
12b0104773SPascal Brand 
13b0104773SPascal Brand #include <stddef.h>
14b0104773SPascal Brand #include <sys/cdefs.h>
15b0104773SPascal Brand 
16b0104773SPascal Brand /*
17b0104773SPascal Brand  * Copy src to string dst of siz size.  At most siz-1 characters
18b0104773SPascal Brand  * will be copied.  Always NUL terminates (unless siz == 0).
19b0104773SPascal Brand  * Returns strlen(src); if retval >= siz, truncation occurred.
20b0104773SPascal Brand  */
21b0104773SPascal Brand size_t strlcpy(char *dst, const char *src, size_t size);
22b0104773SPascal Brand size_t strlcat(char *dst, const char *src, size_t size);
23b0104773SPascal Brand 
241665420cSJoakim Bech /*
251665420cSJoakim Bech  * This memory compare function will compare two buffers in a constant time.
261665420cSJoakim Bech  *
271665420cSJoakim Bech  * Note that this function will not have same kind of return values as the
281665420cSJoakim Bech  * traditional libc memcmp which return either less than or greater than zero
291665420cSJoakim Bech  * depending on which string that is lexically greater. This function will
301665420cSJoakim Bech  * return 0 if it is a match, otherwise it will return a non-zero value.
311665420cSJoakim Bech  */
321665420cSJoakim Bech int buf_compare_ct(const void *s1, const void *s2, size_t n);
331665420cSJoakim Bech 
34*1131d3c5SVolodymyr Babchuk /* Variant of strdup() that uses nex_malloc() instead of malloc() */
35*1131d3c5SVolodymyr Babchuk char *nex_strdup(const char *s);
36*1131d3c5SVolodymyr Babchuk 
37b0104773SPascal Brand #endif /* STRING_EXT_H */
38