[PATCH 2/4] lib/strutils: call gettext() only when argument of --hyperlink is invalid

Benno Schulenberg <[email protected]>
Newsgroups org.kernel.vger.util-linux
Message-ID <[email protected]>
Signed-off-by: Benno Schulenberg <[email protected]>
---
 include/strutils.h   | 2 +-
 lib/strutils.c       | 4 ++--
 lsfd-cmd/lsfd.c      | 3 +--
 misc-utils/findmnt.c | 3 +--
 misc-utils/lsblk.c   | 3 +--
 5 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/include/strutils.h b/include/strutils.h
index a81fdea89..70f97f0c8 100644
--- a/include/strutils.h
+++ b/include/strutils.h
@@ -59,7 +59,7 @@ extern void strtotimespec_or_err(const char *str, struct timespec *ts,
 		const char *errmesg);
 extern time_t strtotime_or_err(const char *str, const char *errmesg);
 
-extern bool hyperlinkwanted_or_err(const char *mode, const char *errmesg);
+extern bool hyperlinkwanted(const char *mode);
 
 extern int isdigit_strend(const char *str, const char **end);
 #define isdigit_string(_s)	isdigit_strend(_s, NULL)
diff --git a/lib/strutils.c b/lib/strutils.c
index af538207a..64fefa878 100644
--- a/lib/strutils.c
+++ b/lib/strutils.c
@@ -524,7 +524,7 @@ time_t strtotime_or_err(const char *str, const char *errmesg)
 	return (time_t) user_input;
 }
 
-bool hyperlinkwanted_or_err(const char *mode, const char *errmesg)
+bool hyperlinkwanted(const char *mode)
 {
 	if (mode && strcmp(mode, "never") == 0)
 		return false;
@@ -535,7 +535,7 @@ bool hyperlinkwanted_or_err(const char *mode, const char *errmesg)
 	if (!mode || strcmp(mode, "auto") == 0)
 		return isatty(STDOUT_FILENO) ? true : false;
 
-	errx(EXIT_FAILURE, "%s: '%s'", errmesg, mode);
+	errx(EXIT_FAILURE, _("invalid argument of --hyperlink: %s"), mode);
 }
 
 /*
diff --git a/lsfd-cmd/lsfd.c b/lsfd-cmd/lsfd.c
index d05a09396..ffaca8c31 100644
--- a/lsfd-cmd/lsfd.c
+++ b/lsfd-cmd/lsfd.c
@@ -2648,8 +2648,7 @@ int main(int argc, char *argv[])
 				err(EXIT_FAILURE, _("failed to drop privilege"));
 			break;
 		case OPT_HYPERLINK:
-			if (hyperlinkwanted_or_err(optarg,
-					_("invalid hyperlink argument")))
+			if (hyperlinkwanted(optarg))
 				ctl.uri = xgethosturi(NULL);
 			break;
 		case 'V':
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
index 130ac1b13..1211bfa07 100644
--- a/misc-utils/findmnt.c
+++ b/misc-utils/findmnt.c
@@ -2026,8 +2026,7 @@ int main(int argc, char *argv[])
 			findmnt.flags |= FL_SHADOWED;
 			break;
 		case FINDMNT_OPT_HYPERLINK:
-			if (hyperlinkwanted_or_err(optarg,
-					_("invalid hyperlink argument")))
+			if (hyperlinkwanted(optarg))
 				findmnt.uri = xgethosturi(NULL);
 			break;
 		case FINDMNT_OPT_ID:
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index a65f5e4e6..da44bd631 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -2678,8 +2678,7 @@ int main(int argc, char *argv[])
 				errtryhelp(EXIT_FAILURE);
 			break;
 		case OPT_HYPERLINK:
-			if (hyperlinkwanted_or_err(optarg,
-					_("invalid hyperlink argument")))
+			if (hyperlinkwanted(optarg))
 				lsblk->uri = xgethosturi(NULL);
 			break;
 		case 'H':
-- 
2.48.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.