From d13ee992a2ee4be395f926913e33b18bf8ef1383 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Wed, 19 Aug 2020 09:47:28 +0100 Subject: ls: allow backslashes to be replaced in displayed paths Normally 'ls' displays paths exactly as the user enters them: $ ls .//file .//file In busybox-w32 paths using backslash as a separator are displayed in a form that can't be reused as input to the shell: $ ls .\\file .\file Allow backslashes to be replaced with forward slashes if the environment variable BB_FIX_BACKSLASH is set to 1. See GitHub issue #196. --- coreutils/ls.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/coreutils/ls.c b/coreutils/ls.c index fb082f1f3..ad754c14d 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -1074,6 +1074,18 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first) } } +#if ENABLE_PLATFORM_MINGW32 +static char *fix_backslash(char *p) +{ + const char *flag = getenv("BB_FIX_BACKSLASH"); + int value = flag ? atoi(flag) : 0; + + if (value == 1) + bs_to_slash(p); + return p; +} +#endif + int ls_main(int argc UNUSED_PARAM, char **argv) { /* ^^^^^^^^^^^^^^^^^ note: if FTPD, argc can be wrong, see ftpd.c */ @@ -1225,6 +1237,9 @@ int ls_main(int argc UNUSED_PARAM, char **argv) dn = NULL; nfiles = 0; do { +#if ENABLE_PLATFORM_MINGW32 + *argv = fix_backslash(*argv); +#endif cur = my_stat(*argv, *argv, /* follow links on command line unless -l, -i, -s or -F: */ !(option_mask32 & (OPT_l|OPT_i|OPT_s|OPT_F)) -- cgit v1.2.3-55-g6feb