diff --git a/lib/Makefile.am b/lib/Makefile.am index 0254977b..b5de79c5 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -37,6 +37,7 @@ libshadow_la_SOURCES = \ basename.c \ bit.c \ bit.h \ + cast.h \ chkname.c \ chkname.h \ chowndir.c \ diff --git a/lib/cast.h b/lib/cast.h new file mode 100644 index 00000000..9229528d --- /dev/null +++ b/lib/cast.h @@ -0,0 +1,21 @@ +// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_CAST_H_ +#define SHADOW_INCLUDE_LIB_CAST_H_ + + +#include + +#include "must_be.h" + + +#define const_cast(T, p) \ +({ \ + static_assert(is_same_type(typeof(&*(p)), const T), ""); \ + (T) (p); \ +}) + + +#endif // include guard