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 | |
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')
-rw-r--r-- | bin/sh/main.c | 2 | ||||
-rw-r--r-- | bin/sh/var.c | 19 | ||||
-rw-r--r-- | bin/sh/var.h | 3 |
3 files changed, 24 insertions, 0 deletions
diff --git a/bin/sh/main.c b/bin/sh/main.c index 12a7ff2..d3250eb 100644 --- a/bin/sh/main.c +++ b/bin/sh/main.c @@ -76,6 +76,7 @@ __FBSDID("$FreeBSD$"); int rootpid; int rootshell; struct jmploc main_handler; +int localeisutf8; static void read_profile(const char *); static char *find_dot_file(char *); @@ -96,6 +97,7 @@ main(int argc, char *argv[]) char *shinit; (void) setlocale(LC_ALL, ""); + updatecharset(); state = 0; if (setjmp(main_handler.loc)) { switch (exception) { 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; diff --git a/bin/sh/var.h b/bin/sh/var.h index 775db41..4336562 100644 --- a/bin/sh/var.h +++ b/bin/sh/var.h @@ -81,6 +81,8 @@ extern struct var vhistsize; extern struct var vterm; #endif +extern int localeisutf8; + /* * The following macros access the values of the above variables. * They have to skip over the name. They return the null string @@ -112,6 +114,7 @@ char *lookupvar(const char *); char *bltinlookup(const char *, int); void bltinsetlocale(void); void bltinunsetlocale(void); +void updatecharset(void); char **environment(void); int showvarscmd(int, char **); int exportcmd(int, char **); |