mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-13 02:15:37 +00:00
15b61b5c4f
Ensures the type is always correct.
68 lines
1.5 KiB
C
68 lines
1.5 KiB
C
// Copyright 2019, Collabora, Ltd.
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
/*!
|
|
* @file
|
|
* @brief Very small misc utils.
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
|
* @ingroup aux_util
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h> // for memset
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
|
|
/*!
|
|
* Allocate and zero the give size and casts the memory into a pointer of the
|
|
* given type.
|
|
*
|
|
* @ingroup aux_util
|
|
*/
|
|
#define U_CALLOC_WITH_CAST(TYPE, SIZE) ((TYPE *)calloc(1, SIZE))
|
|
|
|
/*!
|
|
* Allocate and zero the space required for some type, and cast the return type
|
|
* appropriately.
|
|
*
|
|
* @ingroup aux_util
|
|
*/
|
|
#define U_TYPED_CALLOC(TYPE) ((TYPE *)calloc(1, sizeof(TYPE)))
|
|
|
|
/*!
|
|
* Allocate and zero the space required for some type, and cast the return type
|
|
* appropriately.
|
|
*
|
|
* @ingroup aux_util
|
|
*/
|
|
#define U_TYPED_ARRAY_CALLOC(TYPE, COUNT) \
|
|
((TYPE *)calloc((COUNT), sizeof(TYPE)))
|
|
|
|
/*!
|
|
* Zeroes the correct amount of memory based on the type pointed-to by the
|
|
* argument.
|
|
*
|
|
* Use instead of memset(..., 0, ...) on a structure or pointer to structure.
|
|
*
|
|
* @ingroup aux_util
|
|
*/
|
|
#define U_ZERO(PTR) memset((PTR), 0, sizeof(*(PTR)))
|
|
|
|
/*!
|
|
* Zeroes the correct amount of memory based on the type and size of the static
|
|
* array named in the argument.
|
|
*
|
|
* Use instead of memset(..., 0, ...) on an array.
|
|
*
|
|
* @ingroup aux_util
|
|
*/
|
|
#define U_ZERO_ARRAY(ARRAY) memset((ARRAY), 0, sizeof(ARRAY))
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|