[LTP] [PATCH 1/2] libswap: Move file & line macros to macros

Petr Vorel pvorel@suse.cz
Wed Apr 17 14:31:12 CEST 2024


Having __FILE__ and __LINE__ in C function does not help,
they must be in macros to help identify the caller.

Therefore make_swapfile_() wrapper is not needed.

Fixes: f987ffff5 ("libswap: add two methods to create swapfile")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 include/libswap.h         | 16 +++++-----------
 libs/libltpswap/libswap.c |  2 +-
 2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/include/libswap.h b/include/libswap.h
index 96e718542..87e32328e 100644
--- a/include/libswap.h
+++ b/include/libswap.h
@@ -19,41 +19,35 @@ enum swapfile_method {
 /*
  * Create a swapfile of a specified size or number of blocks.
  */
-int make_swapfile_(const char *file, const int lineno,
+int make_swapfile(const char *file, const int lineno,
 			const char *swapfile, unsigned int num,
 			int safe, enum swapfile_method method);
 
-static inline int make_swapfile(const char *swapfile, unsigned int num,
-			int safe, enum swapfile_method method)
-{
-	return make_swapfile_(__FILE__, __LINE__, swapfile, num, safe, method);
-}
-
 /**
  * Macro to create swapfile size in megabytes (MB).
  */
 #define MAKE_SWAPFILE_SIZE(swapfile, size) \
-    make_swapfile(swapfile, size, 0, SWAPFILE_BY_SIZE)
+    make_swapfile(__FILE__, __LINE__, swapfile, size, 0, SWAPFILE_BY_SIZE)
 
 /**
  * Macro to create swapfile size in block numbers.
  */
 #define MAKE_SWAPFILE_BLKS(swapfile, blocks) \
-    make_swapfile(swapfile, blocks, 0, SWAPFILE_BY_BLKS)
+    make_swapfile(__FILE__, __LINE__, swapfile, blocks, 0, SWAPFILE_BY_BLKS)
 
 /**
  * Macro to safely create swapfile size in megabytes (MB).
  * Includes safety checks to handle potential errors.
  */
 #define SAFE_MAKE_SWAPFILE_SIZE(swapfile, size) \
-    make_swapfile(swapfile, size, 1, SWAPFILE_BY_SIZE)
+    make_swapfile(__FILE__, __LINE__, swapfile, size, 1, SWAPFILE_BY_SIZE)
 
 /**
  * Macro to safely create swapfile size in block numbers.
  * Includes safety checks to handle potential errors.
  */
 #define SAFE_MAKE_SWAPFILE_BLKS(swapfile, blocks) \
-    make_swapfile(swapfile, blocks, 1, SWAPFILE_BY_BLKS)
+    make_swapfile(__FILE__, __LINE__, swapfile, blocks, 1, SWAPFILE_BY_BLKS)
 
 /*
  * Check swapon/swapoff support status of filesystems or files
diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
index 313a15f24..b4233be0d 100644
--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -133,7 +133,7 @@ out:
 	return contiguous;
 }
 
-int make_swapfile_(const char *file, const int lineno,
+int make_swapfile(const char *file, const int lineno,
 			const char *swapfile, unsigned int num,
 			int safe, enum swapfile_method method)
 {
-- 
2.43.0



More information about the ltp mailing list