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