1*1bb92983SJerome Forissier /* SPDX-License-Identifier: BSD-2-Clause */ 2b0104773SPascal Brand /* 3b0104773SPascal Brand * Copyright (c) 2014, STMicroelectronics International N.V. 4b0104773SPascal Brand * All rights reserved. 5b0104773SPascal Brand * 6b0104773SPascal Brand * Redistribution and use in source and binary forms, with or without 7b0104773SPascal Brand * modification, are permitted provided that the following conditions are met: 8b0104773SPascal Brand * 9b0104773SPascal Brand * 1. Redistributions of source code must retain the above copyright notice, 10b0104773SPascal Brand * this list of conditions and the following disclaimer. 11b0104773SPascal Brand * 12b0104773SPascal Brand * 2. Redistributions in binary form must reproduce the above copyright notice, 13b0104773SPascal Brand * this list of conditions and the following disclaimer in the documentation 14b0104773SPascal Brand * and/or other materials provided with the distribution. 15b0104773SPascal Brand * 16b0104773SPascal Brand * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17b0104773SPascal Brand * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18b0104773SPascal Brand * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19b0104773SPascal Brand * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20b0104773SPascal Brand * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21b0104773SPascal Brand * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22b0104773SPascal Brand * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23b0104773SPascal Brand * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24b0104773SPascal Brand * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25b0104773SPascal Brand * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26b0104773SPascal Brand * POSSIBILITY OF SUCH DAMAGE. 27b0104773SPascal Brand */ 28b0104773SPascal Brand 29b0104773SPascal Brand /* 30b0104773SPascal Brand * This file provides extensions for functions not defined in <string.h> 31b0104773SPascal Brand */ 32b0104773SPascal Brand 33b0104773SPascal Brand #ifndef STRING_EXT_H 34b0104773SPascal Brand #define STRING_EXT_H 35b0104773SPascal Brand 36b0104773SPascal Brand #include <stddef.h> 37b0104773SPascal Brand #include <sys/cdefs.h> 38b0104773SPascal Brand 39b0104773SPascal Brand /* 40b0104773SPascal Brand * Copy src to string dst of siz size. At most siz-1 characters 41b0104773SPascal Brand * will be copied. Always NUL terminates (unless siz == 0). 42b0104773SPascal Brand * Returns strlen(src); if retval >= siz, truncation occurred. 43b0104773SPascal Brand */ 44b0104773SPascal Brand size_t strlcpy(char *dst, const char *src, size_t size); 45b0104773SPascal Brand size_t strlcat(char *dst, const char *src, size_t size); 46b0104773SPascal Brand 471665420cSJoakim Bech /* 481665420cSJoakim Bech * This memory compare function will compare two buffers in a constant time. 491665420cSJoakim Bech * 501665420cSJoakim Bech * Note that this function will not have same kind of return values as the 511665420cSJoakim Bech * traditional libc memcmp which return either less than or greater than zero 521665420cSJoakim Bech * depending on which string that is lexically greater. This function will 531665420cSJoakim Bech * return 0 if it is a match, otherwise it will return a non-zero value. 541665420cSJoakim Bech */ 551665420cSJoakim Bech int buf_compare_ct(const void *s1, const void *s2, size_t n); 561665420cSJoakim Bech 57b0104773SPascal Brand #endif /* STRING_EXT_H */ 58