1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License 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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
17 #include <OSD_Directory.ixx>
18 #include <OSD_WhoAmI.hxx>
19 #include <OSD_Protection.hxx>
26 const OSD_WhoAmI Iam = OSD_WDirectory;
29 OSD_Directory::OSD_Directory():OSD_FileNode() {
32 OSD_Directory::OSD_Directory(const OSD_Path& Name):OSD_FileNode(Name){
35 // Create physically a directory
37 void OSD_Directory::Build(const OSD_Protection& Protect){
39 Standard_Integer internal_prot;
40 TCollection_AsciiString aBuffer;
42 internal_prot = Protect.Internal();
43 myPath.SystemName(aBuffer);
45 status = mkdir (aBuffer.ToCString(), (mode_t)internal_prot);
47 if (errno != EEXIST) {
48 Standard_PCharacter err_message;
50 err_message = new Standard_Character [255];
52 "OSD_Directory::Build Directory \"%s\"",
55 myError.SetValue(errno, Iam, err_message);
60 OSD_Directory OSD_Directory::BuildTemporary(){
61 OSD_Protection Protect;
62 OSD_Directory aDirectoryToReturn;
63 Standard_Integer internal_prot;
64 Standard_CString name = tmpnam(NULL);
65 TCollection_AsciiString aString (name);
67 internal_prot = Protect.Internal();
70 mkdir (name, (mode_t)internal_prot);
71 unlink(name);//Destroys link but directory still exists while
72 //current process lives.
74 aDirectoryToReturn.SetPath ( aString );
75 return aDirectoryToReturn;
81 //------------------------------------------------------------------------
82 //------------------- WNT Sources of OSD_Diretory -----------------------
83 //------------------------------------------------------------------------
85 #include <OSD_Directory.hxx>
86 #include <OSD_Protection.hxx>
87 #include <Standard_ProgramError.hxx>
88 #include <TCollection_ExtendedString.hxx>
90 #include <OSD_WNT_1.hxx>
99 # define tctmpnam _wtmpnam
101 # define tctmpnam tmpnam
104 void _osd_wnt_set_error ( OSD_Error&, OSD_WhoAmI, ... );
106 OSD_Directory :: OSD_Directory () {
108 } // end constructor ( 1 )
110 OSD_Directory :: OSD_Directory ( const OSD_Path& Name ) :
111 OSD_FileNode ( Name ) {
113 } // end constructor ( 2 )
115 void OSD_Directory :: Build (const OSD_Protection& Protect ) {
117 TCollection_AsciiString dirName;
119 myPath.SystemName ( dirName );
121 if ( dirName.IsEmpty () )
123 Standard_ProgramError :: Raise (
124 TEXT( "OSD_Directory :: Build (): incorrect call - no directory name" )
126 TCollection_ExtendedString dirNameW(dirName);
127 if ( Exists () || CreateDirectoryW ( (const wchar_t*) dirNameW.ToExtString (), NULL ) )
129 SetProtection ( Protect );
133 _osd_wnt_set_error ( myError, OSD_WDirectory );
135 } // end OSD_Directory :: Build
137 OSD_Directory OSD_Directory :: BuildTemporary () {
139 OSD_Directory retVal;
141 OSD_Path dirPath ( tctmpnam ( NULL ) );
143 retVal.SetPath ( dirPath );
144 retVal.Build ( prt );
148 } // end OSD_Directory :: BuildTemporary