From a200fcc844f1b12ca6dba9a8937a29d3930ce6ed Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Mon, 22 May 2017 19:00:02 -0700 Subject: [PATCH] conmon: Add helper for closing C stdlib FILEs Signed-off-by: Mrunal Patel --- conmon/conmon.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/conmon/conmon.c b/conmon/conmon.c index 56fa274d..9b671fb7 100644 --- a/conmon/conmon.c +++ b/conmon/conmon.c @@ -59,6 +59,12 @@ static inline void closep(int *fd) *fd = -1; } +static inline void fclosep(FILE **fp) { + if (*fp) + fclose(*fp); + *fp = NULL; +} + static inline void gstring_free_cleanup(GString **string) { if (*string) @@ -67,6 +73,7 @@ static inline void gstring_free_cleanup(GString **string) #define _cleanup_free_ _cleanup_(freep) #define _cleanup_close_ _cleanup_(closep) +#define _cleanup_fclose_ _cleanup_(fclosep) #define _cleanup_gstring_ _cleanup_(gstring_free_cleanup) #define BUF_SIZE 256