diff options
author | Guy Harris <gharris@sonic.net> | 2021-06-16 02:01:23 -0700 |
---|---|---|
committer | Guy Harris <gharris@sonic.net> | 2021-06-16 02:01:23 -0700 |
commit | 25a254823f21dee60f621b445e6689b2bbf9d9c4 (patch) | |
tree | 38f5033c9ea6dde5bdfbb9b4399d86be0de7579b /wsutil/ws_roundup.h | |
parent | f541e5e769321df0b4968164f583ecd684152d0e (diff) |
wsutil: add a header that defines some "round to power of 2" macros.
Add macros to round to multiples of 2, 4, 8, 16, and 32.
Use them instead of independently defined macros.
(We don't define a general "round to a power of 2" macro to avoid the
risk of somebody passing something other than a power of 2 to it.)
Diffstat (limited to 'wsutil/ws_roundup.h')
-rw-r--r-- | wsutil/ws_roundup.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/wsutil/ws_roundup.h b/wsutil/ws_roundup.h new file mode 100644 index 0000000000..62b21628c6 --- /dev/null +++ b/wsutil/ws_roundup.h @@ -0,0 +1,22 @@ +/* ws_roundup.h + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef __WS_ROUNDUP_H__ +#define __WS_ROUNDUP_H__ + +/* + * Round up to various powers of 2. + */ +#define WS_ROUNDUP_2(n) (((n) + ((guint)(2U-1U))) & (~((guint)(2U-1U)))) +#define WS_ROUNDUP_4(n) (((n) + ((guint)(4U-1U))) & (~((guint)(4U-1U)))) +#define WS_ROUNDUP_8(n) (((n) + ((guint)(8U-1U))) & (~((guint)(8U-1U)))) +#define WS_ROUNDUP_16(n) (((n) + ((guint)(16U-1U))) & (~((guint)(16U-1U)))) +#define WS_ROUNDUP_32(n) (((n) + ((guint)(32U-1U))) & (~((guint)(32U-1U)))) + +#endif /* __WS_ROUNDUP_H__ */ |