"Fossies" - the Fresh Open Source Software Archive 
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "Dir.c" see the
Fossies "Dox" file reference documentation.
1 /*
2 Legal Notice: Some portions of the source code contained in this file were
3 derived from the source code of TrueCrypt 7.1a, which is
4 Copyright (c) 2003-2012 TrueCrypt Developers Association and which is
5 governed by the TrueCrypt License 3.0, also from the source code of
6 Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux
7 and which is governed by the 'License Agreement for Encryption for the Masses'
8 Modifications and additions to the original source code (contained in this file)
9 and all other portions of this file are Copyright (c) 2013-2017 IDRIX
10 and are governed by the Apache License 2.0 the full text of which is
11 contained in the file License.txt included in VeraCrypt binary and source
12 code distribution packages. */
13
14 #include "Tcdefs.h"
15
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #include <direct.h>
19 #include <string.h>
20 #include <stdlib.h>
21 #include <errno.h>
22 #include <Strsafe.h>
23
24 #include "Dir.h"
25
26 /* create full directory tree. returns 0 for success, -1 if failure */
27 int
28 mkfulldir (wchar_t *oriPath, BOOL bCheckonly)
29 {
30 struct _stat st;
31 wchar_t *uniq_file;
32 wchar_t path [TC_MAX_PATH];
33
34 StringCbCopyW (path, TC_MAX_PATH, oriPath);
35
36 if (wcslen (path) == 3 && path[1] == L':')
37 goto is_root; /* keep final slash in root if present */
38
39 /* strip final forward or backslash if we have one! */
40 uniq_file = wcsrchr (path, L'\\');
41 if (uniq_file && uniq_file[1] == L'\0')
42 uniq_file[0] = L'\0';
43 else
44 {
45 uniq_file = wcsrchr (path, L'/');
46 if (uniq_file && uniq_file[1] == L'\0')
47 uniq_file[0] = L'\0';
48 }
49
50 is_root:
51 if (bCheckonly)
52 return _wstat (path, &st);
53
54 if (_wstat (path, &st))
55 return mkfulldir_internal (path);
56 else
57 return 0;
58 }
59
60
61 int
62 mkfulldir_internal (wchar_t *path)
63 {
64 wchar_t *token;
65 struct _stat st;
66 static wchar_t tokpath[_MAX_PATH];
67 static wchar_t trail[_MAX_PATH];
68
69 StringCbCopyW (tokpath, _MAX_PATH, path);
70 trail[0] = L'\0';
71
72 token = wcstok (tokpath, L"\\/");
73
74 if (tokpath[0] == L'\\' && tokpath[1] == L'\\')
75 { /* unc */
76 trail[0] = tokpath[0];
77 trail[1] = tokpath[1];
78 trail[2] = L'\0';
79 if (token)
80 {
81 StringCbCatW (trail, _MAX_PATH, token);
82 StringCbCatW (trail, _MAX_PATH, L"\\");
83 token = wcstok (NULL, L"\\/");
84 if (token)
85 { /* get share name */
86 StringCbCatW (trail, _MAX_PATH, token);
87 StringCbCatW (trail, _MAX_PATH, L"\\");
88 }
89 token = wcstok (NULL, L"\\/");
90 }
91 }
92
93 if (tokpath[1] == L':')
94 { /* drive letter */
95 StringCbCatW (trail, _MAX_PATH, tokpath);
96 StringCbCatW (trail, _MAX_PATH, L"\\");
97 token = wcstok (NULL, L"\\/");
98 }
99
100 while (token != NULL)
101 {
102 int x;
103 StringCbCatW (trail, _MAX_PATH, token);
104 x = _wmkdir (trail);
105 StringCbCatW (trail, _MAX_PATH, L"\\");
106 token = wcstok (NULL, L"\\/");
107 }
108
109 return _wstat (path, &st);
110 }