File indexing completed on 2025-01-18 10:04:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef _OSD_OpenFile_HeaderFile
0018 #define _OSD_OpenFile_HeaderFile
0019
0020 #include <Standard_Macro.hxx>
0021
0022 #if defined(__cplusplus)
0023
0024 #include <fstream>
0025 #include <TCollection_ExtendedString.hxx>
0026 #include <NCollection_UtfString.hxx>
0027
0028 #if defined(_WIN32) && defined(__GLIBCXX__)
0029 #include <ext/stdio_filebuf.h> // __gnu_cxx::stdio_filebuf
0030 #endif
0031
0032
0033
0034
0035
0036 Standard_EXPORT FILE* OSD_OpenFile (const TCollection_ExtendedString& theName,
0037 const char* theMode);
0038
0039
0040
0041
0042 Standard_EXPORT Standard_Time OSD_FileStatCTime (const char* theName);
0043
0044
0045
0046
0047
0048 Standard_EXPORT int OSD_OpenFileDescriptor (const TCollection_ExtendedString& theName,
0049 ::std::ios_base::openmode theMode);
0050
0051
0052
0053
0054
0055
0056 inline bool OSD_OpenStream (::std::filebuf& theFileBuf,
0057 const TCollection_ExtendedString& theName,
0058 const std::ios_base::openmode theMode)
0059 {
0060 #if defined(_WIN32)
0061 #if defined(__GLIBCXX__)
0062
0063 if (theFileBuf.is_open())
0064 return false;
0065
0066
0067
0068
0069 const int aFileDesc = OSD_OpenFileDescriptor (theName.ToWideString(), theMode);
0070 __gnu_cxx::stdio_filebuf<char> aGccBuf (aFileDesc, theMode);
0071 if (aGccBuf.is_open())
0072 {
0073 theFileBuf.swap (aGccBuf);
0074 return true;
0075 }
0076 return false;
0077 #else
0078 return theFileBuf.open (theName.ToWideString(), theMode) != 0;
0079 #endif
0080 #else
0081
0082 NCollection_Utf8String aString (theName.ToExtString());
0083 return theFileBuf.open (aString.ToCString(), theMode) != 0;
0084 #endif
0085 }
0086
0087
0088
0089
0090
0091 template <typename T>
0092 inline void OSD_OpenStream (T& theStream,
0093 const TCollection_ExtendedString& theName,
0094 const std::ios_base::openmode theMode)
0095 {
0096 #if defined(_WIN32)
0097 #if defined(__GLIBCXX__)
0098
0099
0100
0101 if (! OSD_OpenStream (*theStream.rdbuf(), theName, theMode))
0102 {
0103 theStream.setstate (std::ios_base::failbit);
0104 }
0105 else
0106 {
0107 theStream.clear();
0108 }
0109 #else
0110 theStream.open (theName.ToWideString(), theMode);
0111 #endif
0112 #else
0113
0114 NCollection_Utf8String aString (theName.ToExtString());
0115 theStream.open (aString.ToCString(), theMode);
0116 #endif
0117 }
0118
0119
0120
0121
0122
0123 template <typename T>
0124 inline void OSD_OpenStream (T& theStream,
0125 const char* theName,
0126 const std::ios_base::openmode theMode)
0127 {
0128 #if defined(_WIN32)
0129
0130 const TCollection_ExtendedString aFileNameW (theName, Standard_True);
0131 OSD_OpenStream (theStream, aFileNameW, theMode);
0132 #else
0133 theStream.open (theName, theMode);
0134 #endif
0135 }
0136
0137 extern "C" {
0138 #endif
0139
0140
0141
0142
0143
0144 Standard_EXPORT FILE* OSD_OpenFile (const char* theName, const char* theMode);
0145
0146 #if defined(__cplusplus)
0147 }
0148 #endif
0149
0150 #endif