]> gitweb.factorcode.org Git - factor.git/blob - extra/unix/stat/stat.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / extra / unix / stat / stat.factor
1
2 USING: kernel system combinators alien.syntax alien.c-types
3        math io.unix.backend vocabs.loader unix ;
4
5 IN: unix.stat
6
7 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8 ! File Types
9 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10
11 : S_IFMT   OCT: 170000 ; ! These bits determine file type.
12
13 : S_IFDIR  OCT:  40000 ; inline   ! Directory.
14 : S_IFCHR  OCT:  20000 ; inline   ! Character device.
15 : S_IFBLK  OCT:  60000 ; inline   ! Block device.
16 : S_IFREG  OCT: 100000 ; inline   ! Regular file.
17 : S_IFIFO  OCT: 010000 ; inline   ! FIFO.
18 : S_IFLNK  OCT: 120000 ; inline   ! Symbolic link.
19 : S_IFSOCK OCT: 140000 ; inline   ! Socket.
20
21 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
22 ! File Access Permissions
23 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
24
25 ! Read, write, execute/search by owner
26 : S_IRWXU OCT: 0000700 ; inline    ! rwx mask owner
27 : S_IRUSR OCT: 0000400 ; inline    ! r owner
28 : S_IWUSR OCT: 0000200 ; inline    ! w owner
29 : S_IXUSR OCT: 0000100 ; inline    ! x owner
30 ! Read, write, execute/search by group
31 : S_IRWXG OCT: 0000070 ; inline    ! rwx mask group
32 : S_IRGRP OCT: 0000040 ; inline    ! r group
33 : S_IWGRP OCT: 0000020 ; inline    ! w group
34 : S_IXGRP OCT: 0000010 ; inline    ! x group
35 ! Read, write, execute/search by others
36 : S_IRWXO OCT: 0000007 ; inline    ! rwx mask other
37 : S_IROTH OCT: 0000004 ; inline    ! r other
38 : S_IWOTH OCT: 0000002 ; inline    ! w other
39 : S_IXOTH OCT: 0000001 ; inline    ! x other
40
41 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
42
43 FUNCTION: int chmod ( char* path, mode_t mode ) ;
44
45 FUNCTION: int fchmod ( int fd, mode_t mode ) ;
46
47 FUNCTION: int mkdir ( char* path, mode_t mode ) ;
48
49 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
50 <<
51   os
52   {
53     { linux   [ "unix.stat.linux"   require ] }
54     { macosx  [ "unix.stat.macosx"  require ] }
55     { freebsd [ "unix.stat.freebsd" require ] }
56     { netbsd  [ "unix.stat.netbsd"  require ] }
57     { openbsd [ "unix.stat.openbsd" require ] }
58   }
59   case
60 >>
61 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
62
63 : file-status ( pathname -- stat )
64     "stat" <c-object> dup >r
65     [ stat ] unix-system-call drop
66     r> ;
67
68 : link-status ( pathname -- stat )
69     "stat" <c-object> dup >r
70     [ lstat ] unix-system-call drop
71     r> ;