]> 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)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 30 Nov 2020 22:59:53 +0000 (22:59 +0000)
(cherry picked from commit cce35a50c1de0cec5cd1f6c18979ff6ee3ea1dd1)

support/Makefile
support/support.h
support/xsetlocale.c [new file with mode: 0644]

index bcdb428a4fb5cc72a814a3ef1e4d52198d020d8a..e88a144096f8e70b8900317e66b635e393ce86ce 100644 (file)
@@ -136,6 +136,7 @@ libsupport-routines = \
   xrealloc \
   xrecvfrom \
   xsendto \
+  xsetlocale \
   xsetsockopt \
   xsigaction \
   xsignal \
index 4ea92e1c2109c06fc9e8879cb54c0fd1d252647a..e2de14cf832f374c36b96aba181b4da664686553 100644 (file)
@@ -80,6 +80,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);
 
 __END_DECLS
 
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;
+}