libc: First stab at using strerror_r and (strerror_s on Windows) instead of thread-unsafe strerror.
parent
69262be4d8
commit
d7595bbb7c
|
@ -25,14 +25,6 @@ FUNCTION-ALIAS: set-errno
|
||||||
|
|
||||||
LIBRARY: libc
|
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)
|
FUNCTION-ALIAS: (malloc)
|
||||||
void* malloc ( size_t size ) ;
|
void* malloc ( size_t size ) ;
|
||||||
|
|
||||||
|
@ -45,6 +37,16 @@ FUNCTION-ALIAS: (free)
|
||||||
FUNCTION-ALIAS: (realloc)
|
FUNCTION-ALIAS: (realloc)
|
||||||
void* realloc ( void* alien, size_t size ) ;
|
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
|
<PRIVATE
|
||||||
|
|
||||||
! We stick malloc-ptr instances in the global disposables set
|
! We stick malloc-ptr instances in the global disposables set
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
USING: alien.syntax ;
|
USING: alien.strings destructors kernel libc system ;
|
||||||
IN: libc
|
IN: libc
|
||||||
|
|
||||||
LIBRARY: libc
|
LIBRARY: libc
|
||||||
|
@ -102,3 +102,14 @@ CONSTANT: SIGBREAK 21
|
||||||
CONSTANT: SIGABRT 22
|
CONSTANT: SIGABRT 22
|
||||||
|
|
||||||
CONSTANT: SIGABRT_COMPAT 6
|
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 ;
|
||||||
|
|
Loading…
Reference in New Issue