]> gitweb.factorcode.org Git - factor.git/blob - basis/io/files/unix/unix.factor
Merge branch 'master' into experimental
[factor.git] / basis / io / files / unix / unix.factor
1 ! Copyright (C) 2005, 2008 Slava Pestov, Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: unix byte-arrays kernel io.backend.unix math.bitwise
4 io.ports io.files io.files.private io.pathnames environment
5 destructors system ;
6 IN: io.files.unix
7
8 M: unix cwd ( -- path )
9     MAXPATHLEN [ <byte-array> ] keep getcwd
10     [ (io-error) ] unless* ;
11
12 M: unix cd ( path -- ) [ chdir ] unix-system-call drop ;
13
14 : read-flags ( -- n ) O_RDONLY ; inline
15
16 : open-read ( path -- fd ) O_RDONLY file-mode open-file ;
17
18 M: unix (file-reader) ( path -- stream )
19     open-read <fd> init-fd <input-port> ;
20
21 : write-flags ( -- n )
22     { O_WRONLY O_CREAT O_TRUNC } flags ; inline
23
24 : open-write ( path -- fd )
25     write-flags file-mode open-file ;
26
27 M: unix (file-writer) ( path -- stream )
28     open-write <fd> init-fd <output-port> ;
29
30 : append-flags ( -- n )
31     { O_WRONLY O_APPEND O_CREAT } flags ; inline
32
33 : open-append ( path -- fd )
34     [
35         append-flags file-mode open-file |dispose
36         dup 0 SEEK_END lseek io-error
37     ] with-destructors ;
38
39 M: unix (file-appender) ( path -- stream )
40     open-append <fd> init-fd <output-port> ;
41
42 M: unix home "HOME" os-env ;