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 /* A constant-time version of memcmp() */ 25 int consttime_memcmp(const void *p1, const void *p2, size_t nb); 26 27 /* Deprecated. For backward compatibility. */ 28 static inline int buf_compare_ct(const void *s1, const void *s2, size_t n) 29 { 30 return consttime_memcmp(s1, s2, n); 31 } 32 33 /* Variant of strdup() that uses nex_malloc() instead of malloc() */ 34 char *nex_strdup(const char *s); 35 36 #endif /* STRING_EXT_H */ 37