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