diff options
author | Ron Yorston <rmy@pobox.com> | 2020-08-19 09:47:28 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2020-08-19 10:00:27 +0100 |
commit | d13ee992a2ee4be395f926913e33b18bf8ef1383 (patch) | |
tree | 50c81955e83037ec901443f9fb5e5889ce0a07c1 | |
parent | b95ed10bd31d57b1ca1fac0de273bbe98903d0b8 (diff) | |
download | busybox-w32-fix_backslash.tar.gz busybox-w32-fix_backslash.tar.bz2 busybox-w32-fix_backslash.zip |
ls: allow backslashes to be replaced in displayed pathsfix_backslash
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.
-rw-r--r-- | coreutils/ls.c | 15 |
1 files changed, 15 insertions, 0 deletions
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) | |||
1074 | } | 1074 | } |
1075 | } | 1075 | } |
1076 | 1076 | ||
1077 | #if ENABLE_PLATFORM_MINGW32 | ||
1078 | static char *fix_backslash(char *p) | ||
1079 | { | ||
1080 | const char *flag = getenv("BB_FIX_BACKSLASH"); | ||
1081 | int value = flag ? atoi(flag) : 0; | ||
1082 | |||
1083 | if (value == 1) | ||
1084 | bs_to_slash(p); | ||
1085 | return p; | ||
1086 | } | ||
1087 | #endif | ||
1088 | |||
1077 | 1089 | ||
1078 | int ls_main(int argc UNUSED_PARAM, char **argv) | 1090 | int ls_main(int argc UNUSED_PARAM, char **argv) |
1079 | { /* ^^^^^^^^^^^^^^^^^ note: if FTPD, argc can be wrong, see ftpd.c */ | 1091 | { /* ^^^^^^^^^^^^^^^^^ note: if FTPD, argc can be wrong, see ftpd.c */ |
@@ -1225,6 +1237,9 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |||
1225 | dn = NULL; | 1237 | dn = NULL; |
1226 | nfiles = 0; | 1238 | nfiles = 0; |
1227 | do { | 1239 | do { |
1240 | #if ENABLE_PLATFORM_MINGW32 | ||
1241 | *argv = fix_backslash(*argv); | ||
1242 | #endif | ||
1228 | cur = my_stat(*argv, *argv, | 1243 | cur = my_stat(*argv, *argv, |
1229 | /* follow links on command line unless -l, -i, -s or -F: */ | 1244 | /* follow links on command line unless -l, -i, -s or -F: */ |
1230 | !(option_mask32 & (OPT_l|OPT_i|OPT_s|OPT_F)) | 1245 | !(option_mask32 & (OPT_l|OPT_i|OPT_s|OPT_F)) |