1 ! Copyright (C) 2005, 2010 Slava Pestov.
2 ! Copyright (C) 2008 Eduardo Cavazos.
3 ! See http://factorcode.org/license.txt for BSD license.
4 USING: accessors alien alien.c-types alien.libraries
5 alien.syntax byte-arrays classes.struct combinators
6 combinators.short-circuit combinators.smart continuations
7 generalizations io kernel libc locals macros math namespaces
8 sequences stack-checker strings system unix.time unix.types
9 vocabs vocabs.loader unix.ffi ;
14 ERROR: unix-error errno message ;
16 : (io-error) ( -- * ) errno dup strerror unix-error ;
18 : io-error ( n -- ) 0 < [ (io-error) ] when ;
20 ERROR: unix-system-call-error args errno message word ;
22 : unix-call-failed? ( ret -- ? )
24 [ { [ integer? ] [ 0 < ] } 1&& ]
28 MACRO:: unix-system-call ( quot -- )
37 [ unix-call-failed? dup failed! ]
38 [ drop errno EINTR = ]
44 word unix-system-call-error
53 HOOK: open-file os ( path flags mode -- fd )
55 : close-file ( fd -- ) [ close ] unix-system-call drop ;
57 : _exit ( status -- * )
58 #! We throw to give this a terminating stack effect.
59 int f "_exit" { int } alien-invoke "Exit failed" throw ;
61 M: unix open-file [ open ] unix-system-call ;
63 : touch ( filename -- ) f [ utime ] unix-system-call drop ;
65 : change-file-times ( filename access modification -- )
69 [ utime ] unix-system-call drop ;
71 : read-symbolic-link ( path -- path )
72 PATH_MAX <byte-array> dup [
74 [ readlink ] unix-system-call
75 ] dip swap head-slice >string ;
77 : unlink-file ( path -- ) [ unlink ] unix-system-call drop ;
80 "unix.debugger" require