2023-02-27 13:40:20 +01:00
|
|
|
/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC)
|
2022-09-19 12:39:02 +02:00
|
|
|
* SPDX-License-Identifier: MIT */
|
|
|
|
|
2021-11-18 11:55:28 +01:00
|
|
|
#ifndef COMMON_H
|
|
|
|
#define COMMON_H
|
|
|
|
|
2022-08-22 16:02:07 +02:00
|
|
|
#include <stdio.h>
|
2023-10-17 15:44:07 +02:00
|
|
|
#include <sys/types.h>
|
2022-08-22 16:02:07 +02:00
|
|
|
|
2023-03-08 16:14:34 +01:00
|
|
|
extern int is_debug_enabled;
|
|
|
|
|
2023-10-17 15:44:07 +02:00
|
|
|
/* Path and file utilities */
|
|
|
|
|
|
|
|
int mkpath(const char *path, mode_t mode, int is_dir);
|
|
|
|
|
2021-11-18 11:55:28 +01:00
|
|
|
/* Debug macros */
|
|
|
|
|
2023-01-25 12:01:01 +01:00
|
|
|
void progname_set(char *name);
|
2023-10-17 18:20:06 +02:00
|
|
|
const char *progname_get(void);
|
2023-03-08 16:14:34 +01:00
|
|
|
void enable_debug(void);
|
2023-03-23 17:38:08 +01:00
|
|
|
void verr(const char *prefix, const char *func, const char *errstr, ...);
|
|
|
|
void vdie(const char *prefix, const char *func, const char *errstr, ...);
|
2023-01-25 12:01:01 +01:00
|
|
|
|
2022-09-29 15:05:09 +02:00
|
|
|
/* clang-format off */
|
|
|
|
|
2023-02-16 15:49:21 +01:00
|
|
|
#define rerr(...) fprintf(stderr, __VA_ARGS__)
|
2023-03-23 17:38:08 +01:00
|
|
|
#define err(...) verr("ERROR", __func__, __VA_ARGS__)
|
|
|
|
#define die(...) vdie("FATAL", __func__, __VA_ARGS__)
|
|
|
|
#define info(...) verr("INFO", NULL, __VA_ARGS__)
|
|
|
|
#define warn(...) verr("WARN", NULL, __VA_ARGS__)
|
2023-01-27 18:51:18 +01:00
|
|
|
|
2023-03-08 16:14:34 +01:00
|
|
|
#define dbg(...) do { \
|
|
|
|
if (unlikely(is_debug_enabled)) verr("DEBUG", __func__, __VA_ARGS__); \
|
|
|
|
} while (0);
|
2021-11-18 11:55:28 +01:00
|
|
|
|
|
|
|
#define likely(x) __builtin_expect(!!(x), 1)
|
|
|
|
#define unlikely(x) __builtin_expect(!!(x), 0)
|
|
|
|
#define UNUSED(x) (void)(x)
|
|
|
|
|
2021-12-09 16:56:24 +01:00
|
|
|
/* Poison assert */
|
|
|
|
#pragma GCC poison assert
|
|
|
|
|
2023-01-16 15:21:56 +01:00
|
|
|
#define USE_RET __attribute__((warn_unused_result))
|
|
|
|
|
2023-01-17 19:25:21 +01:00
|
|
|
#define ARRAYLEN(x) (sizeof(x)/sizeof((x)[0]))
|
|
|
|
|
2022-09-29 15:05:09 +02:00
|
|
|
/* clang-format on */
|
|
|
|
|
2023-01-25 12:01:01 +01:00
|
|
|
|
|
|
|
|
2021-11-18 11:55:28 +01:00
|
|
|
#endif /* COMMON_H */
|