|
|
446cf2 |
commit cce35a50c1de0cec5cd1f6c18979ff6ee3ea1dd1
|
|
|
446cf2 |
Author: Arjun Shankar <arjun@redhat.com>
|
|
|
446cf2 |
Date: Mon Nov 11 14:57:23 2019 +0100
|
|
|
446cf2 |
|
|
|
446cf2 |
support: Add xsetlocale function
|
|
|
446cf2 |
|
|
|
446cf2 |
diff --git a/support/Makefile b/support/Makefile
|
|
|
446cf2 |
index 37d5dcc92a5c6dee..6afaa6836c944398 100644
|
|
|
446cf2 |
--- a/support/Makefile
|
|
|
446cf2 |
+++ b/support/Makefile
|
|
|
446cf2 |
@@ -148,6 +148,7 @@ libsupport-routines = \
|
|
|
446cf2 |
xrealloc \
|
|
|
446cf2 |
xrecvfrom \
|
|
|
446cf2 |
xsendto \
|
|
|
446cf2 |
+ xsetlocale \
|
|
|
446cf2 |
xsetsockopt \
|
|
|
446cf2 |
xsigaction \
|
|
|
446cf2 |
xsignal \
|
|
|
446cf2 |
diff --git a/support/support.h b/support/support.h
|
|
|
446cf2 |
index 61a10c34982134ff..97d142e9b6f68188 100644
|
|
|
446cf2 |
--- a/support/support.h
|
|
|
446cf2 |
+++ b/support/support.h
|
|
|
446cf2 |
@@ -91,6 +91,7 @@ char *xasprintf (const char *format, ...)
|
|
|
446cf2 |
__attribute__ ((format (printf, 1, 2), malloc));
|
|
|
446cf2 |
char *xstrdup (const char *);
|
|
|
446cf2 |
char *xstrndup (const char *, size_t);
|
|
|
446cf2 |
+char *xsetlocale (int category, const char *locale);
|
|
|
446cf2 |
|
|
|
446cf2 |
/* These point to the TOP of the source/build tree, not your (or
|
|
|
446cf2 |
support's) subdirectory. */
|
|
|
446cf2 |
diff --git a/support/xsetlocale.c b/support/xsetlocale.c
|
|
|
446cf2 |
new file mode 100644
|
|
|
446cf2 |
index 0000000000000000..063ed4b0d63af884
|
|
|
446cf2 |
--- /dev/null
|
|
|
446cf2 |
+++ b/support/xsetlocale.c
|
|
|
446cf2 |
@@ -0,0 +1,30 @@
|
|
|
446cf2 |
+/* setlocale with error checking.
|
|
|
446cf2 |
+ Copyright (C) 2019 Free Software Foundation, Inc.
|
|
|
446cf2 |
+ This file is part of the GNU C Library.
|
|
|
446cf2 |
+
|
|
|
446cf2 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
446cf2 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
446cf2 |
+ License as published by the Free Software Foundation; either
|
|
|
446cf2 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
446cf2 |
+
|
|
|
446cf2 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
446cf2 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
446cf2 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
446cf2 |
+ Lesser General Public License for more details.
|
|
|
446cf2 |
+
|
|
|
446cf2 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
446cf2 |
+ License along with the GNU C Library; if not, see
|
|
|
446cf2 |
+ <https://www.gnu.org/licenses/>. */
|
|
|
446cf2 |
+
|
|
|
446cf2 |
+#include <support/check.h>
|
|
|
446cf2 |
+
|
|
|
446cf2 |
+#include <locale.h>
|
|
|
446cf2 |
+
|
|
|
446cf2 |
+char *
|
|
|
446cf2 |
+xsetlocale (int category, const char *locale)
|
|
|
446cf2 |
+{
|
|
|
446cf2 |
+ char *p = setlocale (category, locale);
|
|
|
446cf2 |
+ if (p == NULL)
|
|
|
446cf2 |
+ FAIL_EXIT1 ("error: setlocale (%d, \"%s\")\n", category, locale);
|
|
|
446cf2 |
+ return p;
|
|
|
446cf2 |
+}
|