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 ;
12 ERROR: unix-error errno message ;
14 : (io-error) ( -- * ) errno dup strerror unix-error ;
16 : io-error ( n -- ) 0 < [ (io-error) ] when ;
18 ERROR: unix-system-call-error args errno message word ;
20 : unix-call-failed? ( ret -- ? )
22 [ { [ integer? ] [ 0 < ] } 1&& ]
26 MACRO:: unix-system-call ( quot -- )
35 [ unix-call-failed? dup failed! ]
36 [ drop errno EINTR = ]
42 word unix-system-call-error
49 HOOK: open-file os ( path flags mode -- fd )
51 : close-file ( fd -- ) [ close ] unix-system-call drop ;
53 : _exit ( status -- * )
54 #! We throw to give this a terminating stack effect.
55 int f "_exit" { int } alien-invoke "Exit failed" throw ;
57 M: unix open-file [ open ] unix-system-call ;
59 : touch ( filename -- ) f [ utime ] unix-system-call drop ;
61 : change-file-times ( filename access modification -- )
65 [ utime ] unix-system-call drop ;
67 : read-symbolic-link ( path -- path )
68 PATH_MAX <byte-array> dup [
70 [ readlink ] unix-system-call
71 ] dip swap head-slice >string ;
73 : unlink-file ( path -- ) [ unlink ] unix-system-call drop ;
78 "unix.debugger" require