[LTP] [PATCH] safe_macros: match oldlib SAFE_CLOSE with docs

Jan Stancek jstancek@redhat.com
Mon Jul 11 16:29:46 CEST 2016


Docs say that SAFE_CLOSE() sets the passed file descriptor to -1
after it's successfully closed, but oldlib SAFE_CLOSE doesn't
do that.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 include/old/safe_macros.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/old/safe_macros.h b/include/old/safe_macros.h
index 6691a15885ab..8ed2eb493960 100644
--- a/include/old/safe_macros.h
+++ b/include/old/safe_macros.h
@@ -26,8 +26,11 @@
 #define SAFE_CHDIR(cleanup_fn, path)	\
 	safe_chdir(__FILE__, __LINE__, (cleanup_fn), (path))
 
-#define SAFE_CLOSE(cleanup_fn, fildes)	\
-	safe_close(__FILE__, __LINE__, (cleanup_fn), (fildes))
+#define SAFE_CLOSE(cleanup_fn, fd) ({ \
+		int ret = safe_close(__FILE__, __LINE__, (cleanup_fn), (fd)); \
+		fd = -1; \
+		ret; \
+	})
 
 #define SAFE_CREAT(cleanup_fn, pathname, mode)	\
 	safe_creat(__FILE__, __LINE__, cleanup_fn, (pathname), (mode))
-- 
1.8.3.1



More information about the ltp mailing list