* [PATCH] mtd-utils: common.h: clean up PROGRAM_NAME usage
@ 2010-09-27 6:40 Mike Frysinger
2010-09-27 6:42 ` Artem Bityutskiy
0 siblings, 1 reply; 2+ messages in thread
From: Mike Frysinger @ 2010-09-27 6:40 UTC (permalink / raw)
To: linux-mtd
Make PROGRAM_NAME required in order to include common.h so we can rely
on it existing.
Further, stop embedding PROGRAM_NAME in every error message so that we
can save string space with it being declare only once.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
include/common.h | 25 ++++++++++++-------------
1 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/include/common.h b/include/common.h
index 11b0cf6..dce067b 100644
--- a/include/common.h
+++ b/include/common.h
@@ -24,10 +24,9 @@
#include <string.h>
#include <errno.h>
-/*
- * Note, the user is supposed to define its PROGRAM_NAME before including this
- * header.
- */
+#ifndef PROGRAM_NAME
+# error "You must define PROGRAM_NAME before including this header"
+#endif
#ifdef __cplusplus
extern "C" {
@@ -43,27 +42,27 @@ extern "C" {
printf(fmt, ##__VA_ARGS__); \
} while(0)
#define verbose(verbose, fmt, ...) \
- bareverbose(verbose, PROGRAM_NAME ": " fmt "\n", ##__VA_ARGS__)
+ bareverbose(verbose, "%s: " fmt "\n", PROGRAM_NAME, ##__VA_ARGS__)
/* Normal messages */
-#define normsg(fmt, ...) do { \
- printf(PROGRAM_NAME ": " fmt "\n", ##__VA_ARGS__); \
+#define normsg_cont(fmt, ...) do { \
+ printf("%s: " fmt, PROGRAM_NAME, ##__VA_ARGS__); \
} while(0)
-#define normsg_cont(fmt, ...) do { \
- printf(PROGRAM_NAME ": " fmt, ##__VA_ARGS__); \
+#define normsg(fmt, ...) do { \
+ normsg_cont(fmt "\n", ##__VA_ARGS__); \
} while(0)
/* Error messages */
#define errmsg(fmt, ...) ({ \
- fprintf(stderr, PROGRAM_NAME ": error!: " fmt "\n", ##__VA_ARGS__); \
+ fprintf(stderr, "%s: error!: " fmt "\n", PROGRAM_NAME, ##__VA_ARGS__); \
-1; \
})
/* System error messages */
#define sys_errmsg(fmt, ...) ({ \
int _err = errno; \
- size_t _i; \
- fprintf(stderr, PROGRAM_NAME ": error!: " fmt "\n", ##__VA_ARGS__); \
+ size_t _i; \
+ errmsg(fmt, ##__VA_ARGS__); \
for (_i = 0; _i < sizeof(PROGRAM_NAME) + 1; _i++) \
fprintf(stderr, " "); \
fprintf(stderr, "error %d (%s)\n", _err, strerror(_err)); \
@@ -72,7 +71,7 @@ extern "C" {
/* Warnings */
#define warnmsg(fmt, ...) do { \
- fprintf(stderr, PROGRAM_NAME ": warning!: " fmt "\n", ##__VA_ARGS__); \
+ fprintf(stderr, "%s: warning!: " fmt "\n", PROGRAM_NAME, ##__VA_ARGS__); \
} while(0)
static inline int is_power_of_2(unsigned long long n)
--
1.7.2.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mtd-utils: common.h: clean up PROGRAM_NAME usage
2010-09-27 6:40 [PATCH] mtd-utils: common.h: clean up PROGRAM_NAME usage Mike Frysinger
@ 2010-09-27 6:42 ` Artem Bityutskiy
0 siblings, 0 replies; 2+ messages in thread
From: Artem Bityutskiy @ 2010-09-27 6:42 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd
On Mon, 2010-09-27 at 02:40 -0400, Mike Frysinger wrote:
> Make PROGRAM_NAME required in order to include common.h so we can rely
> on it existing.
>
> Further, stop embedding PROGRAM_NAME in every error message so that we
> can save string space with it being declare only once.
>
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
> include/common.h | 25 ++++++++++++-------------
> 1 files changed, 12 insertions(+), 13 deletions(-)
Pushed, thanks!
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-09-27 6:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-27 6:40 [PATCH] mtd-utils: common.h: clean up PROGRAM_NAME usage Mike Frysinger
2010-09-27 6:42 ` Artem Bityutskiy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).