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