X-Git-Url: http://git.draconx.ca/gitweb/dxcommon.git/blobdiff_plain/02e6afe4c4956fd667dfefc04e8f129b5b84f709..476f42d951d7e9f9f30e1a6acb34982466936490:/src/help.c diff --git a/src/help.c b/src/help.c index f96025f..4b77b2c 100644 --- a/src/help.c +++ b/src/help.c @@ -68,9 +68,23 @@ enum { OPT_LONG_WITHOUT_ARG = 0, }; +/* + * When NLS is enabled, we assume snprintf is available. The GNU libintl + * library should provide a suitable fallback if necessary. + */ +#if ENABLE_NLS && !defined(help_do_snprintf) +#define help_do_snprintf snprintf +#elif !ENABLE_NLS +#define help_do_snprintf fake_snprintf +static inline int fake_snprintf(char *buf, size_t n, const char *fmt, ...) +{ + return -1; +} +#endif + int help_print_optstring(const struct option *opt, const char *argname, int l) { - char optstring[100]; + char optstring[256]; int w; if (!ENABLE_NLS) @@ -80,56 +94,56 @@ int help_print_optstring(const struct option *opt, const char *argname, int l) #if HELP_GETOPT_LONG_ONLY case OPT_SHORT_WITH_OPTIONAL_ARG: case OPT_LONG_WITH_OPTIONAL_ARG: - w = snprintf(optstring, sizeof optstring, - _(" -%s [%s]"), opt->name, - pgettext_expr(opt->name, argname)); + w = help_do_snprintf(optstring, sizeof optstring, + _(" -%s [%s]"), opt->name, + pgettext_expr(opt->name, argname)); break; case OPT_SHORT_WITH_MANDATORY_ARG: case OPT_LONG_WITH_MANDATORY_ARG: - w = snprintf(optstring, sizeof optstring, - _(" -%s %s"), opt->name, - pgettext_expr(opt->name, argname)); + w = help_do_snprintf(optstring, sizeof optstring, + _(" -%s %s"), opt->name, + pgettext_expr(opt->name, argname)); break; case OPT_SHORT_WITHOUT_ARG: case OPT_LONG_WITHOUT_ARG: - w = snprintf(optstring, sizeof optstring, - _(" -%s"), opt->name); + w = help_do_snprintf(optstring, sizeof optstring, + _(" -%s"), opt->name); break; #else case OPT_SHORT_WITH_OPTIONAL_ARG: - w = snprintf(optstring, sizeof optstring, - _(" -%c, --%s[=%s]"), opt->val, opt->name, - pgettext_expr(opt->name, argname)); + w = help_do_snprintf(optstring, sizeof optstring, + _(" -%c, --%s[=%s]"), opt->val, opt->name, + pgettext_expr(opt->name, argname)); break; case OPT_LONG_WITH_OPTIONAL_ARG: - w = snprintf(optstring, sizeof optstring, - _(" --%s[=%s]"), opt->name, - pgettext_expr(opt->name, argname)); + w = help_do_snprintf(optstring, sizeof optstring, + _(" --%s[=%s]"), opt->name, + pgettext_expr(opt->name, argname)); break; case OPT_SHORT_WITH_MANDATORY_ARG: - w = snprintf(optstring, sizeof optstring, - _(" -%c, --%s=%s"), opt->val, opt->name, - pgettext_expr(opt->name, argname)); + w = help_do_snprintf(optstring, sizeof optstring, + _(" -%c, --%s=%s"), opt->val, opt->name, + pgettext_expr(opt->name, argname)); break; case OPT_LONG_WITH_MANDATORY_ARG: - w = snprintf(optstring, sizeof optstring, - _(" --%s=%s"), opt->name, - pgettext_expr(opt->name, argname)); + w = help_do_snprintf(optstring, sizeof optstring, + _(" --%s=%s"), opt->name, + pgettext_expr(opt->name, argname)); break; case OPT_SHORT_WITHOUT_ARG: - w = snprintf(optstring, sizeof optstring, - _(" -%c, --%s"), opt->val, opt->name); + w = help_do_snprintf(optstring, sizeof optstring, + _(" -%c, --%s"), opt->val, opt->name); break; case OPT_LONG_WITHOUT_ARG: - w = snprintf(optstring, sizeof optstring, - _(" --%s"), opt->name); + w = help_do_snprintf(optstring, sizeof optstring, + _(" --%s"), opt->name); break; #endif default: assert(0); } - if (w < 0) + if (w < 0 || w >= sizeof optstring) goto no_translate; w = mbsnwidth(optstring, w, 0);