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
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
21 #include <OSD_Directory.ixx>
22 #include <OSD_WhoAmI.hxx>
23 #include <OSD_Protection.hxx>
25 #ifdef HAVE_SYS_TYPES_H
26 # include <sys/types.h>
29 #ifdef HAVE_SYS_STAT_H
30 # include <sys/stat.h>
33 #ifdef HAVE_SYS_PARAM_H
34 # include <sys/param.h> // For getwd()
49 const OSD_WhoAmI Iam = OSD_WDirectory;
52 OSD_Directory::OSD_Directory():OSD_FileNode() {
55 OSD_Directory::OSD_Directory(const OSD_Path& Name):OSD_FileNode(Name){
58 // Create physically a directory
60 void OSD_Directory::Build(const OSD_Protection& Protect){
62 Standard_Integer internal_prot;
63 TCollection_AsciiString aBuffer;
65 internal_prot = Protect.Internal();
66 myPath.SystemName(aBuffer);
68 status = mkdir (aBuffer.ToCString(), (mode_t)internal_prot);
70 if (errno != EEXIST) {
71 Standard_PCharacter err_message;
73 err_message = new Standard_Character [255];
75 "OSD_Directory::Build Directory \"%s\"",
78 myError.SetValue(errno, Iam, err_message);
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);
90 internal_prot = Protect.Internal();
93 mkdir (name, (mode_t)internal_prot);
94 unlink(name);//Destroys link but directory still exists while
95 //current process lives.
97 aDirectoryToReturn.SetPath ( aString );
98 return aDirectoryToReturn;
104 //------------------------------------------------------------------------
105 //------------------- WNT Sources of OSD_Diretory -----------------------
106 //------------------------------------------------------------------------
108 #include <OSD_Directory.hxx>
109 #include <OSD_Protection.hxx>
110 #include <Standard_ProgramError.hxx>
112 #include <OSD_WNT_1.hxx>
121 # define tctmpnam _wtmpnam
123 # define tctmpnam tmpnam
126 void _osd_wnt_set_error ( OSD_Error&, OSD_WhoAmI, ... );
128 OSD_Directory :: OSD_Directory () {
130 } // end constructor ( 1 )
132 OSD_Directory :: OSD_Directory ( const OSD_Path& Name ) :
133 OSD_FileNode ( Name ) {
135 } // end constructor ( 2 )
137 void OSD_Directory :: Build (const OSD_Protection& Protect ) {
139 TCollection_AsciiString dirName;
141 myPath.SystemName ( dirName );
143 if ( dirName.IsEmpty () )
145 Standard_ProgramError :: Raise (
146 TEXT( "OSD_Directory :: Build (): incorrect call - no directory name" )
149 if ( Exists () || CreateDirectory ( dirName.ToCString (), NULL ) )
151 SetProtection ( Protect );
155 _osd_wnt_set_error ( myError, OSD_WDirectory );
157 } // end OSD_Directory :: Build
159 OSD_Directory OSD_Directory :: BuildTemporary () {
161 OSD_Directory retVal;
163 OSD_Path dirPath ( tctmpnam ( NULL ) );
165 retVal.SetPath ( dirPath );
166 retVal.Build ( prt );
170 } // end OSD_Directory :: BuildTemporary