1 ! Copyright (C) 2005, 2008 Slava Pestov, Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors byte-arrays continuations destructors environment
4 io.backend.unix io.files io.files.private io.pathnames io.ports kernel
5 libc literals math system unix unix.ffi ;
8 : (cwd) ( bufsiz -- path )
10 dup <byte-array> over [ getcwd ] unix-system-call nip
12 dup errno>> ERANGE = [
17 M: unix cwd ( -- path )
20 M: unix cd ( path -- ) [ chdir ] unix-system-call drop ;
22 CONSTANT: read-flags flags{ O_RDONLY }
24 : open-read ( path -- fd ) read-flags file-mode open-file ;
26 M: unix (file-reader) ( path -- stream )
27 open-read <fd> init-fd <input-port> ;
29 CONSTANT: write-flags flags{ O_WRONLY O_CREAT O_TRUNC }
31 : open-write ( path -- fd )
32 write-flags file-mode open-file ;
34 M: unix (file-writer) ( path -- stream )
35 open-write <fd> init-fd <output-port> ;
37 CONSTANT: append-flags flags{ O_WRONLY O_APPEND O_CREAT }
39 : open-append ( path -- fd )
41 append-flags file-mode open-file |dispose
42 dup 0 SEEK_END [ lseek ] unix-system-call drop
45 M: unix (file-appender) ( path -- stream )
46 open-append <fd> init-fd <output-port> ;
48 M: unix home "HOME" os-env ;