From a2745278eb03d63f4df8da4367f27ec8cab7deb9 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 30 Sep 2023 00:15:26 +0200 Subject: Add `strlen` --- include/string.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'include/string.h') diff --git a/include/string.h b/include/string.h index e681181..ab7ac43 100644 --- a/include/string.h +++ b/include/string.h @@ -35,6 +35,7 @@ extern "C" { #undef memset #undef strcat #undef strcpy +#undef strlen #undef strncat #undef strncpy @@ -237,6 +238,22 @@ _FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s) #endif } +__access (read_only, 1) +#if __has_builtin(__builtin_strlen) +__diagnose_as_builtin(__builtin_strlen, 1) +#endif +_FORTIFY_FN(strlen) size_t strlen(const char * _FORTIFY_POS0 __s) +{ +#if __has_builtin(__builtin___strlen_chk) && USE_NATIVE_CHK + return __builtin___strlen_chk(__s, __bos(__s, 0)); +#else + size_t ret = __orig_strlen(__s); + if (ret > __bos(__s, 0) - 1) + __builtin_trap(); + return ret; +#endif +} + __access (read_write, 1) __access (read_only, 2, 3) #if __has_builtin(__builtin_strncat) -- cgit v1.3