translate directory-type flags to our factor symbols

db4
Doug Coleman 2008-11-19 16:22:42 -06:00
parent 3ea773fa80
commit 25d9fd68fc
4 changed files with 31 additions and 14 deletions

View File

@ -117,8 +117,8 @@ M: unix stat>file-info ( stat -- file-info )
[ stat-st_blksize >>blocksize ]
} cleave ;
M: unix stat>type ( stat -- type )
stat-st_mode S_IFMT bitand {
: n>file-type ( n -- type )
S_IFMT bitand {
{ S_IFREG [ +regular-file+ ] }
{ S_IFDIR [ +directory+ ] }
{ S_IFCHR [ +character-device+ ] }
@ -129,6 +129,9 @@ M: unix stat>type ( stat -- type )
[ drop +unknown+ ]
} case ;
M: unix stat>type ( stat -- type )
stat-st_mode n>file-type ;
! Linux has no extra fields in its stat struct
os {
{ macosx [ "io.unix.files.bsd" require ] }
@ -150,7 +153,7 @@ os {
M: unix >directory-entry ( byte-array -- directory-entry )
[ dirent-d_name utf8 alien>string ]
[ dirent-d_type ] bi directory-entry boa ;
[ dirent-d_type dirent-type>file-type ] bi directory-entry boa ;
M: unix (directory-entries) ( path -- seq )
[

View File

@ -83,16 +83,6 @@ C-STRUCT: passwd
: SEEK_CUR 1 ; inline
: SEEK_END 2 ; inline
: DT_UNKNOWN 0 ; inline
: DT_FIFO 1 ; inline
: DT_CHR 2 ; inline
: DT_DIR 4 ; inline
: DT_BLK 6 ; inline
: DT_REG 8 ; inline
: DT_LNK 10 ; inline
: DT_SOCK 12 ; inline
: DT_WHT 14 ; inline
os {
{ macosx [ "unix.bsd.macosx" require ] }
{ freebsd [ "unix.bsd.freebsd" require ] }

View File

@ -4,7 +4,7 @@ USING: alien alien.c-types alien.syntax kernel libc
sequences continuations byte-arrays strings math namespaces
system combinators vocabs.loader qualified accessors
stack-checker macros locals generalizations unix.types
debugger io prettyprint ;
debugger io prettyprint io.files ;
IN: unix
: PROT_NONE 0 ; inline
@ -20,6 +20,29 @@ IN: unix
: NGROUPS_MAX 16 ; inline
: DT_UNKNOWN 0 ; inline
: DT_FIFO 1 ; inline
: DT_CHR 2 ; inline
: DT_DIR 4 ; inline
: DT_BLK 6 ; inline
: DT_REG 8 ; inline
: DT_LNK 10 ; inline
: DT_SOCK 12 ; inline
: DT_WHT 14 ; inline
: dirent-type>file-type ( ch -- type )
{
{ DT_BLK [ +block-device+ ] }
{ DT_CHR [ +character-device+ ] }
{ DT_DIR [ +directory+ ] }
{ DT_LNK [ +symbolic-link+ ] }
{ DT_SOCK [ +socket+ ] }
{ DT_FIFO [ +fifo+ ] }
{ DT_REG [ +regular-file+ ] }
{ DT_WHT [ +whiteout+ ] }
[ drop +unknown+ ]
} case ;
C-STRUCT: group
{ "char*" "gr_name" }
{ "char*" "gr_passwd" }

View File

@ -175,6 +175,7 @@ SYMBOL: +character-device+
SYMBOL: +block-device+
SYMBOL: +fifo+
SYMBOL: +socket+
SYMBOL: +whiteout+
SYMBOL: +unknown+
! File metadata