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 -- quot )
29 [ unix-call-failed? dup failed! ]
30 [ drop errno EINTR = ]
36 word unix-system-call-error
43 MACRO:: unix-system-call-allow-eintr ( quot -- quot )
49 ret unix-call-failed? [
51 ! Allow EINTR for close(2)
55 word unix-system-call-error
63 HOOK: open-file os ( path flags mode -- fd )
65 : close-file ( fd -- ) [ close ] unix-system-call-allow-eintr drop ;
67 FUNCTION: int _exit ( int status )
69 M: unix open-file [ open ] unix-system-call ;
71 : make-fifo ( path mode -- ) [ mkfifo ] unix-system-call drop ;
73 : truncate-file ( path n -- ) [ truncate ] unix-system-call drop ;
75 : touch ( filename -- ) f [ utime ] unix-system-call drop ;
77 : change-file-times ( filename access modification -- )
81 [ utime ] unix-system-call drop ;
83 : read-symbolic-link ( path -- path )
84 PATH_MAX <byte-vector> [
86 [ readlink ] unix-system-call
87 ] keep swap >>length >string ;
89 : unlink-file ( path -- ) [ unlink ] unix-system-call drop ;
93 { "unix" "debugger" } "unix.debugger" require-when