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 sequences.generalizations stack-checker strings system
9 unix.time unix.types 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 FUNCTION: int _exit ( int status ) ;
55 M: unix open-file [ open ] unix-system-call ;
57 : touch ( filename -- ) f [ utime ] unix-system-call drop ;
59 : change-file-times ( filename access modification -- )
63 [ utime ] unix-system-call drop ;
65 : read-symbolic-link ( path -- path )
66 PATH_MAX <byte-array> dup [
68 [ readlink ] unix-system-call
69 ] dip swap head-slice >string ;
71 : unlink-file ( path -- ) [ unlink ] unix-system-call drop ;
75 { "unix" "debugger" } "unix.debugger" require-when