]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
utils: auto_fclose cleanup
authorMarek Vavruša <marek.vavrusa@nic.cz>
Wed, 4 Mar 2015 18:29:57 +0000 (19:29 +0100)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Wed, 4 Mar 2015 18:29:57 +0000 (19:29 +0100)
lib/utils.c
lib/utils.h

index 2d0390e710c0a8e9bd86e89e60d6dda5b1c224c9..5f3c6035537dd4404ec347f466f48f33145fb6f6 100644 (file)
@@ -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 */
index 3d6a57cc51cd4a011a3edcb9fbd677aea42fe215..1feaa1dc3267509f2cba9867b8f1c88a0b8f2d25 100644 (file)
@@ -16,6 +16,8 @@
 
 #pragma once
 
+#include <stdio.h>
+
 /*
  * 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.