summaryrefslogtreecommitdiff
path: root/src/locale
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2017-03-21 08:54:19 -0400
committerRich Felker <dalias@aerifal.cx>2017-03-21 08:54:19 -0400
commit16319a5df9d50cfc642ffc8db76bc36562d4b3dd (patch)
treec7d54e4442dae129ec052d50a6b48e73e170ff84 /src/locale
parent0c53178ec09478ca5f6ca6b5ad09d50a10c8f19d (diff)
downloadmusl-16319a5df9d50cfc642ffc8db76bc36562d4b3dd.tar.gz
musl-16319a5df9d50cfc642ffc8db76bc36562d4b3dd.tar.bz2
musl-16319a5df9d50cfc642ffc8db76bc36562d4b3dd.tar.xz
musl-16319a5df9d50cfc642ffc8db76bc36562d4b3dd.zip
make setlocale return a single name for LC_ALL if all categories match
when called for LC_ALL, setlocale has to return a string representing the state of all locale categories. the simplest way to do this was to always return a delimited list of values for each category, but that's not friendly in the fairly common case where all categories have the same setting. He X proposed a patch to check for this case and return a single name; this patch is a simplified approach to do the same.
Diffstat (limited to 'src/locale')
-rw-r--r--src/locale/setlocale.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/locale/setlocale.c b/src/locale/setlocale.c
index 8dae5a4e..623660cc 100644
--- a/src/locale/setlocale.c
+++ b/src/locale/setlocale.c
@@ -48,10 +48,13 @@ char *setlocale(int cat, const char *name)
}
}
char *s = buf;
+ const char *part;
+ int same = 0;
for (i=0; i<LC_ALL; i++) {
const struct __locale_map *lm =
libc.global_locale.cat[i];
- const char *part = lm ? lm->name : "C";
+ if (lm == libc.global_locale.cat[0]) same++;
+ part = lm ? lm->name : "C";
size_t l = strlen(part);
memcpy(s, part, l);
s[l] = ';';
@@ -59,7 +62,7 @@ char *setlocale(int cat, const char *name)
}
*--s = 0;
UNLOCK(lock);
- return buf;
+ return same==LC_ALL ? (char *)part : buf;
}
char *ret = setlocale_one_unlocked(cat, name);