Re: [PATCH 2/2] strutils: move an error message to where it is used, and improve it
Karel Zak <[email protected]>
| Newsgroups | org.kernel.vger.util-linux |
|---|---|
| Message-ID | <wzqyv5xook6ggpl3bvkw66d2cbj2kd665ko5poat2kw5rw2fs2@iid75zn77wpa> |
On Fri, May 02, 2025 at 02:22:42PM +0200, Benno Schulenberg wrote:
> Calling gettext() is somewhat costly: it has to find the given message
> among the more than five thousand messages in util-linux's repertoire.
> So, call gettext() only when the message actually gets printed.
I like the change. The `gettext()` argument for options parsers is a
common issue, and there may be more areas where we can improve. The
general pattern is:
x = strtoxxx_or_err(optarg, _("invalid xxx argument"));
Perhaps we can use the command line option name as an argument and
compose the final error message within the strtoxxx_or_err()
functions.
x = strtoxxx_or_err(optarg, "xxx");
And in strtoxxx_or_err(const char *str, const char *optname):
errx(STRTOXX_EXIT_CODE, _("invalid %s argument: %s"), optname, str);
BTW, it's pretty common:
$ git grep '.*_or_err' | wc -l
399
so we can save a lot of gettext() calls and make the utils faster.
Volunteers? 😊
Karel
--
Karel Zak <[email protected]>
http://karelzak.blogspot.com