[inc][utils] Add a utils.h for miscellaneous helpers

Add a utils.h file containing miscellaneous convenience helpers.
This commit is contained in:
Aaron Odell
2023-04-04 21:30:57 -07:00
committed by Travis Geiselbrecht
parent 8fc673fe4a
commit 9165714702

21
top/include/lk/utils.h Normal file
View File

@@ -0,0 +1,21 @@
/*
* SPDX-License-Identifier: MIT
*
* Copyright (C) 2020-2023 Google LLC.
*/
#pragma once
#define ARRAY_SIZE(_a) (sizeof(_a) / sizeof(*(_a)))
#define KB (1024UL)
#define MB (1024UL * 1024UL)
#define GB (1024UL * 1024UL * 1024UL)
#define RETURN_IF_ERROR(expr) \
do { \
status_t err_ = (expr); \
if (err_ != NO_ERROR) { \
return err_; \
} \
} while (0)