@@ -1244,6 +1244,14 @@ function _redirect_io_libc(stream, unix_fd::Int)
1244
1244
dup (posix_fd, RawFD (unix_fd))
1245
1245
nothing
1246
1246
end
1247
+ function _set_cglobal_stdio (handle:: Union{LibuvStream, IOStream} , unix_fd:: Int )
1248
+ c_sym = unix_fd == 0 ? cglobal (:jl_uv_stdin , Ptr{Cvoid}) :
1249
+ unix_fd == 1 ? cglobal (:jl_uv_stdout , Ptr{Cvoid}) :
1250
+ unix_fd == 2 ? cglobal (:jl_uv_stderr , Ptr{Cvoid}) :
1251
+ C_NULL
1252
+ c_sym == C_NULL || unsafe_store! (c_sym, handle. handle)
1253
+ nothing
1254
+ end
1247
1255
function _redirect_io_global (io, unix_fd:: Int )
1248
1256
unix_fd == 0 && (global stdin = io)
1249
1257
unix_fd == 1 && (global stdout = io)
@@ -1252,18 +1260,15 @@ function _redirect_io_global(io, unix_fd::Int)
1252
1260
end
1253
1261
function (f:: RedirectStdStream )(handle:: Union{LibuvStream, IOStream} )
1254
1262
_redirect_io_libc (handle, f. unix_fd)
1255
- c_sym = f. unix_fd == 0 ? cglobal (:jl_uv_stdin , Ptr{Cvoid}) :
1256
- f. unix_fd == 1 ? cglobal (:jl_uv_stdout , Ptr{Cvoid}) :
1257
- f. unix_fd == 2 ? cglobal (:jl_uv_stderr , Ptr{Cvoid}) :
1258
- C_NULL
1259
- c_sym == C_NULL || unsafe_store! (c_sym, handle. handle)
1263
+ _set_cglobal_stdio (handle, f. unix_fd)
1260
1264
_redirect_io_global (handle, f. unix_fd)
1261
1265
return handle
1262
1266
end
1263
1267
function (f:: RedirectStdStream )(:: DevNull )
1264
1268
nulldev = @static Sys. iswindows () ? " NUL" : " /dev/null"
1265
1269
handle = open (nulldev, write= f. writable)
1266
1270
_redirect_io_libc (handle, f. unix_fd)
1271
+ _set_cglobal_stdio (handle, f. unix_fd)
1267
1272
close (handle) # handle has been dup'ed in _redirect_io_libc
1268
1273
_redirect_io_global (devnull , f. unix_fd)
1269
1274
return devnull
0 commit comments