Windows: Fix binary output of jit.bcsave to stdout.

Thanks to erw7.
master
Mike Pall 2021-12-17 14:30:44 +01:00
parent 8b7ea5c1af
commit 1d20f33d29
1 changed files with 13 additions and 0 deletions

View File

@ -60,6 +60,11 @@ local function savefile(name, mode)
return check(io.open(name, mode))
end
local function set_stdout_binary(ffi)
ffi.cdef[[int _setmode(int fd, int mode);]]
ffi.C._setmode(1, 0x8000)
end
------------------------------------------------------------------------------
local map_type = {
@ -125,6 +130,11 @@ local function bcsave_tail(fp, output, s)
end
local function bcsave_raw(output, s)
if output == "-" and jit.os == "Windows" then
local ok, ffi = pcall(require, "ffi")
check(ok, "FFI library required to write binary file to stdout")
set_stdout_binary(ffi)
end
local fp = savefile(output, "wb")
bcsave_tail(fp, output, s)
end
@ -568,6 +578,9 @@ end
local function bcsave_obj(ctx, output, s)
local ok, ffi = pcall(require, "ffi")
check(ok, "FFI library required to write this file type")
if output == "-" and jit.os == "Windows" then
set_stdout_binary(ffi)
end
if ctx.os == "windows" then
return bcsave_peobj(ctx, output, s, ffi)
elseif ctx.os == "osx" then