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.c-types alien.syntax byte-vectors
5 classes.struct combinators.short-circuit combinators.smart
6 generalizations kernel libc locals math sequences
7 sequences.generalizations strings system unix.ffi vocabs.loader
11 ERROR: unix-system-call-error args errno message word ;
13 : unix-call-failed? ( ret -- ? )
15 [ { [ integer? ] [ 0 < ] } 1&& ]
19 MACRO:: unix-system-call ( quot -- quot )
28 [ unix-call-failed? dup failed! ]
29 [ drop errno EINTR = ]
35 word throw-unix-system-call-error
42 MACRO:: unix-system-call-allow-eintr ( quot -- quot )
48 ret unix-call-failed? [
50 ! Allow EINTR for close(2)
54 word throw-unix-system-call-error
62 HOOK: open-file os ( path flags mode -- fd )
64 : close-file ( fd -- ) [ close ] unix-system-call-allow-eintr drop ;
66 FUNCTION: int _exit ( int status )
68 M: unix open-file [ open ] unix-system-call ;
70 : make-fifo ( path mode -- ) [ mkfifo ] unix-system-call drop ;
72 : truncate-file ( path n -- ) [ truncate ] unix-system-call drop ;
74 : touch ( filename -- ) f [ utime ] unix-system-call drop ;
76 : change-file-times ( filename access modification -- )
80 [ utime ] unix-system-call drop ;
82 : read-symbolic-link ( path -- path )
83 PATH_MAX <byte-vector> [
85 [ readlink ] unix-system-call
86 ] keep swap >>length >string ;
88 : unlink-file ( path -- ) [ unlink ] unix-system-call drop ;
90 { "unix" "debugger" } "unix.debugger" require-when