1 // Copyright (c) 2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <OSD_OpenFile.hxx>
15 #include <TCollection_ExtendedString.hxx>
16 #include <NCollection_UtfString.hxx>
18 // ==============================================
19 // function : OSD_OpenFile
20 // purpose : Opens file
21 // ==============================================
22 FILE* OSD_OpenFile(const char* theName,
27 // file name is treated as UTF-8 string and converted to UTF-16 one
28 const TCollection_ExtendedString aFileNameW (theName, Standard_True);
29 const TCollection_ExtendedString aFileModeW (theMode, Standard_True);
30 aFile = ::_wfopen ((const wchar_t* )aFileNameW.ToExtString(),
31 (const wchar_t* )aFileModeW.ToExtString());
33 aFile = ::fopen (theName, theMode);
38 // ==============================================
39 // function : OSD_OpenFile
40 // purpose : Opens file
41 // ==============================================
42 FILE* OSD_OpenFile(const TCollection_ExtendedString& theName,
47 const TCollection_ExtendedString aFileModeW (theMode, Standard_True);
48 aFile = ::_wfopen ((const wchar_t* )theName.ToExtString(),
49 (const wchar_t* )aFileModeW.ToExtString());
51 // conversion in UTF-8 for linux
52 NCollection_Utf8String aString((const Standard_Utf16Char*)theName.ToExtString());
53 aFile = ::fopen (aString.ToCString(),theMode);
58 // ==============================================
59 // function : OSD_OpenFileBuf
60 // purpose : Opens file buffer
61 // ==============================================
62 void OSD_OpenFileBuf(std::filebuf& theBuff,
64 const std::ios_base::openmode theMode)
67 // file name is treated as UTF-8 string and converted to UTF-16 one
68 const TCollection_ExtendedString aFileNameW (theName, Standard_True);
69 theBuff.open ((const wchar_t* )aFileNameW.ToExtString(), theMode);
71 theBuff.open (theName, theMode);
75 // ==============================================
76 // function : OSD_OpenFileBuf
77 // purpose : Opens file buffer
78 // ==============================================
79 void OSD_OpenFileBuf(std::filebuf& theBuff,
80 const TCollection_ExtendedString& theName,
81 const std::ios_base::openmode theMode)
84 theBuff.open ((const wchar_t* )theName.ToExtString(), theMode);
86 // conversion in UTF-8 for linux
87 NCollection_Utf8String aString((const Standard_Utf16Char*)theName.ToExtString());
88 theBuff.open (aString.ToCString(),theMode);
92 // ==============================================
93 // function : OSD_OpenStream
94 // purpose : Opens file stream
95 // ==============================================
96 void OSD_OpenStream(std::ofstream& theStream,
98 const std::ios_base::openmode theMode)
101 // file name is treated as UTF-8 string and converted to UTF-16 one
102 const TCollection_ExtendedString aFileNameW (theName, Standard_True);
103 theStream.open ((const wchar_t* )aFileNameW.ToExtString(), theMode);
105 theStream.open (theName, theMode);
109 // ==============================================
110 // function : OSD_OpenStream
111 // purpose : Opens file stream
112 // ==============================================
113 void OSD_OpenStream(std::ofstream& theStream,
114 const TCollection_ExtendedString& theName,
115 const std::ios_base::openmode theMode)
118 theStream.open ((const wchar_t* )theName.ToExtString(), theMode);
120 // conversion in UTF-8 for linux
121 NCollection_Utf8String aString((const Standard_Utf16Char*)theName.ToExtString());
122 theStream.open (aString.ToCString(),theMode);