From 79213f0d63fe286fbfc73cfe6b1004d368258800 Mon Sep 17 00:00:00 2001
From: Yorhel <git@yorhel.nl>
Date: Sun, 13 Apr 2014 08:34:32 +0200
Subject: [PATCH] Support building without locale.h

Slightly modified patch from Gianluigi Tiesi.
http://dev.yorhel.nl/ncdu/bug/47
---
 configure.ac |  6 ++++--
 src/main.c   |  2 --
 src/util.c   | 11 +++++++----
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/configure.ac b/configure.ac
index b8a6bfd..4e87cf2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,9 +12,11 @@ PKG_PROG_PKG_CONFIG
 
 # Check for header files.
 AC_CHECK_HEADERS(
-  [limits.h sys/time.h sys/types.h sys/stat.h dirent.h unistd.h fnmatch.h ncurses.h locale.h],[],
+  [limits.h sys/time.h sys/types.h sys/stat.h dirent.h unistd.h fnmatch.h ncurses.h],[],
   AC_MSG_ERROR([required header file not found]))
 
+AC_CHECK_HEADERS(locale.h)
+
 # Check for typedefs, structures, and compiler characteristics.
 AC_TYPE_INT64_T
 AC_TYPE_UINT64_T
@@ -23,7 +25,7 @@ AC_STRUCT_ST_BLOCKS
 
 # Check for library functions.
 AC_CHECK_FUNCS(
-  [getcwd gettimeofday fnmatch chdir rmdir unlink lstat setlocale],[],
+  [getcwd gettimeofday fnmatch chdir rmdir unlink lstat],[],
   AC_MSG_ERROR([required function missing]))
 
 
diff --git a/src/main.c b/src/main.c
index 2e30d25..3426548 100644
--- a/src/main.c
+++ b/src/main.c
@@ -32,7 +32,6 @@
 
 #include <unistd.h>
 #include <sys/time.h>
-#include <locale.h>
 
 #include <yopt.h>
 
@@ -255,7 +254,6 @@ static void init_nc() {
 
 /* main program */
 int main(int argc, char **argv) {
-  setlocale(LC_ALL, "");
   read_locale();
   argv_parse(argc, argv);
 
diff --git a/src/util.c b/src/util.c
index ba28326..2028893 100644
--- a/src/util.c
+++ b/src/util.c
@@ -29,7 +29,9 @@
 #include <stdlib.h>
 #include <ncurses.h>
 #include <stdarg.h>
+#ifdef HAVE_LOCALE_H
 #include <locale.h>
+#endif
 
 int winrows, wincols;
 int subwinr, subwinc;
@@ -113,12 +115,13 @@ char *fullsize(int64_t from) {
 
 
 void read_locale() {
+  thou_sep = '.';
+#ifdef HAVE_LOCALE_H
+  setlocale(LC_ALL, "");
   char *locale_thou_sep = localeconv()->thousands_sep;
-  if (locale_thou_sep && 1 == strlen(locale_thou_sep)) {
+  if(locale_thou_sep && 1 == strlen(locale_thou_sep))
     thou_sep = locale_thou_sep[0];
-  } else {
-    thou_sep = '.';
-  }
+#endif
 }
 
 
-- 
GitLab