2019-03-18 05:52:32 +00:00
|
|
|
// Copyright 2019, Collabora, Ltd.
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief Very small misc utils.
|
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
2019-04-06 11:28:56 +00:00
|
|
|
* @ingroup aux_util
|
2019-03-18 05:52:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-04-03 16:57:05 +00:00
|
|
|
#include <stdlib.h>
|
2019-06-18 18:51:23 +00:00
|
|
|
#include <string.h> // for memset
|
2019-04-03 16:57:05 +00:00
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2019-04-10 11:33:28 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* 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))
|
|
|
|
|
2019-03-21 20:18:44 +00:00
|
|
|
/*!
|
|
|
|
* Allocate and zero the space required for some type, and cast the return type
|
|
|
|
* appropriately.
|
2019-04-06 11:28:56 +00:00
|
|
|
*
|
|
|
|
* @ingroup aux_util
|
2019-03-21 20:18:44 +00:00
|
|
|
*/
|
|
|
|
#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.
|
2019-04-06 11:28:56 +00:00
|
|
|
*
|
|
|
|
* @ingroup aux_util
|
2019-03-21 20:18:44 +00:00
|
|
|
*/
|
|
|
|
#define U_TYPED_ARRAY_CALLOC(TYPE, COUNT) \
|
|
|
|
((TYPE *)calloc((COUNT), sizeof(TYPE)))
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2019-06-18 18:51:23 +00:00
|
|
|
/*!
|
|
|
|
* 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))
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|