|
|
1.1 ! root 1: /* Copyright (C) 2004 TrueCrypt Team, truecrypt.org ! 2: This product uses components written by Paul Le Roux <[email protected]> */ ! 3: ! 4: #include "TCdefs.h" ! 5: ! 6: #include <sys\types.h> ! 7: #include <sys\stat.h> ! 8: #include <direct.h> ! 9: #include <string.h> ! 10: #include <stdlib.h> ! 11: #include <errno.h> ! 12: ! 13: #include "dir.h" ! 14: ! 15: /* create full directory tree. returns 0 for success, -1 if failure */ ! 16: int ! 17: mkfulldir (char *path, BOOL bCheckonly) ! 18: { ! 19: struct _stat st; ! 20: char *uniq_file; ! 21: ! 22: if (strlen (path) == 3 && path[1] == ':') ! 23: goto is_root; /* keep final slash in root if present */ ! 24: ! 25: /* strip final forward or backslash if we have one! */ ! 26: uniq_file = strrchr (path, '\\'); ! 27: if (uniq_file && uniq_file[1] == '\0') ! 28: uniq_file[0] = '\0'; ! 29: else ! 30: { ! 31: uniq_file = strrchr (path, '/'); ! 32: if (uniq_file && uniq_file[1] == '\0') ! 33: uniq_file[0] = '\0'; ! 34: } ! 35: ! 36: is_root: ! 37: if (bCheckonly == TRUE) ! 38: return _stat (path, &st); ! 39: ! 40: if (_stat (path, &st)) ! 41: return mkfulldir_internal (path); ! 42: else ! 43: return 0; ! 44: } ! 45: ! 46: ! 47: int ! 48: mkfulldir_internal (char *path) ! 49: { ! 50: char *token; ! 51: struct _stat st; ! 52: static char tokpath[_MAX_PATH]; ! 53: static char trail[_MAX_PATH]; ! 54: ! 55: strcpy (tokpath, path); ! 56: trail[0] = '\0'; ! 57: ! 58: token = strtok (tokpath, "\\/"); ! 59: ! 60: if (tokpath[0] == '\\' && tokpath[1] == '\\') ! 61: { /* unc */ ! 62: trail[0] = tokpath[0]; ! 63: trail[1] = tokpath[1]; ! 64: trail[2] = '\0'; ! 65: strcat (trail, token); ! 66: strcat (trail, "\\"); ! 67: token = strtok (NULL, "\\/"); ! 68: if (token) ! 69: { /* get share name */ ! 70: strcat (trail, token); ! 71: strcat (trail, "\\"); ! 72: } ! 73: token = strtok (NULL, "\\/"); ! 74: } ! 75: ! 76: if (tokpath[1] == ':') ! 77: { /* drive letter */ ! 78: strcat (trail, tokpath); ! 79: strcat (trail, "\\"); ! 80: token = strtok (NULL, "\\/"); ! 81: } ! 82: ! 83: while (token != NULL) ! 84: { ! 85: int x; ! 86: strcat (trail, token); ! 87: x = _mkdir (trail); ! 88: strcat (trail, "\\"); ! 89: token = strtok (NULL, "\\/"); ! 90: } ! 91: ! 92: return _stat (path, &st); ! 93: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.