aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/mbyte.c
diff options
context:
space:
mode:
authorScott Prager <splinterofchaos@gmail.com>2015-05-03 09:25:53 -0400
committerScott Prager <splinterofchaos@gmail.com>2015-05-29 13:12:12 -0400
commit412d246be71bd99cb4edde4e6f984b0b0d91bcd9 (patch)
tree01307051583b9cf2faf56778a9bd88e00d2a2122 /src/nvim/mbyte.c
parentfa0f1222212704c93ab828b876bda5e9e1cb507e (diff)
downloadrneovim-412d246be71bd99cb4edde4e6f984b0b0d91bcd9.tar.gz
rneovim-412d246be71bd99cb4edde4e6f984b0b0d91bcd9.tar.bz2
rneovim-412d246be71bd99cb4edde4e6f984b0b0d91bcd9.zip
getenv: return NULL if empty #2574
Making an environment variable empty can be a way of unsetting it for platforms that don't support unsetenv(). In most cases, we treat empty variables as having been unset. For all others, use os_env_exists().
Diffstat (limited to 'src/nvim/mbyte.c')
-rw-r--r--src/nvim/mbyte.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index b6e08ab277..368ae8e773 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -3398,22 +3398,29 @@ static int enc_alias_search(char_u *name)
*/
char_u * enc_locale(void)
{
- char *s;
- char *p;
int i;
char buf[50];
+
+ const char *s;
# ifdef HAVE_NL_LANGINFO_CODESET
- if ((s = nl_langinfo(CODESET)) == NULL || *s == NUL)
+ if (!(s = nl_langinfo(CODESET)) || *s == NUL)
# endif
+ {
# if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
- if ((s = setlocale(LC_CTYPE, NULL)) == NULL || *s == NUL)
+ if (!(s = setlocale(LC_CTYPE, NULL)) || *s == NUL)
# endif
- if ((s = (char *)os_getenv("LC_ALL")) == NULL || *s == NUL)
- if ((s = (char *)os_getenv("LC_CTYPE")) == NULL || *s == NUL)
- s = (char *)os_getenv("LANG");
+ {
+ if ((s = os_getenv("LC_ALL"))) {
+ if ((s = os_getenv("LC_CTYPE"))) {
+ s = os_getenv("LANG");
+ }
+ }
+ }
+ }
- if (s == NULL || *s == NUL)
+ if (!s) {
return NULL;
+ }
/* The most generic locale format is:
* language[_territory][.codeset][@modifier][+special][,[sponsor][_revision]]
@@ -3423,11 +3430,12 @@ char_u * enc_locale(void)
* Exception: "ja_JP.EUC" == "euc-jp", "zh_CN.EUC" = "euc-cn",
* "ko_KR.EUC" == "euc-kr"
*/
- if ((p = (char *)vim_strchr((char_u *)s, '.')) != NULL) {
- if (p > s + 2 && STRNICMP(p + 1, "EUC", 3) == 0
+ const char *p = (char *)vim_strchr((char_u *)s, '.');
+ if (p != NULL) {
+ if (p > s + 2 && !STRNICMP(p + 1, "EUC", 3)
&& !isalnum((int)p[4]) && p[4] != '-' && p[-3] == '_') {
/* copy "XY.EUC" to "euc-XY" to buf[10] */
- STRCPY(buf + 10, "euc-");
+ strcpy(buf + 10, "euc-");
buf[14] = p[-2];
buf[15] = p[-1];
buf[16] = 0;