diff options
author | jilles <jilles@FreeBSD.org> | 2010-05-05 21:48:40 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2010-05-05 21:48:40 +0000 |
commit | f3856c6cf2fb115757967b7e32bdeb21bd27d1ee (patch) | |
tree | 01c037f5647b269e05a273c3cef3f8cb4478c6f9 /bin/sh/eval.c | |
parent | a5718881d81033624f276036560f07f69ceac0cc (diff) | |
download | FreeBSD-src-f3856c6cf2fb115757967b7e32bdeb21bd27d1ee.zip FreeBSD-src-f3856c6cf2fb115757967b7e32bdeb21bd27d1ee.tar.gz |
sh: Apply locale vars on builtins, recognize LC_MESSAGES as a locale var.
This allows doing things like LC_ALL=C some_builtin to run a builtin under a
different locale, just like is possible with external programs. The
immediate reason is that this allows making printf(1) a builtin without
breaking things like LC_NUMERIC=C printf '%f\n' 1.2
This change also affects special builtins, as even though the assignment is
persistent, the export is only to the builtin (unless the variable was
already exported).
Note: for this to work for builtins that also exist as external programs
such as /bin/test, the setlocale() call must be under #ifndef SHELL. The
shell will do the setlocale() calls which may not agree with the environment
variables.
Diffstat (limited to 'bin/sh/eval.c')
-rw-r--r-- | bin/sh/eval.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c index e93fb14..c4495d0 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -937,6 +937,8 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) cmdentry.special = 1; if (cmdentry.special) listsetvar(cmdenviron); + if (argc > 0) + bltinsetlocale(); commandname = argv[0]; argptr = argv + 1; nextopt_optptr = NULL; /* initialize nextopt */ @@ -944,6 +946,8 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) exitstatus = (*builtinfunc[cmdentry.u.index])(argc, argv); flushall(); cmddone: + if (argc > 0) + bltinunsetlocale(); cmdenviron = NULL; out1 = &output; out2 = &errout; |