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-vectors 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-system-call-error args errno message word ;
14 : unix-call-failed? ( ret -- ? )
16 [ { [ integer? ] [ 0 < ] } 1&& ]
20 MACRO:: unix-system-call ( quot -- )
29 [ unix-call-failed? dup failed! ]
30 [ drop errno EINTR = ]
36 word unix-system-call-error
43 HOOK: open-file os ( path flags mode -- fd )
45 : close-file ( fd -- ) [ close ] unix-system-call drop ;
47 FUNCTION: int _exit ( int status ) ;
49 M: unix open-file [ open ] unix-system-call ;
51 : make-fifo ( path mode -- ) [ mkfifo ] unix-system-call drop ;
53 : truncate-file ( path n -- ) [ truncate ] unix-system-call drop ;
55 : touch ( filename -- ) f [ utime ] unix-system-call drop ;
57 : change-file-times ( filename access modification -- )
61 [ utime ] unix-system-call drop ;
63 : read-symbolic-link ( path -- path )
64 PATH_MAX <byte-vector> [
66 [ readlink ] unix-system-call
67 ] keep swap >>length >string ;
69 : unlink-file ( path -- ) [ unlink ] unix-system-call drop ;
73 { "unix" "debugger" } "unix.debugger" require-when