|
2 | 2 | // |
3 | 3 | // For the full copyright and license information, please view the LICENSE |
4 | 4 | // file that was distributed with this source code. |
5 | | -// spell-checker:ignore (ToDO) IOFBF IOLBF IONBF setvbuf stderrp stdinp stdoutp |
| 5 | +// spell-checker:ignore (ToDO) getreent reent IOFBF IOLBF IONBF setvbuf stderrp stdinp stdoutp |
6 | 6 |
|
7 | 7 | use ctor::ctor; |
8 | 8 | use libc::{_IOFBF, _IOLBF, _IONBF, FILE, c_char, c_int, fileno, size_t}; |
@@ -35,7 +35,35 @@ pub unsafe extern "C" fn __stdbuf_get_stdin() -> *mut FILE { |
35 | 35 | unsafe { __stdin } |
36 | 36 | } |
37 | 37 |
|
38 | | - #[cfg(not(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd")))] |
| 38 | + #[cfg(target_os = "cygwin")] |
| 39 | + { |
| 40 | + // _getreent()->_std{in,out,err} |
| 41 | + // see: |
| 42 | + // echo '#include <stdio.h>\nstd{in,out,err}' | gcc -E -xc - -std=c23 | tail -n1 |
| 43 | + // echo '#include <stdio.h>' | grep -E -xc - -std=c23 | grep 'struct _reent' -A91 | grep 580 -A91 | tail -n+2 |
| 44 | + |
| 45 | + #[repr(C)] |
| 46 | + struct _reent { |
| 47 | + _errno: c_int, |
| 48 | + _stdin: *mut FILE, |
| 49 | + _stdout: *mut FILE, |
| 50 | + _stderr: *mut FILE, |
| 51 | + // other stuff |
| 52 | + } |
| 53 | + |
| 54 | + unsafe extern "C" { |
| 55 | + fn __getreent() -> *mut _reent; |
| 56 | + } |
| 57 | + |
| 58 | + unsafe { (*__getreent())._stdin } |
| 59 | + } |
| 60 | + |
| 61 | + #[cfg(not(any( |
| 62 | + target_os = "macos", |
| 63 | + target_os = "freebsd", |
| 64 | + target_os = "openbsd", |
| 65 | + target_os = "cygwin" |
| 66 | + )))] |
39 | 67 | { |
40 | 68 | unsafe extern "C" { |
41 | 69 | static mut stdin: *mut FILE; |
@@ -64,7 +92,35 @@ pub unsafe extern "C" fn __stdbuf_get_stdout() -> *mut FILE { |
64 | 92 | unsafe { __stdout } |
65 | 93 | } |
66 | 94 |
|
67 | | - #[cfg(not(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd")))] |
| 95 | + #[cfg(target_os = "cygwin")] |
| 96 | + { |
| 97 | + // _getreent()->_std{in,out,err} |
| 98 | + // see: |
| 99 | + // echo '#include <stdio.h>\nstd{in,out,err}' | gcc -E -xc - -std=c23 | tail -n1 |
| 100 | + // echo '#include <stdio.h>' | grep -E -xc - -std=c23 | grep 'struct _reent' -A91 | grep 580 -A91 | tail -n+2 |
| 101 | + |
| 102 | + #[repr(C)] |
| 103 | + struct _reent { |
| 104 | + _errno: c_int, |
| 105 | + _stdin: *mut FILE, |
| 106 | + _stdout: *mut FILE, |
| 107 | + _stderr: *mut FILE, |
| 108 | + // other stuff |
| 109 | + } |
| 110 | + |
| 111 | + unsafe extern "C" { |
| 112 | + fn __getreent() -> *mut _reent; |
| 113 | + } |
| 114 | + |
| 115 | + unsafe { (*__getreent())._stdout } |
| 116 | + } |
| 117 | + |
| 118 | + #[cfg(not(any( |
| 119 | + target_os = "macos", |
| 120 | + target_os = "freebsd", |
| 121 | + target_os = "openbsd", |
| 122 | + target_os = "cygwin" |
| 123 | + )))] |
68 | 124 | { |
69 | 125 | unsafe extern "C" { |
70 | 126 | static mut stdout: *mut FILE; |
@@ -93,7 +149,35 @@ pub unsafe extern "C" fn __stdbuf_get_stderr() -> *mut FILE { |
93 | 149 | unsafe { __stderr } |
94 | 150 | } |
95 | 151 |
|
96 | | - #[cfg(not(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd")))] |
| 152 | + #[cfg(target_os = "cygwin")] |
| 153 | + { |
| 154 | + // _getreent()->_std{in,out,err} |
| 155 | + // see: |
| 156 | + // echo '#include <stdio.h>\nstd{in,out,err}' | gcc -E -xc - -std=c23 | tail -n1 |
| 157 | + // echo '#include <stdio.h>' | grep -E -xc - -std=c23 | grep 'struct _reent' -A91 | grep 580 -A91 | tail -n+2 |
| 158 | + |
| 159 | + #[repr(C)] |
| 160 | + struct _reent { |
| 161 | + _errno: c_int, |
| 162 | + _stdin: *mut FILE, |
| 163 | + _stdout: *mut FILE, |
| 164 | + _stderr: *mut FILE, |
| 165 | + // other stuff |
| 166 | + } |
| 167 | + |
| 168 | + unsafe extern "C" { |
| 169 | + fn __getreent() -> *mut _reent; |
| 170 | + } |
| 171 | + |
| 172 | + unsafe { (*__getreent())._stdin } |
| 173 | + } |
| 174 | + |
| 175 | + #[cfg(not(any( |
| 176 | + target_os = "macos", |
| 177 | + target_os = "freebsd", |
| 178 | + target_os = "openbsd", |
| 179 | + target_os = "cygwin" |
| 180 | + )))] |
97 | 181 | { |
98 | 182 | unsafe extern "C" { |
99 | 183 | static mut stderr: *mut FILE; |
|
0 commit comments