wchar: allow missing mbsnrtowcs()
authorMarko Kreen <markokr@gmail.com>
Fri, 4 Jan 2013 23:05:48 +0000 (01:05 +0200)
committerMarko Kreen <markokr@gmail.com>
Fri, 4 Jan 2013 23:05:48 +0000 (01:05 +0200)
m4/usual.m4
usual/wchar.c

index 734580bfa025189b7cd5fcb5933536d8e4c9bfa1..7ae5de7805ebd72644fa82c3412cae8323b39381 100644 (file)
@@ -231,7 +231,7 @@ AC_CHECK_FUNCS(err errx warn warnx getprogname setprogname)
 AC_CHECK_FUNCS(posix_memalign memalign valloc)
 AC_CHECK_FUNCS(getopt getopt_long getopt_long_only)
 AC_CHECK_FUNCS(fls flsl flsll ffs ffsl ffsll)
-AC_CHECK_FUNCS(fnmatch)
+AC_CHECK_FUNCS(fnmatch mbsnrtowcs)
 ### Functions provided only on win32
 AC_CHECK_FUNCS(localtime_r gettimeofday recvmsg sendmsg usleep getrusage)
 ### Functions used by libusual itself
index f0d2afcd931815daeb8f0fb4a66d01d9f3642e5c..fbed966d224bf9752bf2cb62d6f42d536f10ca12 100644 (file)
@@ -24,7 +24,7 @@ wchar_t *mbstr_decode(const char *str, int str_len, int *wlen_p,
                      wchar_t *wbuf, int wbuf_len, bool allow_invalid)
 {
        mbstate_t ps;
-       int clen, wcnt;
+       int clen;
        wchar_t *dst, *w, *wend;
        const char *s;
        const char *str_end;
@@ -44,15 +44,17 @@ wchar_t *mbstr_decode(const char *str, int str_len, int *wlen_p,
                        return NULL;
        }
 
+#ifdef HAVE_MBSNRTOWCS
        /* try full decode at once */
        s = str;
        memset(&ps, 0, sizeof(ps));
-       wcnt = mbsnrtowcs(dst, &s, str_len, wmax, &ps);
-       if (wcnt > 0 && s == NULL) {
+       clen = mbsnrtowcs(dst, &s, str_len, wmax, &ps);
+       if (clen > 0 && s == NULL) {
                if (wlen_p)
-                       *wlen_p = wcnt;
+                       *wlen_p = clen;
                return dst;
        }
+#endif
 
        /* full decode failed, decode chars one-by-one */
        s = str;