• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2 // (C) Copyright 2003-2007 Jonathan Turkanis
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
5 
6 // See http://www.boost.org/libs/iostreams for documentation.
7 
8 // Define BOOST_IOSTREAMS_SOURCE so that <boost/iostreams/detail/config.hpp>
9 // knows that we are building the library (possibly exporting code), rather
10 // than using it (possibly importing code).
11 #define BOOST_IOSTREAMS_SOURCE
12 
13 #include <cassert>
14 #include <cerrno>
15 #include <cstdio>                                 // SEEK_SET, etc.
16 #include <boost/config.hpp>                       // BOOST_JOIN
17 #include <boost/iostreams/detail/error.hpp>
18 #include <boost/iostreams/detail/config/dyn_link.hpp>
19 #include <boost/iostreams/detail/config/rtl.hpp>  // BOOST_IOSTREAMS_FD_XXX
20 #include <boost/iostreams/detail/config/windows_posix.hpp>
21 #include <boost/iostreams/detail/system_failure.hpp>
22 #include <boost/iostreams/detail/ios.hpp>         // openmodes, failure.
23 #include <boost/iostreams/device/file_descriptor.hpp>
24 #include <boost/integer_traits.hpp>
25 #include <boost/throw_exception.hpp>
26 
27 // Must come last.
28 #include <boost/iostreams/detail/config/disable_warnings.hpp>
29 
30     // OS-specific headers for low-level i/o.
31 
32 #include <fcntl.h>       // file opening flags.
33 #include <sys/stat.h>    // file access permissions.
34 #ifdef BOOST_IOSTREAMS_WINDOWS
35 # include <io.h>         // low-level file i/o.
36 # define WINDOWS_LEAN_AND_MEAN
37 # include <windows.h>
38 # ifndef INVALID_SET_FILE_POINTER
39 #  define INVALID_SET_FILE_POINTER ((DWORD)-1)
40 # endif
41 #else
42 # include <sys/types.h>  // mode_t.
43 # include <unistd.h>     // low-level file i/o.
44 #endif
45 
46 namespace boost { namespace iostreams {
47 
48 //------------------Definition of file_descriptor_impl------------------------//
49 
50 namespace detail {
51 
52 // Contains the platform dependant implementation
53 struct file_descriptor_impl {
54     // Note: These need to match file_desciptor_flags
55     enum flags {
56         never_close = 0,
57         close_on_exit = 1,
58         close_on_close = 2,
59         close_always = 3
60     };
61 
62     file_descriptor_impl();
63     ~file_descriptor_impl();
64     void open(file_handle fd, flags);
65 #ifdef BOOST_IOSTREAMS_WINDOWS
66     void open(int fd, flags);
67 #endif
68     void open(const detail::path&, BOOST_IOS::openmode);
69     bool is_open() const;
70     void close();
71     void close_impl(bool close_flag, bool throw_);
72     std::streamsize read(char* s, std::streamsize n);
73     std::streamsize write(const char* s, std::streamsize n);
74     std::streampos seek(stream_offset off, BOOST_IOS::seekdir way);
75     static file_handle invalid_handle();
76     file_handle  handle_;
77     int          flags_;
78 };
79 
80 //------------------Implementation of file_descriptor_impl--------------------//
81 
file_descriptor_impl()82 file_descriptor_impl::file_descriptor_impl()
83     : handle_(invalid_handle()), flags_(0)
84     { }
85 
~file_descriptor_impl()86 file_descriptor_impl::~file_descriptor_impl()
87 {
88     close_impl(flags_ & close_on_exit, false);
89 }
90 
open(file_handle fd,flags f)91 void file_descriptor_impl::open(file_handle fd, flags f)
92 {
93     // Using 'close' to close the existing handle so that it will throw an
94     // exception if it fails.
95     //
96     // Only closing after assigning the new handle, so that the class will
97     // take ownership of the handle regardless of whether close throws.
98 
99     file_descriptor_impl tmp;
100     tmp.handle_ = handle_;
101     tmp.flags_ = flags_ & close_on_exit ? close_on_close : never_close;
102 
103     handle_ = fd;
104     flags_ = f;
105 
106     tmp.close();
107 }
108 
109 #ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------//
110 
open(int fd,flags f)111 void file_descriptor_impl::open(int fd, flags f)
112 { open(reinterpret_cast<file_handle>(_get_osfhandle(fd)), f); }
113 
114 #endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------//
115 
open(const detail::path & p,BOOST_IOS::openmode mode)116 void file_descriptor_impl::open(const detail::path& p, BOOST_IOS::openmode mode)
117 {
118     close_impl(flags_ & close_on_exit, true);
119 
120 #ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------//
121     DWORD dwDesiredAccess;
122     DWORD dwCreationDisposition;
123 
124     if ( !(mode & (BOOST_IOS::in | BOOST_IOS::out | BOOST_IOS::app)) ||
125             ((mode & BOOST_IOS::trunc) &&
126             ((mode & BOOST_IOS::app) || !(mode & BOOST_IOS::out))) ) {
127         boost::throw_exception(BOOST_IOSTREAMS_FAILURE("bad open mode"));
128     }
129     else if ( mode & BOOST_IOS::in ) {
130         if ( mode & BOOST_IOS::app )
131             {
132             dwCreationDisposition = OPEN_ALWAYS;
133             dwDesiredAccess =
134                 GENERIC_READ |
135                 FILE_APPEND_DATA |
136                 FILE_WRITE_ATTRIBUTES |
137                 FILE_WRITE_EA |
138                 STANDARD_RIGHTS_WRITE |
139                 SYNCHRONIZE;
140             }
141         else if ( mode & BOOST_IOS::trunc )
142             {
143             dwCreationDisposition = CREATE_ALWAYS;
144             dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
145             }
146         else if ( mode & BOOST_IOS::out )
147             {
148             dwCreationDisposition = OPEN_EXISTING;
149             dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
150             }
151         else
152             {
153             dwCreationDisposition = OPEN_EXISTING;
154             dwDesiredAccess = GENERIC_READ;
155             }
156     }
157     else {
158         if ( mode & BOOST_IOS::app )
159             {
160             dwCreationDisposition = OPEN_ALWAYS;
161             dwDesiredAccess =
162                 FILE_APPEND_DATA |
163                 FILE_WRITE_ATTRIBUTES |
164                 FILE_WRITE_EA |
165                 STANDARD_RIGHTS_WRITE |
166                 SYNCHRONIZE;
167             }
168         else
169             {
170             dwCreationDisposition = CREATE_ALWAYS;
171             dwDesiredAccess = GENERIC_WRITE;
172             }
173     }
174 
175 
176     HANDLE handle = p.is_wide() ?
177         ::CreateFileW( p.c_wstr(),
178                        dwDesiredAccess,
179                        FILE_SHARE_READ | FILE_SHARE_WRITE,
180                        NULL,                   // lpSecurityAttributes
181                        dwCreationDisposition,
182                        FILE_ATTRIBUTE_NORMAL,
183                        NULL ) :                // hTemplateFile
184         ::CreateFileA( p.c_str(),
185                        dwDesiredAccess,
186                        FILE_SHARE_READ | FILE_SHARE_WRITE,
187                        NULL,                   // lpSecurityAttributes
188                        dwCreationDisposition,
189                        FILE_ATTRIBUTE_NORMAL,
190                        NULL );                 // hTemplateFile
191     if (handle != INVALID_HANDLE_VALUE) {
192         handle_ = handle;
193         flags_ = close_always;
194     } else {
195         flags_ = 0;
196         throw_system_failure("failed opening file");
197     }
198 #else // #ifdef BOOST_IOSTREAMS_WINDOWS //------------------------------------//
199 
200         // Calculate oflag argument to open.
201 
202     int oflag = 0;
203     if ( !(mode & (BOOST_IOS::in | BOOST_IOS::out | BOOST_IOS::app)) ||
204             ((mode & BOOST_IOS::trunc) &&
205             ((mode & BOOST_IOS::app) || !(mode & BOOST_IOS::out))) ) {
206         boost::throw_exception(BOOST_IOSTREAMS_FAILURE("bad open mode"));
207     }
208     else if ( mode & BOOST_IOS::in ) {
209         if ( mode & BOOST_IOS::app )
210             oflag |= O_CREAT | O_APPEND | O_RDWR;
211         else if ( mode & BOOST_IOS::trunc )
212             oflag |= O_CREAT | O_TRUNC | O_RDWR;
213         else if ( mode & BOOST_IOS::out )
214             oflag |= O_RDWR;
215         else
216             oflag |= O_RDONLY;
217     }
218     else {
219         if ( mode & BOOST_IOS::app )
220             oflag |= O_CREAT | O_APPEND | O_WRONLY;
221         else
222             oflag |= O_CREAT | O_TRUNC | O_WRONLY;
223     }
224     #ifdef _LARGEFILE64_SOURCE
225         oflag |= O_LARGEFILE;
226     #endif
227 
228         // Calculate pmode argument to open.
229 
230     mode_t pmode = S_IRUSR | S_IWUSR |
231                    S_IRGRP | S_IWGRP |
232                    S_IROTH | S_IWOTH;
233 
234         // Open file.
235 
236     int fd = BOOST_IOSTREAMS_FD_OPEN(p.c_str(), oflag, pmode);
237     if (fd == -1) {
238         boost::throw_exception(system_failure("failed opening file"));
239     } else {
240         if ( mode & BOOST_IOS::ate ) {
241             if (BOOST_IOSTREAMS_FD_SEEK(fd, 0, SEEK_END) == -1) {
242                 BOOST_IOSTREAMS_FD_CLOSE(fd);
243                 boost::throw_exception(system_failure("failed opening file"));
244             }
245         }
246         handle_ = fd;
247         flags_ = close_always;
248     }
249 #endif // #ifndef BOOST_IOSTREAMS_WINDOWS //----------------------------------//
250 }
251 
is_open() const252 bool file_descriptor_impl::is_open() const
253 { return handle_ != invalid_handle(); }
254 
close()255 void file_descriptor_impl::close()
256 {
257     close_impl((flags_ & close_on_close) != 0, true);
258 }
259 
close_impl(bool close_flag,bool throw_)260 void file_descriptor_impl::close_impl(bool close_flag, bool throw_) {
261     if (handle_ != invalid_handle()) {
262         if (close_flag) {
263             bool success =
264                 #ifdef BOOST_IOSTREAMS_WINDOWS
265                     ::CloseHandle(handle_) == 1;
266                 #else
267                     BOOST_IOSTREAMS_FD_CLOSE(handle_) != -1;
268                 #endif
269             if (!success && throw_)
270                 throw_system_failure("failed closing file");
271         }
272         handle_ = invalid_handle();
273         flags_ = 0;
274     }
275 }
276 
read(char * s,std::streamsize n)277 std::streamsize file_descriptor_impl::read(char* s, std::streamsize n)
278 {
279 #ifdef BOOST_IOSTREAMS_WINDOWS
280     DWORD result;
281     if (!::ReadFile(handle_, s, static_cast<DWORD>(n), &result, NULL))
282     {
283         // report EOF if the write-side of a pipe has been closed
284         if (GetLastError() == ERROR_BROKEN_PIPE)
285         {
286             result = 0;
287         }
288         else
289             throw_system_failure("failed reading");
290     }
291     return result == 0 ? -1 : static_cast<std::streamsize>(result);
292 #else // #ifdef BOOST_IOSTREAMS_WINDOWS
293     errno = 0;
294     std::streamsize result = BOOST_IOSTREAMS_FD_READ(handle_, s, n);
295     if (errno != 0)
296         throw_system_failure("failed reading");
297     return result == 0 ? -1 : result;
298 #endif // #ifdef BOOST_IOSTREAMS_WINDOWS
299 }
300 
write(const char * s,std::streamsize n)301 std::streamsize file_descriptor_impl::write(const char* s, std::streamsize n)
302 {
303 #ifdef BOOST_IOSTREAMS_WINDOWS
304     DWORD ignore;
305     if (!::WriteFile(handle_, s, static_cast<DWORD>(n), &ignore, NULL))
306         throw_system_failure("failed writing");
307     return n;
308 #else // #ifdef BOOST_IOSTREAMS_WINDOWS
309     int amt = BOOST_IOSTREAMS_FD_WRITE(handle_, s, n);
310     if (amt < n) // Handles blocking fd's only.
311         throw_system_failure("failed writing");
312     return n;
313 #endif // #ifdef BOOST_IOSTREAMS_WINDOWS
314 }
315 
seek(stream_offset off,BOOST_IOS::seekdir way)316 std::streampos file_descriptor_impl::seek
317     (stream_offset off, BOOST_IOS::seekdir way)
318 {
319 #ifdef BOOST_IOSTREAMS_WINDOWS
320     LONG lDistanceToMove = static_cast<LONG>(off & 0xffffffff);
321     LONG lDistanceToMoveHigh = static_cast<LONG>(off >> 32);
322     DWORD dwResultLow =
323         ::SetFilePointer( handle_,
324                           lDistanceToMove,
325                           &lDistanceToMoveHigh,
326                           way == BOOST_IOS::beg ?
327                               FILE_BEGIN :
328                               way == BOOST_IOS::cur ?
329                                 FILE_CURRENT :
330                                 FILE_END );
331     if ( dwResultLow == INVALID_SET_FILE_POINTER &&
332          ::GetLastError() != NO_ERROR )
333     {
334         boost::throw_exception(system_failure("failed seeking"));
335     } else {
336        return offset_to_position(
337                   (stream_offset(lDistanceToMoveHigh) << 32) + dwResultLow
338               );
339     }
340 #else // #ifdef BOOST_IOSTREAMS_WINDOWS
341     if ( off > integer_traits<BOOST_IOSTREAMS_FD_OFFSET>::const_max ||
342          off < integer_traits<BOOST_IOSTREAMS_FD_OFFSET>::const_min )
343     {
344         boost::throw_exception(BOOST_IOSTREAMS_FAILURE("bad offset"));
345     }
346     stream_offset result =
347         BOOST_IOSTREAMS_FD_SEEK(
348             handle_,
349             static_cast<BOOST_IOSTREAMS_FD_OFFSET>(off),
350             ( way == BOOST_IOS::beg ?
351                   SEEK_SET :
352                   way == BOOST_IOS::cur ?
353                       SEEK_CUR :
354                       SEEK_END )
355         );
356     if (result == -1)
357         boost::throw_exception(system_failure("failed seeking"));
358     return offset_to_position(result);
359 #endif // #ifdef BOOST_IOSTREAMS_WINDOWS
360 }
361 
362 // Returns the value stored in a file_handle variable when no file is open
invalid_handle()363 file_handle file_descriptor_impl::invalid_handle()
364 {
365 #ifdef BOOST_IOSTREAMS_WINDOWS
366     return INVALID_HANDLE_VALUE;
367 #else
368     return -1;
369 #endif
370 }
371 
372 } // End namespace detail.
373 
374 //------------------Implementation of file_descriptor-------------------------//
375 
file_descriptor()376 file_descriptor::file_descriptor() : pimpl_(new impl_type) { }
377 
file_descriptor(handle_type fd,file_descriptor_flags f)378 file_descriptor::file_descriptor(handle_type fd, file_descriptor_flags f)
379     : pimpl_(new impl_type)
380 { open(fd, f); }
381 
382 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
file_descriptor(handle_type fd,bool close_on_exit)383 file_descriptor::file_descriptor(handle_type fd, bool close_on_exit)
384     : pimpl_(new impl_type)
385 { open(fd, close_on_exit); }
386 #endif
387 
388 #ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------//
389 
file_descriptor(int fd,file_descriptor_flags f)390 file_descriptor::file_descriptor(int fd, file_descriptor_flags f)
391     : pimpl_(new impl_type)
392 { open(fd, f); }
393 
394 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
file_descriptor(int fd,bool close_on_exit)395 file_descriptor::file_descriptor(int fd, bool close_on_exit)
396     : pimpl_(new impl_type)
397 { open(fd, close_on_exit); }
398 #endif
399 
400 #endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------//
401 
file_descriptor(const std::string & path,BOOST_IOS::openmode mode)402 file_descriptor::file_descriptor( const std::string& path,
403                                   BOOST_IOS::openmode mode )
404     : pimpl_(new impl_type)
405 { open(path, mode); }
406 
file_descriptor(const char * path,BOOST_IOS::openmode mode)407 file_descriptor::file_descriptor( const char* path,
408                                   BOOST_IOS::openmode mode )
409     : pimpl_(new impl_type)
410 { open(path, mode); }
411 
file_descriptor(const file_descriptor & other)412 file_descriptor::file_descriptor(const file_descriptor& other)
413     : pimpl_(other.pimpl_)
414     { }
415 
open(handle_type fd,file_descriptor_flags f)416 void file_descriptor::open(handle_type fd, file_descriptor_flags f)
417 { pimpl_->open(fd, static_cast<detail::file_descriptor_impl::flags>(f)); }
418 
419 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
open(handle_type fd,bool close_on_exit)420 void file_descriptor::open(handle_type fd, bool close_on_exit)
421 { pimpl_->open(fd, close_on_exit ?
422     detail::file_descriptor_impl::close_always :
423     detail::file_descriptor_impl::close_on_close); }
424 #endif
425 
426 #ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------//
427 
open(int fd,file_descriptor_flags f)428 void file_descriptor::open(int fd, file_descriptor_flags f)
429 { pimpl_->open(fd, static_cast<detail::file_descriptor_impl::flags>(f)); }
430 
431 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
open(int fd,bool close_on_exit)432 void file_descriptor::open(int fd, bool close_on_exit)
433 { pimpl_->open(fd, close_on_exit ?
434     detail::file_descriptor_impl::close_always :
435     detail::file_descriptor_impl::close_on_close); }
436 #endif
437 
438 #endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------//
439 
open(const std::string & path,BOOST_IOS::openmode mode)440 void file_descriptor::open(const std::string& path, BOOST_IOS::openmode mode)
441 { open(detail::path(path), mode); }
442 
open(const char * path,BOOST_IOS::openmode mode)443 void file_descriptor::open(const char* path, BOOST_IOS::openmode mode)
444 { open(detail::path(path), mode); }
445 
is_open() const446 bool file_descriptor::is_open() const { return pimpl_->is_open(); }
447 
close()448 void file_descriptor::close() { pimpl_->close(); }
449 
read(char_type * s,std::streamsize n)450 std::streamsize file_descriptor::read(char_type* s, std::streamsize n)
451 { return pimpl_->read(s, n); }
452 
write(const char_type * s,std::streamsize n)453 std::streamsize file_descriptor::write(const char_type* s, std::streamsize n)
454 { return pimpl_->write(s, n); }
455 
seek(stream_offset off,BOOST_IOS::seekdir way)456 std::streampos file_descriptor::seek(stream_offset off, BOOST_IOS::seekdir way)
457 { return pimpl_->seek(off, way); }
458 
handle() const459 detail::file_handle file_descriptor::handle() const { return pimpl_->handle_; }
460 
init()461 void file_descriptor::init() { pimpl_.reset(new impl_type); }
462 
open(const detail::path & path,BOOST_IOS::openmode mode,BOOST_IOS::openmode base)463 void file_descriptor::open(
464     const detail::path& path,
465     BOOST_IOS::openmode mode,
466     BOOST_IOS::openmode base )
467 {
468     mode |= base;
469     pimpl_->open(path, mode);
470 }
471 
472 //------------------Implementation of file_descriptor_source------------------//
473 
file_descriptor_source(handle_type fd,file_descriptor_flags f)474 file_descriptor_source::file_descriptor_source(
475     handle_type fd, file_descriptor_flags f)
476 { open(fd, f); }
477 
478 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
file_descriptor_source(handle_type fd,bool close_on_exit)479 file_descriptor_source::file_descriptor_source(
480     handle_type fd, bool close_on_exit)
481 { open(fd, close_on_exit); }
482 #endif
483 
484 #ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------//
485 
file_descriptor_source(int fd,file_descriptor_flags f)486 file_descriptor_source::file_descriptor_source(int fd, file_descriptor_flags f)
487 { open(fd, f); }
488 
489 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
file_descriptor_source(int fd,bool close_on_exit)490 file_descriptor_source::file_descriptor_source(int fd, bool close_on_exit)
491 { open(fd, close_on_exit); }
492 #endif
493 
494 #endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------//
495 
file_descriptor_source(const std::string & path,BOOST_IOS::openmode mode)496 file_descriptor_source::file_descriptor_source(
497     const std::string& path, BOOST_IOS::openmode mode)
498 { open(path, mode); }
499 
file_descriptor_source(const char * path,BOOST_IOS::openmode mode)500 file_descriptor_source::file_descriptor_source(
501     const char* path, BOOST_IOS::openmode mode)
502 { open(path, mode); }
503 
file_descriptor_source(const file_descriptor_source & other)504 file_descriptor_source::file_descriptor_source(
505     const file_descriptor_source& other)
506         : file_descriptor(static_cast<const file_descriptor&>(other))
507     { }
508 
open(handle_type fd,file_descriptor_flags f)509 void file_descriptor_source::open(handle_type fd, file_descriptor_flags f)
510 { file_descriptor::open(fd, f);  }
511 
512 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
open(handle_type fd,bool close_on_exit)513 void file_descriptor_source::open(handle_type fd, bool close_on_exit)
514 { file_descriptor::open(fd, close_on_exit); }
515 #endif
516 
517 #ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------//
518 
open(int fd,file_descriptor_flags f)519 void file_descriptor_source::open(int fd, file_descriptor_flags f)
520 { file_descriptor::open(fd, f); }
521 
522 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
open(int fd,bool close_on_exit)523 void file_descriptor_source::open(int fd, bool close_on_exit)
524 { file_descriptor::open(fd, close_on_exit); }
525 #endif
526 
527 #endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------//
528 
open(const std::string & path,BOOST_IOS::openmode mode)529 void file_descriptor_source::open(
530     const std::string& path, BOOST_IOS::openmode mode)
531 { open(detail::path(path), mode); }
532 
open(const char * path,BOOST_IOS::openmode mode)533 void file_descriptor_source::open(
534     const char* path, BOOST_IOS::openmode mode)
535 { open(detail::path(path), mode); }
536 
open(const detail::path & path,BOOST_IOS::openmode mode)537 void file_descriptor_source::open(
538     const detail::path& path, BOOST_IOS::openmode mode)
539 {
540     if (mode & (BOOST_IOS::out | BOOST_IOS::trunc))
541         boost::throw_exception(BOOST_IOSTREAMS_FAILURE("invalid mode"));
542     file_descriptor::open(path, mode, BOOST_IOS::in);
543 }
544 
545 //------------------Implementation of file_descriptor_sink--------------------//
546 
file_descriptor_sink(handle_type fd,file_descriptor_flags f)547 file_descriptor_sink::file_descriptor_sink(
548     handle_type fd, file_descriptor_flags f)
549 { open(fd, f); }
550 
551 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
file_descriptor_sink(handle_type fd,bool close_on_exit)552 file_descriptor_sink::file_descriptor_sink(
553     handle_type fd, bool close_on_exit)
554 { open(fd, close_on_exit); }
555 #endif
556 
557 #ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------//
558 
file_descriptor_sink(int fd,file_descriptor_flags f)559 file_descriptor_sink::file_descriptor_sink(int fd, file_descriptor_flags f)
560 { open(fd, f); }
561 
562 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
file_descriptor_sink(int fd,bool close_on_exit)563 file_descriptor_sink::file_descriptor_sink(int fd, bool close_on_exit)
564 { open(fd, close_on_exit); }
565 #endif
566 
567 #endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------//
568 
file_descriptor_sink(const std::string & path,BOOST_IOS::openmode mode)569 file_descriptor_sink::file_descriptor_sink(
570     const std::string& path, BOOST_IOS::openmode mode)
571 { open(path, mode); }
572 
file_descriptor_sink(const char * path,BOOST_IOS::openmode mode)573 file_descriptor_sink::file_descriptor_sink(
574     const char* path, BOOST_IOS::openmode mode)
575 { open(path, mode); }
576 
file_descriptor_sink(const file_descriptor_sink & other)577 file_descriptor_sink::file_descriptor_sink(const file_descriptor_sink& other)
578     : file_descriptor(static_cast<const file_descriptor&>(other))
579     { }
580 
open(handle_type fd,file_descriptor_flags f)581 void file_descriptor_sink::open(handle_type fd, file_descriptor_flags f)
582 { file_descriptor::open(fd, f);  }
583 
584 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
open(handle_type fd,bool close_on_exit)585 void file_descriptor_sink::open(handle_type fd, bool close_on_exit)
586 { file_descriptor::open(fd, close_on_exit); }
587 #endif
588 
589 #ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------//
590 
open(int fd,file_descriptor_flags f)591 void file_descriptor_sink::open(int fd, file_descriptor_flags f)
592 { file_descriptor::open(fd, f); }
593 
594 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
open(int fd,bool close_on_exit)595 void file_descriptor_sink::open(int fd, bool close_on_exit)
596 { file_descriptor::open(fd, close_on_exit); }
597 #endif
598 
599 #endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------//
600 
open(const std::string & path,BOOST_IOS::openmode mode)601 void file_descriptor_sink::open(
602     const std::string& path, BOOST_IOS::openmode mode)
603 { open(detail::path(path), mode); }
604 
open(const char * path,BOOST_IOS::openmode mode)605 void file_descriptor_sink::open(
606     const char* path, BOOST_IOS::openmode mode)
607 { open(detail::path(path), mode); }
608 
open(const detail::path & path,BOOST_IOS::openmode mode)609 void file_descriptor_sink::open(
610     const detail::path& path, BOOST_IOS::openmode mode)
611 {
612     if (mode & BOOST_IOS::in)
613         boost::throw_exception(BOOST_IOSTREAMS_FAILURE("invalid mode"));
614     file_descriptor::open(path, mode, BOOST_IOS::out);
615 }
616 
617 #include <boost/iostreams/detail/config/enable_warnings.hpp>
618 
619 } } // End namespaces iostreams, boost.
620