libc: minor indent(1) cleanups.

Illumos and Schillix is adopting some of the locale code and our style(9)
sometimes matches the Solaris cstyle, so the changes are also useful as a
way to reduce diffs.

No functional change.

Discussed with: Joerg Schilling
MFC after:	1 week
This commit is contained in:
Pedro F. Giffuni 2017-08-26 16:11:21 +00:00
parent 8657387683
commit be53a489c6
3 changed files with 47 additions and 51 deletions

View File

@ -249,7 +249,7 @@ rangematch(const char *pattern, wchar_t test, int flags, char **newp,
* consistency with the regular expression syntax.
* J.T. Conklin (conklin@ngai.kaleida.com)
*/
if ( (negate = (*pattern == '!' || *pattern == '^')) )
if ((negate = (*pattern == '!' || *pattern == '^')))
++pattern;
if (flags & FNM_CASEFOLD)

View File

@ -42,48 +42,48 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <limits.h>
#include <locale.h>
#include <paths.h> /* for _PATH_LOCALE */
#include <paths.h> /* for _PATH_LOCALE */
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "collate.h"
#include "lmonetary.h" /* for __monetary_load_locale() */
#include "lnumeric.h" /* for __numeric_load_locale() */
#include "lmessages.h" /* for __messages_load_locale() */
#include "lmonetary.h" /* for __monetary_load_locale() */
#include "lnumeric.h" /* for __numeric_load_locale() */
#include "lmessages.h" /* for __messages_load_locale() */
#include "setlocale.h"
#include "ldpart.h"
#include "../stdtime/timelocal.h" /* for __time_load_locale() */
#include "../stdtime/timelocal.h" /* for __time_load_locale() */
/*
* Category names for getenv()
*/
static const char categories[_LC_LAST][12] = {
"LC_ALL",
"LC_COLLATE",
"LC_CTYPE",
"LC_MONETARY",
"LC_NUMERIC",
"LC_TIME",
"LC_MESSAGES",
"LC_ALL",
"LC_COLLATE",
"LC_CTYPE",
"LC_MONETARY",
"LC_NUMERIC",
"LC_TIME",
"LC_MESSAGES",
};
/*
* Current locales for each category
*/
static char current_categories[_LC_LAST][ENCODING_LEN + 1] = {
"C",
"C",
"C",
"C",
"C",
"C",
"C",
"C",
"C",
"C",
"C",
"C",
"C",
"C",
};
/*
* Path to locale storage directory
*/
char *_PathLocale;
char *_PathLocale;
/*
* The locales we are going to try and load
@ -93,21 +93,20 @@ 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;
return (NULL);
}
if (locale == NULL)
return (category != LC_ALL ?
current_categories[category] : currentlocale());
@ -162,13 +161,13 @@ 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);
}
(void)strlcpy(new_categories[i], locale,
len + 1);
len + 1);
i++;
while (*r == '/')
r++;
@ -178,7 +177,7 @@ setlocale(int category, const char *locale)
} while (*locale);
while (i < _LC_LAST) {
(void)strcpy(new_categories[i],
new_categories[i-1]);
new_categories[i - 1]);
i++;
}
}
@ -193,7 +192,7 @@ setlocale(int category, const char *locale)
saverr = errno;
for (j = 1; j < i; j++) {
(void)strcpy(new_categories[j],
saved_categories[j]);
saved_categories[j]);
if (loadlocale(j) == NULL) {
(void)strcpy(new_categories[j], "C");
(void)loadlocale(j);
@ -218,7 +217,7 @@ currentlocale(void)
for (i = 2; i < _LC_LAST; ++i) {
(void)strcat(current_locale_string, "/");
(void)strcat(current_locale_string,
current_categories[i]);
current_categories[i]);
}
break;
}
@ -230,16 +229,15 @@ loadlocale(int category)
{
char *new = new_categories[category];
char *old = current_categories[category];
int (*func)(const char *);
int (*func) (const char *);
int saved_errno;
if ((new[0] == '.' &&
(new[1] == '\0' || (new[1] == '.' && new[2] == '\0'))) ||
(new[1] == '\0' || (new[1] == '.' && new[2] == '\0'))) ||
strchr(new, '/') != NULL) {
errno = EINVAL;
return (NULL);
}
saved_errno = errno;
errno = __detect_path_locale();
if (errno != 0)
@ -285,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);
}
@ -326,4 +324,3 @@ __detect_path_locale(void)
}
return (0);
}

View File

@ -38,7 +38,7 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#define __RUNETYPE_INTERNAL 1
#define __RUNETYPE_INTERNAL 1
#include <runetype.h>
#include <errno.h>
@ -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
@ -144,7 +144,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)
@ -204,10 +204,9 @@ __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);
}