Ported some lines to linux, introduced unsafe buffers in error handling