From b3affb29cff0b16e24a53e0b629daffb597c499c Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Mon, 29 Jan 2024 13:43:07 +0100 Subject: [PATCH] lib/string/strftime.[ch]: STRFTIME(): Add macro This macro makes sure that the first argument is an array, and calculates its size. Reviewed-by: "Serge E. Hallyn" Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 2 ++ lib/string/strftime.c | 7 +++++++ lib/string/strftime.h | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 lib/string/strftime.c create mode 100644 lib/string/strftime.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 58d9c142..0aa9d5ec 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -149,6 +149,8 @@ libshadow_la_SOURCES = \ string/stpecpy.h \ string/stpeprintf.c \ string/stpeprintf.h \ + string/strftime.c \ + string/strftime.h \ string/strncpy.h \ string/strtcpy.c \ string/strtcpy.h \ diff --git a/lib/string/strftime.c b/lib/string/strftime.c new file mode 100644 index 00000000..ea1deb3f --- /dev/null +++ b/lib/string/strftime.c @@ -0,0 +1,7 @@ +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include + +#include "strftime.h" diff --git a/lib/string/strftime.h b/lib/string/strftime.h new file mode 100644 index 00000000..bebb31a4 --- /dev/null +++ b/lib/string/strftime.h @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_STRFTIME_H_ +#define SHADOW_INCLUDE_LIB_STRFTIME_H_ + + +#include + +#include + +#include "sizeof.h" + + +#define STRFTIME(dst, fmt, ...) strftime(dst, NITEMS(dst), fmt, __VA_ARGS__) + + +#endif // include guard