libc: reduce code duplication.

db4
John Benediktsson 2014-11-21 10:19:12 -08:00
parent 39093727b1
commit 7badef25ce
5 changed files with 11 additions and 9 deletions

View File

@ -97,7 +97,7 @@ M: fd refill
errno { errno {
{ EINTR [ 2drop +retry+ ] } { EINTR [ 2drop +retry+ ] }
{ EAGAIN [ 2drop +input+ ] } { EAGAIN [ 2drop +input+ ] }
[ throw-errno ] [ (throw-errno) ]
} case } case
] if ; ] if ;
@ -117,7 +117,7 @@ M: fd drain
errno { errno {
{ EINTR [ 2drop +retry+ ] } { EINTR [ 2drop +retry+ ] }
{ EAGAIN [ 2drop +output+ ] } { EAGAIN [ 2drop +output+ ] }
[ throw-errno ] [ (throw-errno) ]
} case } case
] if ; ] if ;

View File

@ -7,7 +7,7 @@ IN: io.directories.unix.linux
: next-dirent ( DIR* dirent* -- dirent* ? ) : next-dirent ( DIR* dirent* -- dirent* ? )
f void* <ref> [ f void* <ref> [
readdir64_r [ dup strerror libc-error ] unless-zero readdir64_r [ (throw-errno) ] unless-zero
] 2keep void* deref ; inline ] 2keep void* deref ; inline
M: linux (directory-entries) ( path -- seq ) M: linux (directory-entries) ( path -- seq )

View File

@ -56,7 +56,7 @@ M: unix copy-file ( from to -- )
: next-dirent ( DIR* dirent* -- dirent* ? ) : next-dirent ( DIR* dirent* -- dirent* ? )
f void* <ref> [ f void* <ref> [
readdir_r [ dup strerror libc-error ] unless-zero readdir_r [ (throw-errno) ] unless-zero
] 2keep void* deref ; inline ] 2keep void* deref ; inline
: >directory-entry ( dirent* -- directory-entry ) : >directory-entry ( dirent* -- directory-entry )

View File

@ -56,7 +56,7 @@ DEFER: wait-to-connect
errno { errno {
{ EAGAIN [ wait-for-output ] } { EAGAIN [ wait-for-output ] }
{ EINTR [ wait-to-connect ] } { EINTR [ wait-to-connect ] }
[ throw-errno ] [ (throw-errno) ]
} case } case
] if ; ] if ;
@ -67,7 +67,7 @@ M: object establish-connection
errno { errno {
{ EINTR [ establish-connection ] } { EINTR [ establish-connection ] }
{ EINPROGRESS [ drop wait-for-output ] } { EINPROGRESS [ drop wait-for-output ] }
[ throw-errno ] [ (throw-errno) ]
} case } case
] if ; ] if ;
@ -114,7 +114,7 @@ M: object (accept)
[ (accept) ] [ (accept) ]
2bi 2bi
] } ] }
[ throw-errno ] [ (throw-errno) ]
} case } case
] if ; ] if ;
@ -157,7 +157,7 @@ M: unix (receive-unsafe)
datagram +output+ wait-for-port datagram +output+ wait-for-port
packet sockaddr len socket datagram do-send packet sockaddr len socket datagram do-send
] } ] }
[ throw-errno ] [ (throw-errno) ]
} case } case
] when ; inline recursive ] when ; inline recursive

View File

@ -45,7 +45,9 @@ M: object strerror strerror_unsafe ;
ERROR: libc-error errno message ; ERROR: libc-error errno message ;
: throw-errno ( -- * ) errno dup strerror libc-error ; : (throw-errno) ( errno -- * ) dup strerror libc-error ;
: throw-errno ( -- * ) errno (throw-errno) ;
: io-error ( n -- ) 0 < [ throw-errno ] when ; : io-error ( n -- ) 0 < [ throw-errno ] when ;