diff --git a/basis/io/unix/files/files.factor b/basis/io/unix/files/files.factor index 3f254e7713..98206bc992 100644 --- a/basis/io/unix/files/files.factor +++ b/basis/io/unix/files/files.factor @@ -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 ) [ diff --git a/basis/unix/bsd/bsd.factor b/basis/unix/bsd/bsd.factor index bd66c5253e..bf426ad867 100644 --- a/basis/unix/bsd/bsd.factor +++ b/basis/unix/bsd/bsd.factor @@ -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 ] } diff --git a/basis/unix/unix.factor b/basis/unix/unix.factor index 4950daef2c..ca8a7a2e60 100644 --- a/basis/unix/unix.factor +++ b/basis/unix/unix.factor @@ -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" } diff --git a/core/io/files/files.factor b/core/io/files/files.factor index ca8125d936..25f6f36e7c 100644 --- a/core/io/files/files.factor +++ b/core/io/files/files.factor @@ -175,6 +175,7 @@ SYMBOL: +character-device+ SYMBOL: +block-device+ SYMBOL: +fifo+ SYMBOL: +socket+ +SYMBOL: +whiteout+ SYMBOL: +unknown+ ! File metadata