xref: /optee_os/lib/libutils/ext/include/string_ext.h (revision dc0f4ec2074a459f7bf6279e19dd3a68f86468f1)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2014, STMicroelectronics International N.V.
4  */
5 
6 /*
7  * This file provides extensions for functions not defined in <string.h>
8  */
9 
10 #ifndef STRING_EXT_H
11 #define STRING_EXT_H
12 
13 #include <stddef.h>
14 #include <sys/cdefs.h>
15 
16 /*
17  * Copy src to string dst of siz size.  At most siz-1 characters
18  * will be copied.  Always NUL terminates (unless siz == 0).
19  * Returns strlen(src); if retval >= siz, truncation occurred.
20  */
21 size_t strlcpy(char *dst, const char *src, size_t size);
22 size_t strlcat(char *dst, const char *src, size_t size);
23 
24 /*
25  * This memory compare function will compare two buffers in a constant time.
26  *
27  * Note that this function will not have same kind of return values as the
28  * traditional libc memcmp which return either less than or greater than zero
29  * depending on which string that is lexically greater. This function will
30  * return 0 if it is a match, otherwise it will return a non-zero value.
31  */
32 int buf_compare_ct(const void *s1, const void *s2, size_t n);
33 
34 #endif /* STRING_EXT_H */
35