logo

utils-std

Collection of commonly available Unix tools
commit: cd9123c51ba5e7092229c9c44d16577dae0ef775
parent 5656589f5a4538a8acc84fa225020d74bb84dd8e
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 19 Sep 2023 13:19:57 +0200

lib/bitmasks.h: Create macros for bitmasks manipulation

Diffstat:

Alib/bitmasks.h9+++++++++
1 file changed, 9 insertions(+), 0 deletions(-)

diff --git a/lib/bitmasks.h b/lib/bitmasks.h @@ -0,0 +1,9 @@ +// SPDX-FileCopyrightText: 2023 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +// SPDX-License-Identifier: CC0-1.0 + +// C had one job: Portable bitfields. +#define FIELD_SET(field, val) field |= (val) +#define FIELD_CLR(field, val) field &= ~(val) +#define FIELD_TGL(field, val) field ^= (val) + +#define FIELD_GET(field, val) (field & (val))