Annotation of truecrypt/setup/dir.c, revision 1.1.1.4

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.