From 5c4b026c4ad992badb261268a5d368d245ad80cd Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Thu, 19 Dec 2013 20:10:46 -0800 Subject: [PATCH] Refactor lafe_setprogname slightly to avoid the repeated logic about default handling --- cpio/cpio.c | 4 +--- libarchive_fe/err.c | 6 ++++-- libarchive_fe/err.h | 2 +- tar/bsdtar.c | 4 +--- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/cpio/cpio.c b/cpio/cpio.c index 933bedf3c..98fd83cc7 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -150,9 +150,7 @@ main(int argc, char *argv[]) #endif /* Set lafe_progname before calling lafe_warnc. */ - if (*argv == NULL) - *argv = "bsdcpio"; - lafe_setprogname(*argv); + lafe_setprogname(*argv, "bsdcpio"); #if HAVE_SETLOCALE if (setlocale(LC_ALL, "") == NULL) diff --git a/libarchive_fe/err.c b/libarchive_fe/err.c index 408c2029f..8618a94ea 100644 --- a/libarchive_fe/err.c +++ b/libarchive_fe/err.c @@ -52,9 +52,11 @@ lafe_getprogname(void) } void -lafe_setprogname(const char *name) +lafe_setprogname(const char *name, const char *defaultname) { - + + if (name == NULL) + name = defaultname; #if defined(_WIN32) && !defined(__CYGWIN__) lafe_progname = strrchr(name, '\\'); if (strrchr(name, '/') > lafe_progname) diff --git a/libarchive_fe/err.h b/libarchive_fe/err.h index c351cba88..ebf5de814 100644 --- a/libarchive_fe/err.h +++ b/libarchive_fe/err.h @@ -45,6 +45,6 @@ void lafe_errc(int eval, int code, const char *fmt, ...) __LA_DEAD __LA_PRINTFLIKE(3, 4); const char * lafe_getprogname(void); -void lafe_setprogname(const char *); +void lafe_setprogname(const char *name, const char *defaultname); #endif diff --git a/tar/bsdtar.c b/tar/bsdtar.c index 8b05b4015..d743718f1 100644 --- a/tar/bsdtar.c +++ b/tar/bsdtar.c @@ -179,9 +179,7 @@ main(int argc, char **argv) #endif /* Set lafe_progname before calling lafe_warnc. */ - if (*argv == NULL) - *argv = "bsdtar"; - lafe_setprogname(*argv); + lafe_setprogname(*argv, "bsdtar"); #if HAVE_SETLOCALE if (setlocale(LC_ALL, "") == NULL) -- 2.47.2