From 830407e88f9d40d954356c3754f2647f91d5c06a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 17:26:00 +0200 Subject: Adding upstream version 5.6.0. Signed-off-by: Daniel Baumann --- contrib/cleanup.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 contrib/cleanup.h (limited to 'contrib/cleanup.h') diff --git a/contrib/cleanup.h b/contrib/cleanup.h new file mode 100644 index 0000000..c9d170a --- /dev/null +++ b/contrib/cleanup.h @@ -0,0 +1,25 @@ +/* Copyright (C) CZ.NIC, z.s.p.o. + * SPDX-License-Identifier: GPL-3.0-or-later +*/ +/** + * Cleanup attributes. + * @cond internal + */ +#pragma once +#include +#include +#include + +#define auto_free __attribute__((cleanup(_cleanup_free))) +static inline void _cleanup_free(const void *p) { + free(*(char **)p); +} +#define auto_close __attribute__((cleanup(_cleanup_close))) +static inline void _cleanup_close(int *p) { + if (*p != -1) close(*p); +} +#define auto_fclose __attribute__((cleanup(_cleanup_fclose))) +static inline void _cleanup_fclose(FILE **p) { + if (*p) fclose(*p); +} +/* @endcond */ -- cgit v1.2.3