diff options
author | jilles <jilles@FreeBSD.org> | 2011-05-06 22:31:27 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2011-05-06 22:31:27 +0000 |
commit | 6672b66ab789f3a873bf4afedd4e33f79c47960d (patch) | |
tree | e050eac60e8f976d2dc8403b5f48b7fee966845d /bin/sh/var.c | |
parent | d5f31a325b1e05306848b941346f144f410e2097 (diff) | |
download | FreeBSD-src-6672b66ab789f3a873bf4afedd4e33f79c47960d.zip FreeBSD-src-6672b66ab789f3a873bf4afedd4e33f79c47960d.tar.gz |
sh: Track if the current locale's charset is UTF-8 or not.
Diffstat (limited to 'bin/sh/var.c')
-rw-r--r-- | bin/sh/var.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/bin/sh/var.c b/bin/sh/var.c index e14027f..5c87a1f 100644 --- a/bin/sh/var.c +++ b/bin/sh/var.c @@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$"); */ #include <locale.h> +#include <langinfo.h> #include "shell.h" #include "output.h" @@ -361,6 +362,7 @@ setvareq(char *s, int flags) if ((vp->flags & VEXPORT) && localevar(s)) { change_env(s, 1); (void) setlocale(LC_ALL, ""); + updatecharset(); } INTON; return; @@ -379,6 +381,7 @@ setvareq(char *s, int flags) if ((vp->flags & VEXPORT) && localevar(s)) { change_env(s, 1); (void) setlocale(LC_ALL, ""); + updatecharset(); } INTON; } @@ -480,6 +483,7 @@ bltinsetlocale(void) if (loc != NULL) { setlocale(LC_ALL, loc); INTON; + updatecharset(); return; } locdef = bltinlookup("LANG", 0); @@ -491,6 +495,7 @@ bltinsetlocale(void) setlocale(locale_categories[i], loc); } INTON; + updatecharset(); } /* @@ -505,12 +510,24 @@ bltinunsetlocale(void) for (lp = cmdenviron ; lp ; lp = lp->next) { if (localevar(lp->text)) { setlocale(LC_ALL, ""); + updatecharset(); return; } } INTON; } +/* + * Update the localeisutf8 flag. + */ +void +updatecharset(void) +{ + char *charset; + + charset = nl_langinfo(CODESET); + localeisutf8 = !strcmp(charset, "UTF-8"); +} /* * Generate a list of exported variables. This routine is used to construct @@ -656,6 +673,7 @@ exportcmd(int argc, char **argv) if ((vp->flags & VEXPORT) && localevar(vp->text)) { change_env(vp->text, 1); (void) setlocale(LC_ALL, ""); + updatecharset(); } goto found; } @@ -850,6 +868,7 @@ unsetvar(const char *s) if ((vp->flags & VEXPORT) && localevar(vp->text)) { change_env(s, 0); setlocale(LC_ALL, ""); + updatecharset(); } vp->flags &= ~VEXPORT; vp->flags |= VUNSET; |