20 #if defined(_WIN32) && defined(__GLIBCXX__)
21 # include <ext/stdio_filebuf.h>
24 # include <sys/stat.h>
30 template<
class _CharT,
class _Traits = std::
char_traits<_CharT>>
31 class basic_ifstream :
public std::basic_istream<_CharT, _Traits> {
34 typedef _Traits traits_type;
35 typedef typename traits_type::int_type
int_type;
36 typedef typename traits_type::pos_type pos_type;
37 typedef typename traits_type::off_type off_type;
39 typedef typename __gnu_cxx::stdio_filebuf<char_type, traits_type>
44 explicit basic_ifstream(
const std::wstring&
path,
45 std::ios_base::openmode __mode = std::ios_base::in);
47 virtual ~basic_ifstream();
49 stdio_filebuf* rdbuf()
const;
52 std::ios_base::openmode __mode = std::ios_base::in);
56 void open_internal(
const std::wstring&
path, std::ios_base::openmode
mode);
61 template<
class _CharT,
class _Traits>
62 inline basic_ifstream<_CharT, _Traits>::basic_ifstream()
63 : std::basic_istream<
char_type, traits_type>(0)
69 template<
class _CharT,
class _Traits>
70 inline basic_ifstream<_CharT, _Traits>::basic_ifstream(
71 const std::wstring&
path, std::ios_base::openmode __mode)
72 : std::basic_istream<
char_type, traits_type>(0)
75 open_internal(path, __mode | std::ios_base::in);
78 template<
class _CharT,
class _Traits>
79 inline basic_ifstream<_CharT, _Traits>::~basic_ifstream()
86 ios_open_mode_to_oflag(std::ios_base::openmode
mode)
89 if (mode & std::ios_base::in) {
92 if (mode & std::ios_base::out) {
95 if (mode & std::ios_base::app) {
110 template<
class _CharT,
class _Traits>
112 basic_ifstream<_CharT, _Traits>::open_internal(
const std::wstring&
path,
113 std::ios_base::openmode mode)
117 this->setstate(std::ios_base::failbit);
121 int oflag = ios_open_mode_to_oflag(mode);
122 errno_t errcode = _wsopen_s(&fd, path.c_str(), oflag, _SH_DENYNO,
123 _S_IREAD | _S_IWRITE);
125 this->setstate(std::ios_base::failbit);
128 __sb_ =
new stdio_filebuf(fd, mode, 1);
130 this->setstate(std::ios_base::failbit);
140 assert(this->good() && !this->fail());
143 template<
class _CharT,
class _Traits>
144 inline typename basic_ifstream<_CharT, _Traits>::stdio_filebuf*
145 basic_ifstream<_CharT, _Traits>::rdbuf()
const
147 return const_cast<stdio_filebuf*
>(__sb_);
151 template<
class _CharT,
class _Traits>
153 basic_ifstream<_CharT, _Traits>::is_open()
const
155 return __sb_ && __sb_->is_open();
159 template<
class _CharT,
class _Traits>
162 std::ios_base::openmode __mode)
164 open_internal(path, __mode | std::ios_base::in);
167 template<
class _CharT,
class _Traits>
174 if (__sb_->close() == 0)
175 this->setstate(std::ios_base::failbit);
183 template<
class _CharT,
class _Traits = std::
char_traits<_CharT>>
184 class basic_ofstream :
public std::basic_ostream<_CharT, _Traits> {
187 typedef _Traits traits_type;
188 typedef typename traits_type::int_type
int_type;
189 typedef typename traits_type::pos_type pos_type;
190 typedef typename traits_type::off_type off_type;
192 typedef typename __gnu_cxx::stdio_filebuf<char_type, traits_type>
197 explicit basic_ofstream(
const std::wstring& path,
198 std::ios_base::openmode __mode = std::ios_base::out);
200 virtual ~basic_ofstream();
202 stdio_filebuf* rdbuf()
const;
203 bool is_open()
const;
204 void open(
const std::wstring& path,
205 std::ios_base::openmode __mode = std::ios_base::out);
209 void open_internal(
const std::wstring& path, std::ios_base::openmode mode);
211 stdio_filebuf* __sb_;
214 template<
class _CharT,
class _Traits>
215 inline basic_ofstream<_CharT, _Traits>::basic_ofstream()
216 : std::basic_ostream<
char_type, traits_type>(0)
222 template<
class _CharT,
class _Traits>
223 inline basic_ofstream<_CharT, _Traits>::basic_ofstream(
224 const std::wstring& path, std::ios_base::openmode __mode)
225 : std::basic_ostream<
char_type, traits_type>(0)
228 open_internal(path, __mode | std::ios_base::out);
231 template<
class _CharT,
class _Traits>
232 inline basic_ofstream<_CharT, _Traits>::~basic_ofstream()
238 template<
class _CharT,
class _Traits>
240 basic_ofstream<_CharT, _Traits>::open_internal(
const std::wstring& path,
241 std::ios_base::openmode mode)
245 this->setstate(std::ios_base::failbit);
249 int oflag = ios_open_mode_to_oflag(mode);
250 errno_t errcode = _wsopen_s(&fd, path.c_str(), oflag, _SH_DENYNO,
251 _S_IREAD | _S_IWRITE);
253 this->setstate(std::ios_base::failbit);
256 __sb_ =
new stdio_filebuf(fd, mode, 1);
258 this->setstate(std::ios_base::failbit);
268 assert(this->good() && !this->fail());
272 template<
class _CharT,
class _Traits>
273 inline typename basic_ofstream<_CharT, _Traits>::stdio_filebuf*
274 basic_ofstream<_CharT, _Traits>::rdbuf()
const
276 return const_cast<stdio_filebuf*
>(__sb_);
281 template<
class _CharT,
class _Traits>
283 basic_ofstream<_CharT, _Traits>::is_open()
const
285 return __sb_ && __sb_->is_open();
289 template<
class _CharT,
class _Traits>
292 std::ios_base::openmode __mode)
294 open_internal(path, __mode | std::ios_base::out);
297 template<
class _CharT,
class _Traits>
304 if (__sb_->close() == 0)
305 this->setstate(std::ios_base::failbit);
315 #endif // #if defined(_WIN32) && defined(__GLIBCXX__)
const GLuint GLenum const void * binary
GLsizei const GLchar *const * path
IMATH_HOSTDEVICE constexpr int trunc(T x) IMATH_NOEXCEPT
#define OIIO_NAMESPACE_END
#define OIIO_NAMESPACE_BEGIN