From: Marek VavruĊĦa Date: Wed, 4 Mar 2015 18:29:57 +0000 (+0100) Subject: utils: auto_fclose cleanup X-Git-Tag: v1.0.0-beta1~301^2~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=eaaa268385486526b7b590a6cc8dbc00a41222eb;p=thirdparty%2Fknot-resolver.git utils: auto_fclose cleanup --- diff --git a/lib/utils.c b/lib/utils.c index 2d0390e71..5f3c60355 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -23,6 +23,11 @@ void _cleanup_close(int *p) if (*p > 0) close(*p); } +void _cleanup_fclose(FILE **p) +{ + if (*p) fclose(*p); +} + char* kr_strcatdup(unsigned n, ...) { /* Calculate total length */ diff --git a/lib/utils.h b/lib/utils.h index 3d6a57cc5..1feaa1dc3 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -16,6 +16,8 @@ #pragma once +#include + /* * General-purpose attributes. */ @@ -23,6 +25,8 @@ extern void _cleanup_free(char **p); #define auto_close __attribute__((cleanup(_cleanup_close))) extern void _cleanup_close(int *p); +#define auto_fclose __attribute__((cleanup(_cleanup_fclose))) +extern void _cleanup_fclose(FILE **p); /* * Defines.