]> err.no Git - util-linux/commitdiff
lib: add fallback for nl_langinfo()
authorKarel Zak <kzak@redhat.com>
Mon, 15 Nov 2010 15:42:45 +0000 (16:42 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 15 Nov 2010 15:42:45 +0000 (16:42 +0100)
The fallback ignores locales and returns hardcoded static strings. It
should be enough to include "nls.h" to work with nl_langinfo() on all
systems.

Signed-off-by: Karel Zak <kzak@redhat.com>
configure.ac
include/nls.h
lib/langinfo.c [new file with mode: 0644]

index 561424a63a430a40fe46f0a550354392c768b138..ca3e4af5a709e971fbbcd7d2873f4e8dc96fe5e3 100644 (file)
@@ -110,7 +110,6 @@ AC_CHECK_HEADERS(
        [err.h \
        errno.h \
        getopt.h \
-       langinfo.h \
        linux/fd.h \
        linux/tiocl.h \
        linux/version.h \
@@ -146,10 +145,16 @@ AC_CHECK_HEADERS(
        sys/user.h \
        sys/resource.h \
        unistd.h ])
+
 AC_CHECK_HEADERS([linux/raw.h],
                 [AM_CONDITIONAL([HAVE_RAW], [true])],
                 [AM_CONDITIONAL([HAVE_RAW], [false])])
 
+AC_CHECK_HEADERS([langinfo.h],
+               [AM_CONDITIONAL([HAVE_LANGINFO], [true])],
+               [AM_CONDITIONAL([HAVE_LANGINFO], [false])])
+
+
 AC_CHECK_DECLS([_NL_TIME_WEEK_1STDAY],[],[],[[#include <langinfo.h>]])
 
 AC_CHECK_DECL([llseek],
index dd0440c9a3e1aba08df0dc540a037c6cd8a98272..00f2e37a745a344b6f8b293706ae7daf155a5782 100644 (file)
@@ -31,4 +31,77 @@ int main(int argc, char *argv[]);
 # define N_(Text) (Text)
 #endif
 
+#ifdef HAVE_LANGINFO_H
+# include <langinfo.h>
+#else
+
+typedef int nl_item;
+extern char *langinfo_fallback(nl_item item);
+
+# define nl_langinfo   langinfo_fallback
+
+enum {
+       CODESET = 1,
+       RADIXCHAR,
+       THOUSEP,
+       D_T_FMT,
+       D_FMT,
+       T_FMT,
+       T_FMT_AMPM,
+       AM_STR,
+       PM_STR,
+
+       DAY_1,
+       DAY_2,
+       DAY_3,
+       DAY_4,
+       DAY_5,
+       DAY_6,
+       DAY_7,
+
+       ABDAY_1,
+       ABDAY_2,
+       ABDAY_3,
+       ABDAY_4,
+       ABDAY_5,
+       ABDAY_6,
+       ABDAY_7,
+
+       MON_1,
+       MON_2,
+       MON_3,
+       MON_4,
+       MON_5,
+       MON_6,
+       MON_7,
+       MON_8,
+       MON_9,
+       MON_10,
+       MON_11,
+       MON_12,
+
+       ABMON_1,
+       ABMON_2,
+       ABMON_3,
+       ABMON_4,
+       ABMON_5,
+       ABMON_6,
+       ABMON_7,
+       ABMON_8,
+       ABMON_9,
+       ABMON_10,
+       ABMON_11,
+       ABMON_12,
+
+       ERA_D_FMT,
+       ERA_D_T_FMT,
+       ERA_T_FMT,
+       ALT_DIGITS,
+       CRNCYSTR,
+       YESEXPR,
+       NOEXPR
+};
+
+#endif /* !HAVE_LANGINFO_H */
+
 #endif /* UTIL_LINUX_NLS_H */
diff --git a/lib/langinfo.c b/lib/langinfo.c
new file mode 100644 (file)
index 0000000..deeab9b
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * This is callback solution for systems without nl_langinfo(), this function
+ * returns hardcoded and on locale setting independed value.
+ *
+ * See langinfo.h man page for more details.
+ *
+ * Copyright (C) 2010 Karel Zak <kzak@redhat.com>
+ */
+#include "nls.h"
+
+char *langinfo_fallback(nl_item item)
+{
+       switch (item) {
+       case CODESET:
+               return "ISO-8859-1";
+       case THOUSEP:
+               return ",";
+       case D_T_FMT:
+       case ERA_D_T_FMT:
+               return "%a %b %e %H:%M:%S %Y";
+       case D_FMT:
+       case ERA_D_FMT:
+               return "%m/%d/%y";
+       case T_FMT:
+       case ERA_T_FMT:
+               return "%H:%M:%S";
+       case T_FMT_AMPM:
+               return "%I:%M:%S %p";
+       case AM_STR:
+               return "AM";
+       case PM_STR:
+               return "PM";
+       case DAY_1:
+               return "Sunday";
+       case DAY_2:
+               return "Monday";
+       case DAY_3:
+               return "Tuesday";
+       case DAY_4:
+               return "Wednesday";
+       case DAY_5:
+               return "Thursday";
+       case DAY_6:
+               return "Friday";
+       case DAY_7:
+               return "Saturday";
+       case ABDAY_1:
+               return "Sun";
+       case ABDAY_2:
+               return "Mon";
+       case ABDAY_3:
+               return "Tue";
+       case ABDAY_4:
+               return "Wed";
+       case ABDAY_5:
+               return "Thu";
+       case ABDAY_6:
+               return "Fri";
+       case ABDAY_7:
+               return "Sat";
+       case MON_1:
+               return "January";
+       case MON_2:
+               return "February";
+       case MON_3:
+               return "March";
+       case MON_4:
+               return "April";
+       case MON_5:
+               return "May";
+       case MON_6:
+               return "June";
+       case MON_7:
+               return "July";
+       case MON_8:
+               return "August";
+       case MON_9:
+               return "September";
+       case MON_10:
+               return "October";
+       case MON_11:
+               return "November";
+       case MON_12:
+               return "December";
+       case ABMON_1:
+               return "Jan";
+       case ABMON_2:
+               return "Feb";
+       case ABMON_3:
+               return "Mar";
+       case ABMON_4:
+               return "Apr";
+       case ABMON_5:
+               return "May";
+       case ABMON_6:
+               return "Jun";
+       case ABMON_7:
+               return "Jul";
+       case ABMON_8:
+               return "Aug";
+       case ABMON_9:
+               return "Sep";
+       case ABMON_10:
+               return "Oct";
+       case ABMON_11:
+               return "Nov";
+       case ABMON_12:
+               return "Dec";
+       case ALT_DIGITS:
+               return "\0\0\0\0\0\0\0\0\0\0";
+       case CRNCYSTR:
+               return "-";
+       case YESEXPR:
+               return "^[yY]";
+       case NOEXPR:
+               return "^[nN]";
+       default:
+               return "";
+       }
+}
+