From 44783347406e77a177cd8f4b1fd81e4c89d9813b Mon Sep 17 00:00:00 2001 From: zrj Date: Fri, 29 Dec 2017 15:37:16 +0200 Subject: [PATCH] libc/locale: Misc cleanup. Mostly whitespace, use NULL and fix typo. --- lib/libc/locale/collate.c | 3 +-- lib/libc/locale/nl_langinfo.c | 2 +- lib/libc/locale/setlocale.c | 28 ++++++++++++++-------------- lib/libc/locale/setrunelocale.c | 17 ++++++++--------- lib/libc/locale/xlocale.c | 6 ++---- lib/libc/locale/xlocale_private.h | 11 +++++------ 6 files changed, 31 insertions(+), 36 deletions(-) diff --git a/lib/libc/locale/collate.c b/lib/libc/locale/collate.c index 1409f18f73..adcb02dd64 100644 --- a/lib/libc/locale/collate.c +++ b/lib/libc/locale/collate.c @@ -96,8 +96,7 @@ __collate_load(const char *encoding, __unused locale_t unused) int __collate_load_tables(const char *encoding) { - int ret = __collate_load_tables_l(encoding, &__xlocale_global_collate); - return ret; + return (__collate_load_tables_l(encoding, &__xlocale_global_collate)); } int diff --git a/lib/libc/locale/nl_langinfo.c b/lib/libc/locale/nl_langinfo.c index 87f2175d89..5f50c8c272 100644 --- a/lib/libc/locale/nl_langinfo.c +++ b/lib/libc/locale/nl_langinfo.c @@ -153,7 +153,7 @@ nl_langinfo_l(nl_item item, locale_t loc) break; /* * YESSTR and NOSTR items marked with LEGACY are available, but not - * recomended by SUSv2 to be used in portable applications since + * recommended by SUSv2 to be used in portable applications since * they're subject to remove in future specification editions. */ case YESSTR: /* LEGACY */ diff --git a/lib/libc/locale/setlocale.c b/lib/libc/locale/setlocale.c index 7776bf55d5..f69fa297c5 100644 --- a/lib/libc/locale/setlocale.c +++ b/lib/libc/locale/setlocale.c @@ -81,7 +81,7 @@ static char current_categories[_LC_LAST][ENCODING_LEN + 1] = { /* * Path to locale storage directory */ -char *_PathLocale; +char *_PathLocale; /* * The locales we are going to try and load @@ -91,15 +91,15 @@ static char saved_categories[_LC_LAST][ENCODING_LEN + 1]; static char current_locale_string[_LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)]; -static char *currentlocale(void); -static char *loadlocale(int); +static char *currentlocale(void); +static char *loadlocale(int); const char *__get_locale_env(int); char * setlocale(int category, const char *locale) { int i, j, len, saverr; - const char *env, *r; + const char *env, *r; if (category < LC_ALL || category >= _LC_LAST) { errno = EINVAL; @@ -160,7 +160,7 @@ setlocale(int category, const char *locale) } do { if (i == _LC_LAST) - break; /* Too many slashes... */ + break; /* Too many slashes... */ if ((len = r - locale) > ENCODING_LEN) { errno = EINVAL; return (NULL); @@ -283,22 +283,22 @@ loadlocale(int category) const char * __get_locale_env(int category) { - const char *env; + const char *env; - /* 1. check LC_ALL. */ - env = getenv(categories[0]); + /* 1. check LC_ALL. */ + env = getenv(categories[0]); - /* 2. check LC_* */ + /* 2. check LC_* */ if (env == NULL || !*env) - env = getenv(categories[category]); + env = getenv(categories[category]); - /* 3. check LANG */ + /* 3. check LANG */ if (env == NULL || !*env) - env = getenv("LANG"); + env = getenv("LANG"); - /* 4. if none is set, fall to "C" */ + /* 4. if none is set, fall to "C" */ if (env == NULL || !*env) - env = "C"; + env = "C"; return (env); } diff --git a/lib/libc/locale/setrunelocale.c b/lib/libc/locale/setrunelocale.c index 1da958d731..ece10102ec 100644 --- a/lib/libc/locale/setrunelocale.c +++ b/lib/libc/locale/setrunelocale.c @@ -38,7 +38,7 @@ */ -#define __RUNETYPE_INTERNAL 1 +#define __RUNETYPE_INTERNAL 1 #include #include @@ -72,7 +72,7 @@ destruct_ctype(void *v) { struct xlocale_ctype *l = v; - if (&_DefaultRuneLocale != l->runes) + if (&_DefaultRuneLocale != l->runes) free(l->runes); free(l); } @@ -81,7 +81,7 @@ const _RuneLocale * __getCurrentRuneLocale(void) { - return XLOCALE_CTYPE(__get_locale())->runes; + return (XLOCALE_CTYPE(__get_locale())->runes); } static void @@ -141,7 +141,7 @@ __setrunelocale(struct xlocale_ctype *l, const char *encoding) else if (strcmp(rl->__encoding, "EUC-TW") == 0) ret = _EUC_TW_init(l, rl); else if (strcmp(rl->__encoding, "GB18030") == 0) - ret = _GB18030_init(l, rl); + ret = _GB18030_init(l, rl); else if (strcmp(rl->__encoding, "GB2312") == 0) ret = _GB2312_init(l, rl); else if (strcmp(rl->__encoding, "GBK") == 0) @@ -196,15 +196,14 @@ __set_thread_rune_locale(locale_t loc) #endif void * -__ctype_load(const char *locale, __unused locale_t unused) +__ctype_load(const char *locale, locale_t unused __unused) { struct xlocale_ctype *l = calloc(sizeof(struct xlocale_ctype), 1); l->header.header.destructor = destruct_ctype; - if (__setrunelocale(l, locale)) - { + if (__setrunelocale(l, locale)) { free(l); - return NULL; + return (NULL); } - return l; + return (l); } diff --git a/lib/libc/locale/xlocale.c b/lib/libc/locale/xlocale.c index 45e44701a4..4044572240 100644 --- a/lib/libc/locale/xlocale.c +++ b/lib/libc/locale/xlocale.c @@ -66,10 +66,8 @@ int __has_thread_locale; /* * Private functions in setlocale.c. */ -const char * -__get_locale_env(int category); -int -__detect_path_locale(void); +const char * __get_locale_env(int category); +int __detect_path_locale(void); struct _xlocale __xlocale_global_locale = { {0}, diff --git a/lib/libc/locale/xlocale_private.h b/lib/libc/locale/xlocale_private.h index 778181858a..4a041fbd2b 100644 --- a/lib/libc/locale/xlocale_private.h +++ b/lib/libc/locale/xlocale_private.h @@ -155,12 +155,11 @@ __attribute__((unused)) static void xlocale_release(void *val) { struct xlocale_refcounted *obj = val; - long count = atomic_fetchadd_long(&(obj->retain_count), -1) - 1; - if (count < 0) { - if (0 != obj->destructor) { - obj->destructor(obj); - } - } + long count; + + count = atomic_fetchadd_long(&(obj->retain_count), -1) - 1; + if (count < 0 && obj->destructor != NULL) + obj->destructor(obj); } /** -- 2.11.4.GIT