]> 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)
committerFlorian Weimer <fweimer@redhat.com>
Tue, 30 Aug 2022 10:42:19 +0000 (12:42 +0200)
(cherry picked from commit cce35a50c1de0cec5cd1f6c18979ff6ee3ea1dd1)

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

index 34262473c111bf6c703cd1ad6f58e22926403a96..2d712a5f7d72a8d34295874737e36a6e45949cc7 100644 (file)
@@ -141,6 +141,7 @@ libsupport-routines = \
   xrealloc \
   xrecvfrom \
   xsendto \
+  xsetlocale \
   xsetsockopt \
   xsigaction \
   xsignal \
index 9d95ebbea1d063f52af1f1c6ca80edb38d8101b9..b0e25be6b1741effca126dd7c2f6d8e589d73e44 100644 (file)
@@ -81,6 +81,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;
+}