[vlc-devel] [PATCH] configure: Improve the detection of POSIX locale features

Kamil Rytarowski n54 at gmx.com
Thu Feb 22 09:51:09 CET 2018


Split the detection of the POSIX locale support from a single check
of uselocale() to multiple ones.

Newly added autotools checks:
 - <locale.h> header available,
 - locale_t type available,
 - newlocale() function available,
 - freelocale() function available,
 - setlocale() function available.

While there don't blindly define for systems without uselocale()
in the vlc_fixups.h header:
 - LC_ALL_MASK
 - LC_NUMERIC_MASK
 - LC_MESSAGES_MASK
 - LC_GLOBAL_LOCALE

This corrects NetBSD build failres where all the features are
available, with the exception of missing uselocale().

While there, don't include <locale.h> in file.c just for systems
with uselocale().
---
 configure.ac         | 10 +++++++++-
 include/vlc_fixups.h | 31 +++++++++++++++++++++++++++++--
 src/config/file.c    |  2 +-
 3 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 5bf2a0366e..dfb8a08273 100644
--- a/configure.ac
+++ b/configure.ac
@@ -590,7 +590,7 @@ dnl Check for system libs needed
 need_libc=false
 
 dnl Check for usual libc functions
-AC_CHECK_FUNCS([accept4 daemon fcntl flock fstatvfs fork getenv getpwuid_r isatty lstat memalign mkostemp mmap open_memstream openat pipe2 pread posix_fadvise posix_madvise posix_memalign setlocale stricmp strnicmp strptime uselocale])
+AC_CHECK_FUNCS([accept4 daemon fcntl flock fstatvfs fork getenv getpwuid_r isatty lstat memalign mkostemp mmap open_memstream openat pipe2 pread posix_fadvise posix_madvise posix_memalign setlocale stricmp strnicmp strptime uselocale freelocale newlocale])
 AC_REPLACE_FUNCS([aligned_alloc atof atoll dirfd fdopendir ffsll flockfile fsync getdelim getpid lldiv memrchr nrand48 poll recvmsg rewind sendmsg setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tdestroy tfind timegm timespec_get strverscmp pathconf])
 AC_REPLACE_FUNCS([gettimeofday])
 AC_CHECK_FUNC(fdatasync,,
@@ -852,6 +852,14 @@ AC_CHECK_HEADERS([features.h getopt.h linux/dccp.h linux/magic.h mntent.h sys/ev
 dnl  MacOS
 AC_CHECK_HEADERS([xlocale.h])
 
+dnl  POSIX
+AC_CHECK_HEADERS([locale.h])
+
+dnl  locale_t in locale.h
+AC_CHECK_TYPE([locale_t],
+  AC_DEFINE([HAVE_LOCALE_T], [1], [locale_t available]),,
+  [#include <locale.h>])
+
 dnl LP64 and LLP64 architectures had better define ssize_t by themselves...
 AH_TEMPLATE(ssize_t, [Define to `int' if <stddef.h> does not define.]) dnl ` (fix VIM syntax highlight
 AC_CHECK_TYPE(ssize_t,, [
diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
index f1bcd06ce9..b498743dcc 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -316,24 +316,51 @@ void *aligned_alloc(size_t, size_t);
 
 #if defined(__native_client__) && defined(__cplusplus)
 # define HAVE_USELOCALE
+# define HAVE_FREELOCALE
+# define HAVE_NEWLOCALE
 #endif
 
 /* locale.h */
-#ifndef HAVE_USELOCALE
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
+#ifndef LC_ALL_MASK
 #define LC_ALL_MASK      0
+#endif
+
+#ifndef LC_NUMERIC_MASK
 #define LC_NUMERIC_MASK  0
+#endif
+
+#ifndef LC_MESSAGES_MASK
 #define LC_MESSAGES_MASK 0
-#define LC_GLOBAL_LOCALE ((locale_t)(uintptr_t)1)
+#endif
+
+#ifndef HAVE_LOCALE_T
 typedef void *locale_t;
+#endif
+
+#ifndef LC_GLOBAL_LOCALE
+#define LC_GLOBAL_LOCALE ((locale_t)(uintptr_t)1)
+#endif
+
+#ifndef HAVE_USELOCALE
 static inline locale_t uselocale(locale_t loc)
 {
     (void)loc;
     return NULL;
 }
+#endif
+
+#ifndef HAVE_FREELOCALE
 static inline void freelocale(locale_t loc)
 {
     (void)loc;
 }
+#endif
+
+#ifndef HAVE_NEWLOCALE
 static inline locale_t newlocale(int mask, const char * locale, locale_t base)
 {
     (void)mask; (void)locale; (void)base;
diff --git a/src/config/file.c b/src/config/file.c
index 6270a6bc9d..16b9d55377 100644
--- a/src/config/file.c
+++ b/src/config/file.c
@@ -32,7 +32,7 @@
 #include <sys/stat.h>
 #ifdef __APPLE__
 #   include <xlocale.h>
-#elif defined(HAVE_USELOCALE)
+#elif defined(HAVE_LOCALE_H)
 #include <locale.h>
 #endif
 #include <unistd.h>
-- 
2.16.1



More information about the vlc-devel mailing list