]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
support: Add xsetlocale function
authorArjun Shankar <arjun@redhat.com>
Mon, 11 Nov 2019 13:57:23 +0000 (14:57 +0100)
committerArjun Shankar <ashankar@redhat.com>
Mon, 11 Nov 2019 16:40:46 +0000 (17:40 +0100)
support/Makefile
support/support.h
support/xsetlocale.c [new file with mode: 0644]

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