From: Tim Kientzle Date: Fri, 20 Dec 2013 04:10:46 +0000 (-0800) Subject: Refactor lafe_setprogname slightly to avoid the repeated logic about default handling X-Git-Tag: v3.1.900a~352 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c4b026c4ad992badb261268a5d368d245ad80cd;p=thirdparty%2Flibarchive.git Refactor lafe_setprogname slightly to avoid the repeated logic about default handling --- 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)