inetd: comment tweak. no code changes
[oweals/busybox.git] / coreutils / ls.c
index 8a6faf23f7dec120d9fcf95a1426debde3ff2fd8..827b3508930f0366f20ec4db072764088a7ad2d0 100644 (file)
  * [2009-03]
  * ls sorts listing now, and supports almost all options.
  */
-
 #include "libbb.h"
+#include "unicode.h"
 
-#if ENABLE_FEATURE_ASSUME_UNICODE
-#include <wchar.h>
-#endif
 
 /* This is a NOEXEC applet. Be very careful! */
 
@@ -292,21 +289,6 @@ enum {
 } while (0)
 
 
-#if ENABLE_FEATURE_ASSUME_UNICODE
-/* libbb candidate */
-static size_t mbstrlen(const char *string)
-{
-       size_t width = mbsrtowcs(NULL /*dest*/, &string,
-                               MAXINT(size_t) /*len*/, NULL /*state*/);
-       if (width == (size_t)-1)
-               return strlen(string);
-       return width;
-}
-#else
-#define mbstrlen(string) strlen(string)
-#endif
-
-
 static struct dnode *my_stat(const char *fullname, const char *name, int force_follow)
 {
        struct stat dstat;
@@ -574,7 +556,7 @@ static void showfiles(struct dnode **dn, int nfiles)
        } else {
                /* find the longest file name, use that as the column width */
                for (i = 0; i < nfiles; i++) {
-                       int len = mbstrlen(dn[i]->name);
+                       int len = bb_mbstrlen(dn[i]->name);
                        if (column_width < len)
                                column_width = len;
                }
@@ -721,7 +703,7 @@ static int print_name(const char *name)
 {
        if (option_mask32 & OPT_Q) {
 #if ENABLE_FEATURE_ASSUME_UNICODE
-               int len = 2 + mbstrlen(name);
+               int len = 2 + bb_mbstrlen(name);
 #else
                int len = 2;
 #endif
@@ -741,7 +723,7 @@ static int print_name(const char *name)
        /* No -Q: */
 #if ENABLE_FEATURE_ASSUME_UNICODE
        fputs(name, stdout);
-       return mbstrlen(name);
+       return bb_mbstrlen(name);
 #else
        return printf("%s", name);
 #endif
@@ -932,6 +914,8 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
 
        INIT_G();
 
+       check_unicode_in_env();
+
        all_fmt = LIST_SHORT |
                (ENABLE_FEATURE_LS_SORTFILES * (SORT_NAME | SORT_FORWARD));