Aric Stewart : wcmd: mkdir recursive create
Alexandre Julliard
julliard at wine.codeweavers.com
Sat Dec 3 12:31:11 CST 2005
Module: wine
Branch: refs/heads/master
Commit: 1d5adff0f1216f9930762c00cdb44d1e16e73836
URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=1d5adff0f1216f9930762c00cdb44d1e16e73836
Author: Aric Stewart <aric at codeweavers.com>
Date: Sat Dec 3 18:02:15 2005 +0100
wcmd: mkdir recursive create
In at least both win2k and winxp mkdir from the command prompt can
recursively create full directory paths. This implements that
functionality.
---
programs/wcmd/builtins.c | 49 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 48 insertions(+), 1 deletions(-)
diff --git a/programs/wcmd/builtins.c b/programs/wcmd/builtins.c
index 5652089..a47bc0a 100644
--- a/programs/wcmd/builtins.c
+++ b/programs/wcmd/builtins.c
@@ -150,11 +150,58 @@ char string[8], outpath[MAX_PATH], inpat
* WCMD_create_dir
*
* Create a directory.
+ *
+ * this works recursivly. so mkdir dir1\dir2\dir3 will create dir1 and dir2 if
+ * they do not already exist.
*/
+BOOL create_full_path(CHAR* path)
+{
+ int len;
+ CHAR *new_path;
+ BOOL ret = TRUE;
+
+ new_path = HeapAlloc(GetProcessHeap(),0,strlen(path)+1);
+ strcpy(new_path,path);
+
+ while ((len = strlen(new_path)) && new_path[len - 1] == '\\')
+ new_path[len - 1] = 0;
+
+ while (!CreateDirectory(new_path,NULL))
+ {
+ CHAR *slash;
+ DWORD last_error = GetLastError();
+ if (last_error == ERROR_ALREADY_EXISTS)
+ break;
+
+ if (last_error != ERROR_PATH_NOT_FOUND)
+ {
+ ret = FALSE;
+ break;
+ }
+
+ if (!(slash = strrchr(new_path,'\\')) && ! (slash = strrchr(new_path,'/')))
+ {
+ ret = FALSE;
+ break;
+ }
+
+ len = slash - new_path;
+ new_path[len] = 0;
+ if (!create_full_path(new_path))
+ {
+ ret = FALSE;
+ break;
+ }
+ new_path[len] = '\\';
+ }
+ HeapFree(GetProcessHeap(),0,new_path);
+ return ret;
+}
+
void WCMD_create_dir (void) {
- if (!CreateDirectory (param1, NULL)) WCMD_print_error ();
+ if (!create_full_path(param1)) WCMD_print_error ();
}
/****************************************************************************
More information about the wine-cvs
mailing list