nobi56

Change the file translation mode of stdout

May 6th, 2021
440
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --
  2. --  Change the file translation mode of stdout: _setmode, _O_BINARY
  3. --
  4. --  _setmode: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/setmode?view=msvc-160
  5. --  _O_BINARY: https://github.com/mirror/mingw-w64/blob/master/mingw-w64-headers/crt/fcntl.h
  6. --  STDOUT_FILENO: https://github.com/mirror/mingw-w64/blob/master/mingw-w64-headers/crt/unistd.h
  7. --
  8.  
  9. local ffi = require 'ffi'
  10. local C = ffi.C
  11.  
  12. ffi.cdef [[
  13. int _setmode(int fd, int mode);
  14. ]]
  15.  
  16. C._setmode(1, 0x8000)
  17.  
  18. --
  19. -- > luajit -e "M=require('ffi')M.cdef('int _setmode(int,int);')M.C._setmode(1,0x8000)print()" | busybox xxd
  20. -- 00000000: 0a                                       .
  21. --
  22. -- > luajit -e "print()" | busybox xxd
  23. -- 00000000: 0d0a                                     ..
  24. --
RAW Paste Data