From 6ceffc4eaf10275500206a9727b9c6fcd0be7774 Mon Sep 17 00:00:00 2001 From: Tomas Mlcoch Date: Wed, 1 Apr 2015 14:47:18 +0200 Subject: [PATCH] cleanup: More sane _cleanup_file_close_ --- src/cleanup.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cleanup.h b/src/cleanup.h index b3109f0..097ff89 100644 --- a/src/cleanup.h +++ b/src/cleanup.h @@ -30,6 +30,14 @@ G_BEGIN_DECLS +static void +my_close(int fildes) +{ + if (fildes < 0) + return; + close(fildes); +} + #define CR_DEFINE_CLEANUP_FUNCTION(Type, name, func) \ static inline void name (void *v) \ { \ @@ -62,13 +70,13 @@ CR_DEFINE_CLEANUP_FUNCTION0(GKeyFile*, cr_local_keyfile_unref, g_key_file_unref) #endif CR_DEFINE_CLEANUP_FUNCTION0(GPtrArray*, cr_local_ptrarray_unref, g_ptr_array_unref) CR_DEFINE_CLEANUP_FUNCTION0(GTimer*, cr_local_destroy_timer, g_timer_destroy) -CR_DEFINE_CLEANUP_FUNCTION0(int, cr_local_file_close, close) CR_DEFINE_CLEANUP_FUNCTIONt(GString*, cr_local_free_string, g_string_free) CR_DEFINE_CLEANUP_FUNCTION(char**, cr_local_strfreev, g_strfreev) CR_DEFINE_CLEANUP_FUNCTION(GList*, cr_local_free_list, g_list_free) CR_DEFINE_CLEANUP_FUNCTION(void*, cr_local_free, g_free) +CR_DEFINE_CLEANUP_FUNCTION(int, cr_local_file_close, my_close) #define _cleanup_array_unref_ __attribute__ ((cleanup(cr_local_array_unref))) #define _cleanup_checksum_free_ __attribute__ ((cleanup(cr_local_checksum_free))) -- 2.7.4