Re: [PATCH 2/2] strutils: move an error message to where it is used, and improve it

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com





[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux