From 5b0ab02d65a2764e27f186bd4e7b4b738ef7b61a Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Wed, 27 Feb 2008 01:55:49 -0600 Subject: [PATCH] add unix.stat --- extra/unix/stat/linux/32/32.factor | 54 ++++++++++++++++++++++++++++++ extra/unix/stat/linux/64/64.factor | 54 ++++++++++++++++++++++++++++++ extra/unix/stat/linux/linux.factor | 11 ++++++ extra/unix/stat/stat.factor | 11 ++++++ 4 files changed, 130 insertions(+) create mode 100644 extra/unix/stat/linux/32/32.factor create mode 100644 extra/unix/stat/linux/64/64.factor create mode 100644 extra/unix/stat/linux/linux.factor create mode 100644 extra/unix/stat/stat.factor diff --git a/extra/unix/stat/linux/32/32.factor b/extra/unix/stat/linux/32/32.factor new file mode 100644 index 0000000000..4525fd3879 --- /dev/null +++ b/extra/unix/stat/linux/32/32.factor @@ -0,0 +1,54 @@ + +USING: kernel alien.syntax math ; + +IN: unix.stat + +! Ubuntu 8.04 32-bit + +C-STRUCT: stat + { "dev_t" "st_dev" } + { "ushort" "__pad1" } + { "ino_t" "st_ino" } + { "mode_t" "st_mode" } + { "nlink_t" "st_nlink" } + { "uid_t" "st_uid" } + { "gid_t" "st_gid" } + { "dev_t" "st_rdev" } + { "ushort" "__pad2" } + { "off_t" "st_size" } + { "blksize_t" "st_blksize" } + { "blkcnt_t" "st_blocks" } + { "timespec" "st_atim" } + { "timespec" "st_mtim" } + { "timespec" "st_ctim" } + { "ulong" "unused4" } + { "ulong" "unused5" } ; + +FUNCTION: int __xstat ( int ver, char* pathname, stat* buf ) ; +FUNCTION: int __lxstat ( int ver, char* pathname, stat* buf ) ; + +: stat ( pathname buf -- int ) 3 -rot __xstat ; +: lstat ( pathname buf -- int ) 3 -rot __lxstat ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: S_IFMT OCT: 170000 ; ! These bits determine file type. + +: S_IFDIR OCT: 40000 ; ! Directory. +: S_IFCHR OCT: 20000 ; ! Character device. +: S_IFBLK OCT: 60000 ; ! Block device. +: S_IFREG OCT: 100000 ; ! Regular file. +: S_IFIFO OCT: 010000 ; ! FIFO. +: S_IFLNK OCT: 120000 ; ! Symbolic link. +: S_IFSOCK OCT: 140000 ; ! Socket. + +: S_ISTYPE ( mode mask -- val ) >r S_IFMT bitand r> = ; + +: S_ISREG ( mode -- value ) S_IFREG S_ISTYPE ; +: S_ISDIR ( mode -- value ) S_IFDIR S_ISTYPE ; +: S_ISCHR ( mode -- value ) S_IFCHR S_ISTYPE ; +: S_ISBLK ( mode -- value ) S_IFBLK S_ISTYPE ; +: S_ISFIFO ( mode -- value ) S_IFIFO S_ISTYPE ; +: S_ISLNK ( mode -- value ) S_IFLNK S_ISTYPE ; +: S_ISSOCK ( mode -- value ) S_IFSOCK S_ISTYPE ; + diff --git a/extra/unix/stat/linux/64/64.factor b/extra/unix/stat/linux/64/64.factor new file mode 100644 index 0000000000..3281af91d5 --- /dev/null +++ b/extra/unix/stat/linux/64/64.factor @@ -0,0 +1,54 @@ + +USING: kernel alien.syntax math ; + +IN: unix.stat + +! Ubuntu 7.10 64-bit + +C-STRUCT: stat + { "dev_t" "st_dev" } + { "ino_t" "st_ino" } + { "nlink_t" "st_nlink" } + { "mode_t" "st_mode" } + { "uid_t" "st_uid" } + { "gid_t" "st_gid" } + { "int" "pad0" } + { "dev_t" "st_rdev" } + { "off_t" "st_size" } + { "blksize_t" "st_blksize" } + { "blkcnt_t" "st_blocks" } + { "timespec" "st_atim" } + { "timespec" "st_mtim" } + { "timespec" "st_ctim" } + { "long" "__unused0" } + { "long" "__unused1" } + { "long" "__unused2" } ; + +FUNCTION: int __xstat ( int ver, char* pathname, stat* buf ) ; +FUNCTION: int __lxstat ( int ver, char* pathname, stat* buf ) ; + +: stat ( pathname buf -- int ) 3 -rot __xstat ; +: lstat ( pathname buf -- int ) 3 -rot __lxstat ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: S_IFMT OCT: 170000 ; ! These bits determine file type. + +: S_IFDIR OCT: 40000 ; ! Directory. +: S_IFCHR OCT: 20000 ; ! Character device. +: S_IFBLK OCT: 60000 ; ! Block device. +: S_IFREG OCT: 100000 ; ! Regular file. +: S_IFIFO OCT: 010000 ; ! FIFO. +: S_IFLNK OCT: 120000 ; ! Symbolic link. +: S_IFSOCK OCT: 140000 ; ! Socket. + +: S_ISTYPE ( mode mask -- val ) >r S_IFMT bitand r> = ; + +: S_ISREG ( mode -- value ) S_IFREG S_ISTYPE ; +: S_ISDIR ( mode -- value ) S_IFDIR S_ISTYPE ; +: S_ISCHR ( mode -- value ) S_IFCHR S_ISTYPE ; +: S_ISBLK ( mode -- value ) S_IFBLK S_ISTYPE ; +: S_ISFIFO ( mode -- value ) S_IFIFO S_ISTYPE ; +: S_ISLNK ( mode -- value ) S_IFLNK S_ISTYPE ; +: S_ISSOCK ( mode -- value ) S_IFSOCK S_ISTYPE ; + diff --git a/extra/unix/stat/linux/linux.factor b/extra/unix/stat/linux/linux.factor new file mode 100644 index 0000000000..71248a59f1 --- /dev/null +++ b/extra/unix/stat/linux/linux.factor @@ -0,0 +1,11 @@ + +USING: system combinators vocabs.loader ; + +IN: unix.stat + +cell-bits + { + { 32 [ "unix.stat.linux.32" require ] } + { 64 [ "unix.stat.linux.64" require ] } + } +case diff --git a/extra/unix/stat/stat.factor b/extra/unix/stat/stat.factor new file mode 100644 index 0000000000..a3165fe214 --- /dev/null +++ b/extra/unix/stat/stat.factor @@ -0,0 +1,11 @@ + +USING: system combinators vocabs.loader ; + +IN: unix.stat + +{ + { [ linux? ] [ "unix.stat.linux" require ] } + { [ t ] [ ] } +} +cond +