LIBRARY: libc
-FUNCTION: c-string strerror ( int errno ) ;
-
-ERROR: libc-error errno message ;
-
-: (io-error) ( -- * ) errno dup strerror libc-error ;
-
-: io-error ( n -- ) 0 < [ (io-error) ] when ;
-
FUNCTION-ALIAS: (malloc)
void* malloc ( size_t size ) ;
FUNCTION-ALIAS: (realloc)
void* realloc ( void* alien, size_t size ) ;
+HOOK: strerror os ( errno -- str )
+
+FUNCTION: int strerror_r ( int errno, char* buf, size_t buflen ) ;
+
+ERROR: libc-error errno message ;
+
+: (io-error) ( -- * ) errno dup strerror libc-error ;
+
+: io-error ( n -- ) 0 < [ (io-error) ] when ;
+
<PRIVATE
! We stick malloc-ptr instances in the global disposables set
-USING: alien.syntax ;
+USING: alien.strings destructors kernel libc system ;
IN: libc
LIBRARY: libc
CONSTANT: SIGABRT 22
CONSTANT: SIGABRT_COMPAT 6
+
+LIBRARY: libc
+
+FUNCTION: int strerror_s ( char *buffer, size_t numberOfElements, int errnum ) ;
+
+M: windows strerror ( errno -- str )
+ [
+ [ 1024 [ malloc &free ] keep ] dip
+ [ strerror_s drop ] 3keep 2drop
+ alien>native-string
+ ] with-destructors ;