From 14aa5e63ab989e4f85495e96a74f34d18813caf6 Mon Sep 17 00:00:00 2001 From: Zhihao Cheng Date: Mon, 11 Nov 2024 16:36:35 +0800 Subject: ubifs-utils: Clean up error message printing functions Functions 'err_msg' and 'sys_err_msg' are almost same with 'errmsg' and 'sys_errmsg', since 'errmsg' and 'sys_errmsg' can print programe name, so replace error message printing functions (ubifs-utils) with common lib functions(include/common.h). Signed-off-by: Zhihao Cheng Signed-off-by: David Oberhollenzer --- ubifs-utils/common/defs.h | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'ubifs-utils/common/defs.h') diff --git a/ubifs-utils/common/defs.h b/ubifs-utils/common/defs.h index 143f6c6..3dafc6d 100644 --- a/ubifs-utils/common/defs.h +++ b/ubifs-utils/common/defs.h @@ -12,6 +12,13 @@ #include #include +#include "ubifs.h" + +/* common.h requires the PROGRAM_NAME macro */ +extern struct ubifs_info info_; +#define PROGRAM_NAME (info_.program_name) +#include "common.h" + #define MKFS_PROGRAM_NAME "mkfs.ubifs" enum { MKFS_PROGRAM_TYPE = 0 }; @@ -19,21 +26,9 @@ enum { MKFS_PROGRAM_TYPE = 0 }; extern int debug_level; #define dbg_msg(lvl, fmt, ...) do {if (debug_level >= lvl) \ - printf("mkfs.ubifs: %s: " fmt "\n", __FUNCTION__, ##__VA_ARGS__); \ + printf("%s: %s: " fmt "\n", PROGRAM_NAME, __FUNCTION__, ##__VA_ARGS__); \ } while(0) -#define err_msg(fmt, ...) ({ \ - fprintf(stderr, "Error: " fmt "\n", ##__VA_ARGS__); \ - -1; \ -}) - -#define sys_err_msg(fmt, ...) ({ \ - int err_ = errno; \ - fprintf(stderr, "Error: " fmt "\n", ##__VA_ARGS__); \ - fprintf(stderr, " %s (error %d)\n", strerror(err_), err_); \ - -1; \ -}) - #define t16(x) ({ \ uint16_t __b = (x); \ (__LITTLE_ENDIAN==__BYTE_ORDER) ? __b : bswap_16(__b); \ -- cgit v1.2.3