diff --git a/usr.bin/sort/sort.h b/usr.bin/sort/sort.h --- a/usr.bin/sort/sort.h +++ b/usr.bin/sort/sort.h @@ -49,7 +49,8 @@ #include extern nl_catd catalog; -#define getstr(n) catgets(catalog, 1, n, nlsstr[n]) +#define getstr(n) \ + (catalog == (nl_catd)-1 ? nlsstr[n] : catgets(catalog, 1, n, nlsstr[n])) #endif extern const char *nlsstr[]; diff --git a/usr.bin/sort/sort.c b/usr.bin/sort/sort.c --- a/usr.bin/sort/sort.c +++ b/usr.bin/sort/sort.c @@ -57,7 +57,7 @@ #ifndef WITHOUT_NLS #include -nl_catd catalog; +nl_catd catalog = (nl_catd)-1; #endif #define OPTIONS "bcCdfghik:Mmno:RrsS:t:T:uVz" @@ -1011,6 +1011,10 @@ set_tmpdir(); set_sort_opts(); +#ifndef WITHOUT_NLS + catalog = catopen("sort", NL_CAT_LOCALE); +#endif + fix_obsolete_keys(&argc, argv); while (((c = getopt_long(argc, argv, OPTIONS, long_options, NULL)) @@ -1194,17 +1198,9 @@ argv = argv_from_file0; } -#ifndef WITHOUT_NLS - catalog = catopen("sort", NL_CAT_LOCALE); -#endif - if (sort_opts_vals.cflag && sort_opts_vals.mflag) errx(1, "%c:%c: %s", 'm', 'c', getstr(1)); -#ifndef WITHOUT_NLS - catclose(catalog); -#endif - if (keys_num == 0) { keys_num = 1; keys = sort_realloc(keys, sizeof(struct key_specs)); @@ -1343,5 +1339,10 @@ sort_free(outfile); +#ifndef WITHOUT_NLS + if (catalog != (nl_catd)-1) + catclose(catalog); +#endif + return (result); }