From 67c42427a0941a4b47c04e8a95322be9d069ff32 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Tue, 15 Oct 2024 13:21:17 +0200 Subject: [PATCH] lib/string/strcmp/: streq(): Add function Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 2 ++ lib/string/strcmp/streq.c | 12 ++++++++++++ lib/string/strcmp/streq.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 lib/string/strcmp/streq.c create mode 100644 lib/string/strcmp/streq.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 4ea5ec4e..96393354 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -190,6 +190,8 @@ libshadow_la_SOURCES = \ string/strchr/strnul.h \ string/strchr/strrspn.c \ string/strchr/strrspn.h \ + string/strcmp/streq.c \ + string/strcmp/streq.h \ string/strcpy/stpecpy.c \ string/strcpy/stpecpy.h \ string/strcpy/strncat.c \ diff --git a/lib/string/strcmp/streq.c b/lib/string/strcmp/streq.c new file mode 100644 index 00000000..52057ed8 --- /dev/null +++ b/lib/string/strcmp/streq.c @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include + +#include + +#include "string/strcmp/streq.h" + + +extern inline bool streq(const char *s1, const char *s2); diff --git a/lib/string/strcmp/streq.h b/lib/string/strcmp/streq.h new file mode 100644 index 00000000..267045c5 --- /dev/null +++ b/lib/string/strcmp/streq.h @@ -0,0 +1,30 @@ +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_STRING_STRCMP_STREQ_H_ +#define SHADOW_INCLUDE_LIB_STRING_STRCMP_STREQ_H_ + + +#include + +#include +#include + +#include "attr.h" + + +ATTR_STRING(1) +ATTR_STRING(2) +inline bool streq(const char *s1, const char *s2); + + +/* Return true if s1 and s2 compare equal. */ +inline bool +streq(const char *s1, const char *s2) +{ + return strcmp(s1, s2) == 0; +} + + +#endif // include guard