blob: 098fded283976c79d44a21159a9c850aaa6fa6e8 [file] [log] [blame]
Antonio Nino Diazcf0f8052018-08-17 10:45:47 +01001/*
2 * Copyright (c) 2012-2017 Roberto E. Vargas Caballero
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
Antonio Nino Diaz6ef16122018-08-15 19:51:09 +01006/*
Boyan Karatotev7ab30812025-03-17 10:31:03 +00007 * Portions copyright (c) 2018-2025, Arm Limited and Contributors.
Jit Loon Lim410c4512023-05-28 16:33:28 +08008 * Portions copyright (c) 2023, Intel Corporation. All rights reserved.
Antonio Nino Diaz6ef16122018-08-15 19:51:09 +01009 * All rights reserved.
10 */
Antonio Nino Diazcf0f8052018-08-17 10:45:47 +010011
Antonio Nino Diaz17605e72018-08-14 13:39:29 +010012#ifndef STRING_H
13#define STRING_H
Antonio Nino Diazcf0f8052018-08-17 10:45:47 +010014
Bence Szépkúti92410c92019-10-25 18:12:41 +020015#include <stddef.h>
Antonio Nino Diazcf0f8052018-08-17 10:45:47 +010016
Boyan Karatotev7ab30812025-03-17 10:31:03 +000017/*
18 * When conditions are right, the compiler may have a baked-in call that can be
19 * inlined and that will be much more optimal than our generic implementation.
20 * When it doesn't, it will emit a call to the original function for which we
21 * provide an implementation.
22 */
23#define memcpy __builtin_memcpy
24#define memset __builtin_memset
25#define memcmp __builtin_memcmp
26#define memchr __builtin_memchr
27#define strcmp __builtin_strcmp
28#define strncmp __builtin_strncmp
29#define strchr __builtin_strchr
30#define strlen __builtin_strlen
31#define strrchr __builtin_strrchr
32
Jit Loon Lim410c4512023-05-28 16:33:28 +080033int memcpy_s(void *dst, size_t dsize, void *src, size_t ssize);
Antonio Nino Diaz17605e72018-08-14 13:39:29 +010034void *memmove(void *dst, const void *src, size_t len);
Ambroise Vincent35248f22019-06-19 17:14:09 +010035void *memrchr(const void *src, int c, size_t len);
Antonio Nino Diaz17605e72018-08-14 13:39:29 +010036size_t strnlen(const char *s, size_t maxlen);
Antonio Nino Diazbbf55f92018-09-27 09:22:19 +010037size_t strlcpy(char * dst, const char * src, size_t dsize);
Madhukar Pappireddyaf0cd5f2020-09-04 14:04:23 -050038size_t strlcat(char * dst, const char * src, size_t dsize);
Madhukar Pappireddyd7e7be32020-09-16 18:58:49 -050039char *strtok_r(char *s, const char *delim, char **last);
Jit Loon Lim012a9d92025-03-17 16:25:53 +080040size_t strnlen_secure(const char *str, size_t maxlen);
41int strcpy_secure(char *restrict dest, size_t dest_size, const char *restrict src);
Antonio Nino Diazcf0f8052018-08-17 10:45:47 +010042
Antonio Nino Diaz17605e72018-08-14 13:39:29 +010043#endif /* STRING_H */