|
|
1.1.1.9 root 1: /*
2: Legal Notice: The source code contained in this file has been derived from
3: the source code of Encryption for the Masses 2.02a, which is Copyright (c)
4: Paul Le Roux and which is covered by the 'License Agreement for Encryption
5: for the Masses'. Modifications and additions to that source code contained
6: in this file are Copyright (c) TrueCrypt Foundation and are covered by the
1.1.1.10! root 7: TrueCrypt License 2.3 the full text of which is contained in the file
1.1.1.9 root 8: License.txt included in TrueCrypt binary and source code distribution
9: packages. */
1.1 root 10:
1.1.1.6 root 11: #include "Tcdefs.h"
1.1 root 12:
1.1.1.6 root 13: #include <sys/types.h>
14: #include <sys/stat.h>
1.1 root 15: #include <direct.h>
16: #include <string.h>
17: #include <stdlib.h>
18: #include <errno.h>
19:
1.1.1.6 root 20: #include "Dir.h"
1.1 root 21:
22: /* create full directory tree. returns 0 for success, -1 if failure */
23: int
24: mkfulldir (char *path, BOOL bCheckonly)
25: {
26: struct _stat st;
27: char *uniq_file;
28:
29: if (strlen (path) == 3 && path[1] == ':')
30: goto is_root; /* keep final slash in root if present */
31:
32: /* strip final forward or backslash if we have one! */
33: uniq_file = strrchr (path, '\\');
34: if (uniq_file && uniq_file[1] == '\0')
35: uniq_file[0] = '\0';
36: else
37: {
38: uniq_file = strrchr (path, '/');
39: if (uniq_file && uniq_file[1] == '\0')
40: uniq_file[0] = '\0';
41: }
42:
43: is_root:
1.1.1.6 root 44: if (bCheckonly)
1.1 root 45: return _stat (path, &st);
46:
47: if (_stat (path, &st))
48: return mkfulldir_internal (path);
49: else
50: return 0;
51: }
52:
53:
54: int
55: mkfulldir_internal (char *path)
56: {
57: char *token;
58: struct _stat st;
59: static char tokpath[_MAX_PATH];
60: static char trail[_MAX_PATH];
61:
62: strcpy (tokpath, path);
63: trail[0] = '\0';
64:
65: token = strtok (tokpath, "\\/");
66:
67: if (tokpath[0] == '\\' && tokpath[1] == '\\')
68: { /* unc */
69: trail[0] = tokpath[0];
70: trail[1] = tokpath[1];
71: trail[2] = '\0';
72: strcat (trail, token);
73: strcat (trail, "\\");
74: token = strtok (NULL, "\\/");
75: if (token)
76: { /* get share name */
77: strcat (trail, token);
78: strcat (trail, "\\");
79: }
80: token = strtok (NULL, "\\/");
81: }
82:
83: if (tokpath[1] == ':')
84: { /* drive letter */
85: strcat (trail, tokpath);
86: strcat (trail, "\\");
87: token = strtok (NULL, "\\/");
88: }
89:
90: while (token != NULL)
91: {
92: int x;
93: strcat (trail, token);
94: x = _mkdir (trail);
95: strcat (trail, "\\");
96: token = strtok (NULL, "\\/");
97: }
98:
99: return _stat (path, &st);
100: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.