1 ! Copyright (C) 2005, 2010 Slava Pestov.
2 ! Copyright (C) 2008 Eduardo Cavazos.
3 ! See https://factorcode.org/license.txt for BSD license.
4 USING: accessors alien.c-types alien.syntax byte-arrays
5 combinators.short-circuit combinators.smart generalizations kernel
6 libc math sequences sequences.generalizations strings system
7 unix.ffi vocabs.loader ;
10 ERROR: unix-system-call-error args errno message word ;
12 : unix-call-failed? ( ret -- ? )
14 [ { [ integer? ] [ 0 < ] } 1&& ]
18 MACRO:: unix-system-call ( quot -- quot )
27 [ unix-call-failed? dup failed! ]
28 [ drop errno EINTR = ]
34 word unix-system-call-error
41 MACRO:: unix-system-call-allow-eintr ( quot -- quot )
47 ret unix-call-failed? [
49 ! Allow EINTR for close(2)
53 word unix-system-call-error
61 HOOK: open-file os ( path flags mode -- fd )
63 : close-file ( fd -- ) [ close ] unix-system-call-allow-eintr drop ;
65 FUNCTION: int _exit ( int status )
67 M: unix open-file [ open ] unix-system-call ;
69 : make-fifo ( path mode -- ) [ mkfifo ] unix-system-call drop ;
71 : touch ( filename -- ) f [ utime ] unix-system-call drop ;
73 : change-file-times ( filename access modification -- )
77 [ utime ] unix-system-call drop ;
79 : (read-symbolic-link) ( path bufsiz -- path' )
80 dup <byte-array> 3dup swap [ readlink ] unix-system-call
81 pick dupd < [ head >string 2nip ] [
82 2nip 2 * (read-symbolic-link)
85 : read-symbolic-link ( path -- path )
86 4096 (read-symbolic-link) ;
88 : unlink-file ( path -- ) [ unlink ] unix-system-call drop ;
90 { "unix" "debugger" } "unix.debugger" require-when