mitigate.hpp
Go to the documentation of this file.
1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
3 // Copyright (c) 2009 Boris Schaeling
4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 
10 /**
11  * \file boost/process/mitigate.hpp
12  *
13  * Helpers to mitigate platform differences.
14  */
15 
16 #pragma once
17 
18 #include <boost/asio.hpp>
19 #if defined(BOOST_POSIX_API)
20 # include <sys/wait.h>
21 #endif
22 
23 namespace boost
24 {
25  namespace process
26  {
27 
28 #if defined(BOOST_WINDOWS_API)
29  using pipe_end = boost::asio::windows::stream_handle;
30 #elif defined(BOOST_POSIX_API)
31  using pipe_end = boost::asio::posix::stream_descriptor;
32 #endif
33 
34  inline const char* zero_device()
35  {
36 #if defined(BOOST_WINDOWS_API)
37  return "NUL";
38 #elif defined(BOOST_POSIX_API)
39  return "/dev/zero";
40 #endif
41  }
42 
43  inline const char* null_device()
44  {
45 #if defined(BOOST_WINDOWS_API)
46  return "NUL";
47 #elif defined(BOOST_POSIX_API)
48  return "/dev/null";
49 #endif
50  }
51 
52 #if defined(BOOST_WINDOWS_API)
53 # define BOOST_PROCESS_EXITSTATUS(a) static_cast<int>(a)
54 #elif defined(BOOST_POSIX_API)
55 # define BOOST_PROCESS_EXITSTATUS WEXITSTATUS
56 #endif
57 
58 #if defined(BOOST_PROCESS_DOXYGEN)
59  /**
60  * Type definition for the end of a pipe.
61  *
62  * On Windows the type is based on boost::asio::windows::stream_handle. On
63  * POSIX it is based on boost::asio::posix::stream_descriptor.
64  *
65  * You can use this type definition for asynchronous I/O with streams of
66  * child processes.
67  */
68  using pipe_end = boost_asio_type;
69 
70  /**
71  * Gets the name of the zero device.
72  *
73  * You can use zero_device to initialize a
74  * boost::iostreams::file_descriptor_source to read
75  * null characters from.
76  *
77  * \returns NUL on Windows and /dev/zero on POSIX.
78  */
79  const char* zero_device();
80 
81  /**
82  * Gets the name of the null device.
83  *
84  * You can use null_device to initialize a
85  * boost::iostreams::file_descriptor_sink which discards
86  * data written to it.
87  *
88  * \returns NUL on Windows and /dev/null on POSIX.
89  */
90  const char* null_device();
91 
92  /**
93  * \def BOOST_PROCESS_EXITSTATUS
94  *
95  * On Windows \c BOOST_PROCESS_EXITSTATUS is a static cast to \c int.
96  * On POSIX it is set to \c WEXITSTATUS.
97  *
98  * You can use \c BOOST_PROCESS_EXITSTATUS for the return value of
99  * boost::process::wait_for_exit to get the exit status of a process.
100  */
101 #define BOOST_PROCESS_EXITSTATUS
102 #endif
103 
104  }
105 }
106 
boost::process::zero_device
const char * zero_device()
Definition: mitigate.hpp:34
boost::process::null_device
const char * null_device()
Definition: mitigate.hpp:43
boost
Definition: ApplicationOptions.h:37