add MakeSureDirectoryPathExistsExA/W
Added: trunk/reactos/include/rosrtl/path.h
Added: trunk/reactos/lib/rosrtl/file/path.c
Modified: trunk/reactos/lib/rosrtl/makefile
_____
Added: trunk/reactos/include/rosrtl/path.h
--- trunk/reactos/include/rosrtl/path.h 2005-01-12 06:02:58 UTC (rev
12944)
+++ trunk/reactos/include/rosrtl/path.h 2005-01-12 07:51:11 UTC (rev
12945)
@@ -0,0 +1,21 @@
+/*
+ */
+
+#ifndef ROSRTL_PATH_H__
+#define ROSRTL_PATH_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+BOOL STDCALL MakeSureDirectoryPathExistsExA(LPCSTR DirPath, BOOL
FileAtEnd);
+BOOL STDCALL MakeSureDirectoryPathExistsExW(LPCWSTR DirPath, BOOL
FileAtEnd);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+/* EOF */
_____
Added: trunk/reactos/lib/rosrtl/file/path.c
--- trunk/reactos/lib/rosrtl/file/path.c 2005-01-12 06:02:58 UTC
(rev 12944)
+++ trunk/reactos/lib/rosrtl/file/path.c 2005-01-12 07:51:11 UTC
(rev 12945)
@@ -0,0 +1,100 @@
+#include <windows.h>
+#include <string.h>
+
+
+/**********************************************************************
*
+ * MakeSureDirectoryPathExistsExA
+ *
+ * If a dir is at the end and the path ends with a backslash, FileAtEnd
+ * is ignored. If the path doesn't end with a backslash, FileAtEnd is
+ * used to determine if the last part of the path is a file name or a
+ * directory.
+ *
+ * Path may be absolute or relative to current dir.
+ */
+BOOL STDCALL MakeSureDirectoryPathExistsExA(LPCSTR DirPath, BOOL
FileAtEnd)
+{
+ char Path[MAX_PATH];
+ char *SlashPos = Path;
+ char Slash;
+ BOOL bRes;
+
+ strcpy(Path, DirPath);
+
+ while((SlashPos=strpbrk(SlashPos+1,"\\/")))
+ {
+ Slash = *SlashPos;
+ *SlashPos = 0;
+
+ bRes = CreateDirectoryA(Path, NULL);
+ if (bRes == FALSE && GetLastError() != ERROR_ALREADY_EXISTS)
+ {
+ return FALSE;
+ }
+
+ *SlashPos = Slash;
+
+ if (*(SlashPos+1) == 0) return TRUE;
+ }
+
+ if (!FileAtEnd)
+ {
+ bRes = CreateDirectoryA(Path, NULL);
+ if (bRes == FALSE && GetLastError() != ERROR_ALREADY_EXISTS)
+ {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+
+
+
+/**********************************************************************
*
+ * MakeSureDirectoryPathExistsExW
+ *
+ * If a dir is at the end and the path ends with a backslash, FileAtEnd
+ * is ignored. If the path doesn't end with a backslash, FileAtEnd is
+ * used to determine if the last part of the path is a file name or a
+ * directory.
+ *
+ * Path may be absolute or relative to current dir.
+ */
+BOOL STDCALL MakeSureDirectoryPathExistsExW(LPCWSTR DirPath, BOOL
FileAtEnd)
+{
+ WCHAR Path[MAX_PATH];
+ WCHAR *SlashPos = Path;
+ WCHAR Slash;
+ BOOL bRes;
+
+ wcscpy(Path, DirPath);
+
+ while((SlashPos=wcspbrk(SlashPos+1,L"\\/")))
+ {
+ Slash = *SlashPos;
+ *SlashPos = 0;
+
+ bRes = CreateDirectoryW(Path, NULL);
+ if (bRes == FALSE && GetLastError() != ERROR_ALREADY_EXISTS)
+ {
+ return FALSE;
+ }
+
+ *SlashPos = Slash;
+
+ if (*(SlashPos+1) == 0) return TRUE;
+ }
+
+ if (!FileAtEnd)
+ {
+ bRes = CreateDirectoryW(Path, NULL);
+ if (bRes == FALSE && GetLastError() != ERROR_ALREADY_EXISTS)
+ {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
_____
Modified: trunk/reactos/lib/rosrtl/makefile
--- trunk/reactos/lib/rosrtl/makefile 2005-01-12 06:02:58 UTC (rev
12944)
+++ trunk/reactos/lib/rosrtl/makefile 2005-01-12 07:51:11 UTC (rev
12945)
@@ -30,7 +30,8 @@
misc/qsort.o
FILE_OBJECTS = \
- file/sparse.o
+ file/sparse.o \
+ file/path.o
RECMUTEX_OBJECTS = recmutex/recmutex.o