]> git.mxchange.org Git - flightgear.git/blob - Makedir/makedir.cxx
Removed forced -g compile flag.
[flightgear.git] / Makedir / makedir.cxx
1
2 #ifdef HAVE_CONFIG_H
3 #include <config.h>
4 #endif
5
6 #ifdef HAVE_STDLIB_H
7 #include <stdlib.h>
8 #endif
9
10 #include <stdio.h>
11 #include <sys/stat.h> // stat()
12 #include <unistd.h>   // stat()
13
14 #include <string>
15
16 #include <Bucket/bucketutils.h>
17
18
19
20 #ifdef WIN32
21 #ifndef TRUE
22  #define FALSE 0
23  #define TRUE 1
24 #endif
25
26 char* PathDivider()
27 {
28         return "\\";
29 } // PathDivider
30
31 void ReplaceDivider( char* path )
32 {
33         char    div = PathDivider()[0];
34         int             i;
35
36         if ( ! path )
37                 return;
38         if ( div == '/' )
39                 return;
40
41         for ( i = 0; path[i]; i++ )
42                 if ( path[i] == '/' )
43                         path[i] = div;
44
45 } // ReplaceDivider
46
47 int     Exists( char* path )
48 {
49     struct stat statbuff;
50
51         ReplaceDivider( path );
52         if ( path[strlen( path ) - 1] == ':' )
53                 return TRUE;
54         if ( _stat( path, &statbuff ) != 0 )
55                 return FALSE;
56         return TRUE;
57 } // Exists
58
59
60 void CreateDir( char* path )
61 {
62         if ( ! path  ||  ! strlen( path ) )
63                 return;
64         ReplaceDivider( path );
65                                                                 // see if the parent exists yet
66         int             i;      // looping index
67         string  parent; // path to parent
68
69         parent =  path;
70         for ( i = strlen( parent.c_str() )-1; i >= 0; i-- )
71                 if ( parent[i] == PathDivider()[0] )
72                 {
73                         parent[i] = '\0';
74                         break;
75                 }
76         
77         if ( ! Exists( parent.c_str() ) )
78         {
79                 CreateDir( parent.c_str() );
80         }
81
82         if ( ! Exists( path ) )
83         {
84                 if (mkdir(path, S_IRWXU) != 0 )
85                 {
86                         cout << "Could not create directory " << path << endl;
87                 }else{
88                         cout << "CreateDir: " << path << endl;
89                 }
90         }
91         
92 } // CreateDir
93
94
95 int main(int argc, char **argv)
96 {
97         string root;
98
99         if(argc != 2)
100         {
101                 cout << "Makedir failed needs one argument\n";
102                 return(10);
103         }
104         root = argv[1];
105         
106         CreateDir(root.c_str());
107         
108         return(0);
109 }
110 #else
111
112 int main(int argc, char **argv)
113 {
114         cout << "This program is intended to work with windoze\n";
115         cout << "Other platforms can use mkdir\n";
116 }
117
118 #endif // WIN32
119