b311480e |
1 | // Copyright (c) 1998-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
973c2be1 |
6 | // This library is free software; you can redistribute it and / or modify it |
7 | // under the terms of the GNU Lesser General Public version 2.1 as published |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
7fd59977 |
14 | |
15 | #ifdef HAVE_CONFIG_H |
16 | # include <config.h> |
17 | #endif |
18 | |
19 | #ifndef WNT |
20 | |
21 | #include <OSD_Directory.ixx> |
22 | #include <OSD_WhoAmI.hxx> |
23 | #include <OSD_Protection.hxx> |
24 | |
25 | #ifdef HAVE_SYS_TYPES_H |
26 | # include <sys/types.h> |
27 | #endif |
28 | |
29 | #ifdef HAVE_SYS_STAT_H |
30 | # include <sys/stat.h> |
31 | #endif |
32 | |
33 | #ifdef HAVE_SYS_PARAM_H |
34 | # include <sys/param.h> // For getwd() |
35 | #endif |
36 | |
37 | #include <errno.h> |
38 | |
39 | #ifdef HAVE_UNISTD_H |
40 | # include <unistd.h> |
41 | #endif |
42 | |
43 | #include <stdio.h> |
44 | |
45 | #ifdef HAVE_OSFCN_H |
46 | # include <osfcn.h> |
47 | #endif |
48 | |
49 | const OSD_WhoAmI Iam = OSD_WDirectory; |
50 | |
51 | |
52 | OSD_Directory::OSD_Directory():OSD_FileNode() { |
53 | } |
54 | |
55 | OSD_Directory::OSD_Directory(const OSD_Path& Name):OSD_FileNode(Name){ |
56 | } |
57 | |
58 | // Create physically a directory |
59 | |
60 | void OSD_Directory::Build(const OSD_Protection& Protect){ |
61 | int status; |
62 | Standard_Integer internal_prot; |
63 | TCollection_AsciiString aBuffer; |
64 | |
65 | internal_prot = Protect.Internal(); |
66 | myPath.SystemName(aBuffer); |
67 | umask ( 0 ); |
68 | status = mkdir (aBuffer.ToCString(), (mode_t)internal_prot); |
69 | if (status == -1) |
70 | if (errno != EEXIST) { |
71 | Standard_PCharacter err_message; |
72 | |
73 | err_message = new Standard_Character [255]; |
74 | sprintf (err_message, |
75 | "OSD_Directory::Build Directory \"%s\"", |
76 | aBuffer.ToCString()); |
77 | |
78 | myError.SetValue(errno, Iam, err_message); |
79 | delete err_message; |
80 | } |
81 | } |
82 | |
83 | OSD_Directory OSD_Directory::BuildTemporary(){ |
84 | OSD_Protection Protect; |
85 | OSD_Directory aDirectoryToReturn; |
86 | Standard_Integer internal_prot; |
87 | Standard_CString name = tmpnam(NULL); |
88 | TCollection_AsciiString aString (name); |
89 | |
90 | internal_prot = Protect.Internal(); |
91 | |
92 | umask ( 0 ); |
93 | mkdir (name, (mode_t)internal_prot); |
94 | unlink(name);//Destroys link but directory still exists while |
95 | //current process lives. |
96 | |
97 | aDirectoryToReturn.SetPath ( aString ); |
98 | return aDirectoryToReturn; |
99 | |
100 | } |
101 | |
102 | #else |
103 | |
104 | //------------------------------------------------------------------------ |
105 | //------------------- WNT Sources of OSD_Diretory ----------------------- |
106 | //------------------------------------------------------------------------ |
107 | |
108 | #include <OSD_Directory.hxx> |
109 | #include <OSD_Protection.hxx> |
110 | #include <Standard_ProgramError.hxx> |
111 | |
112 | #include <OSD_WNT_1.hxx> |
113 | |
114 | #include <stdio.h> |
115 | |
116 | #ifndef _INC_TCHAR |
117 | # include <tchar.h> |
118 | #endif // _INC_TCHAR |
119 | |
120 | #ifdef _UNICODE |
121 | # define tctmpnam _wtmpnam |
122 | #else |
123 | # define tctmpnam tmpnam |
124 | #endif // _UNICODE |
125 | |
126 | void _osd_wnt_set_error ( OSD_Error&, OSD_WhoAmI, ... ); |
127 | |
128 | OSD_Directory :: OSD_Directory () { |
129 | |
130 | } // end constructor ( 1 ) |
131 | |
132 | OSD_Directory :: OSD_Directory ( const OSD_Path& Name ) : |
133 | OSD_FileNode ( Name ) { |
134 | |
135 | } // end constructor ( 2 ) |
136 | |
137 | void OSD_Directory :: Build (const OSD_Protection& Protect ) { |
138 | |
139 | TCollection_AsciiString dirName; |
140 | |
141 | myPath.SystemName ( dirName ); |
142 | |
143 | if ( dirName.IsEmpty () ) |
144 | |
145 | Standard_ProgramError :: Raise ( |
146 | TEXT( "OSD_Directory :: Build (): incorrect call - no directory name" ) |
147 | ); |
148 | |
149 | if ( Exists () || CreateDirectory ( dirName.ToCString (), NULL ) ) |
150 | |
151 | SetProtection ( Protect ); |
152 | |
153 | else |
154 | |
155 | _osd_wnt_set_error ( myError, OSD_WDirectory ); |
156 | |
157 | } // end OSD_Directory :: Build |
158 | |
159 | OSD_Directory OSD_Directory :: BuildTemporary () { |
160 | |
161 | OSD_Directory retVal; |
162 | OSD_Protection prt; |
163 | OSD_Path dirPath ( tctmpnam ( NULL ) ); |
164 | |
165 | retVal.SetPath ( dirPath ); |
166 | retVal.Build ( prt ); |
167 | |
168 | return retVal; |
169 | |
170 | } // end OSD_Directory :: BuildTemporary |
171 | |
172 | #endif |