Skip to content

Commit fd4def8

Browse files
lpprojPerditionC
authored andcommitted
DBCS: handle DBCS for "mkdir /p" and "rmdir /s"
(cherry picked from commit b231e93)
1 parent e24bd7e commit fd4def8

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

cmd/mkdir.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
#include "suppl.h"
1111
#include "dfn.h"
12+
#ifdef DBCS
13+
# include "mbcs.h"
14+
#endif
1215

1316
#include "../include/command.h"
1417
#include "../include/misc.h"
@@ -25,7 +28,11 @@ int recursive_mkdir(const char * path, int recursiveMode, int quiet)
2528
dprintf(("fullpath = %s\n", fullname));
2629
do {
2730
while (*p && ((*p != '\\') && (*p != '/'))) {
31+
#ifdef DBCS
32+
p += MbLen(p);
33+
#else
2834
p++;
35+
#endif
2936
}
3037
flag_not_done = *p; /* == 0 when end of path found, nonzero if \ or / */
3138
*p = '\0';

cmd/rmdir.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
#include "suppl.h"
1515
#include "dfn.h"
16+
#ifdef DBCS
17+
# include "mbcs.h"
18+
#endif
1619

1720
#include "../include/command.h"
1821
#include "../include/misc.h"
@@ -25,15 +28,23 @@
2528
#endif
2629

2730
/* recursively delete subdirs and files */
31+
#ifdef DBCS
32+
int rmdir_withfiles(const char * fullname, char * path, int maxlen)
33+
#else
2834
int rmdir_withfiles(char * path, int maxlen)
35+
#endif
2936
{
3037
struct dos_ffblk f;
3138
int ret;
3239
int len = strlen(path); /* Warning: we assume path is a buffer is large enough for longest file path */
3340
char *p = path+len;
3441

3542
/* ensure ends with \ */
43+
#ifdef DBCS
44+
if (*fullname && *(CharPrev(fullname, p)) != '\\')
45+
#else
3646
if (p[-1] != '\\')
47+
#endif
3748
*p++ = '\\';
3849
*p = '\0';
3950

@@ -60,7 +71,11 @@ int rmdir_withfiles(char * path, int maxlen)
6071

6172
strcpy(p, f.ff_name); /* Make the full path */
6273
/* recursively delete subdirectory */
74+
#ifdef DBCS
75+
ret = rmdir_withfiles(fullname, path, maxlen);
76+
#else
6377
ret = rmdir_withfiles(path, maxlen);
78+
#endif
6479
}
6580
} while (!ret && (dos_findnext(&f) == 0));
6681
dos_findclose(&f);
@@ -128,7 +143,11 @@ int recursive_rmdir(const char * path, int recursiveMode, int quiet)
128143
}
129144

130145
/* ensure ends with \ */
146+
#ifdef DBCS
147+
if (len > 0 && *(CharPrev(fullname, p)) != '\\')
148+
#else
131149
if (p[-1] != '\\')
150+
#endif
132151
*p++ = '\\';
133152
*p = 0;
134153

@@ -141,8 +160,11 @@ int recursive_rmdir(const char * path, int recursiveMode, int quiet)
141160
return E_Other;
142161
}
143162
}
144-
163+
#ifdef DBCS
164+
return rmdir_withfiles(fullname, fullname, sizeof(fullname));
165+
#else
145166
return rmdir_withfiles(fullname, sizeof(fullname));
167+
#endif
146168
} else {
147169
return rmdir(path);
148170
}

0 commit comments

Comments
 (0)