From c1f743ab2e4a7046d5500875a47d1f62c8624603 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 8 Apr 2024 22:37:50 +0200 Subject: Adding upstream version 5.7.1. 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