@@ -5,47 +5,16 @@ if not jit then
55
66elseif jit .arch ~= " Windows" then
77 local ffi = require (" ffi" )
8- ffi .cdef (" char *strerror(int);" )
98
10- function fs .last_error ()
11- local num = ffi .errno ()
12- local err = ffi .string (ffi .C .strerror (num ))
13- return err == " " and tostring (num ) or err
14- end
15- else
16- local ffi = require (" ffi" )
17- ffi .cdef (" uint32_t GetLastError();" )
18- ffi .cdef [[
19- uint32_t FormatMessageA (
20- uint32_t dwFlags ,
21- const void * lpSource ,
22- uint32_t dwMessageId ,
23- uint32_t dwLanguageId ,
24- char * lpBuffer ,
25- uint32_t nSize ,
26- va_list * Arguments
27- );
28- ]]
29- local error_str = ffi .new (" uint8_t[?]" , 1024 )
30- local FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
31- local FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200
32- local error_flags = bit .bor (FORMAT_MESSAGE_FROM_SYSTEM , FORMAT_MESSAGE_IGNORE_INSERTS )
33-
34- function fs .last_error ()
35- local code = ffi .C .GetLastError ()
36- local numout = ffi .C .FormatMessageA (error_flags , nil , code , 0 , error_str , 1023 , nil )
37- local err = numout ~= 0 and ffi .string (error_str , numout )
38-
39- if err and err :sub (- 2 ) == " \r\n " then return err :sub (0 , - 3 ) end
40-
41- return err
42- end
43- end
44-
45- if not jit then
9+ do
10+ ffi .cdef (" char *strerror(int);" )
4611
47- elseif jit .arch ~= " Windows" then
48- local ffi = require (" ffi" )
12+ function fs .last_error ()
13+ local num = ffi .errno ()
14+ local err = ffi .string (ffi .C .strerror (num ))
15+ return err == " " and tostring (num ) or err
16+ end
17+ end
4918
5019 do -- attributes
5120 local stat_struct
@@ -361,6 +330,37 @@ elseif jit.arch ~= "Windows" then
361330 end
362331else
363332 local ffi = require (" ffi" )
333+
334+ do
335+ local ffi = require (" ffi" )
336+ ffi .cdef (" uint32_t GetLastError();" )
337+ ffi .cdef [[
338+ uint32_t FormatMessageA (
339+ uint32_t dwFlags ,
340+ const void * lpSource ,
341+ uint32_t dwMessageId ,
342+ uint32_t dwLanguageId ,
343+ char * lpBuffer ,
344+ uint32_t nSize ,
345+ va_list * Arguments
346+ );
347+ ]]
348+ local error_str = ffi .new (" uint8_t[?]" , 1024 )
349+ local FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
350+ local FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200
351+ local error_flags = bit .bor (FORMAT_MESSAGE_FROM_SYSTEM , FORMAT_MESSAGE_IGNORE_INSERTS )
352+
353+ function fs .last_error ()
354+ local code = ffi .C .GetLastError ()
355+ local numout = ffi .C .FormatMessageA (error_flags , nil , code , 0 , error_str , 1023 , nil )
356+ local err = numout ~= 0 and ffi .string (error_str , numout )
357+
358+ if err and err :sub (- 2 ) == " \r\n " then return err :sub (0 , - 3 ) end
359+
360+ return err
361+ end
362+ end
363+
364364 local DIRECTORY = 0x10
365365 local time_struct = ffi .typeof ([[
366366 struct {
0 commit comments