2005-03-29 19:58:22 -05:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
IN: files
|
2005-04-17 18:34:09 -04:00
|
|
|
! We want the system call stat to shadow the word stat we define
|
|
|
|
USING: alien io-internals kernel math namespaces unix-internals ;
|
2005-03-29 19:58:22 -05:00
|
|
|
|
|
|
|
: cd ( dir -- )
|
|
|
|
"void" "libc" "chdir" [ "char*" ] alien-invoke ;
|
|
|
|
|
|
|
|
: stat ( path -- [ dir? mode size mtime ] )
|
2005-04-17 18:34:09 -04:00
|
|
|
<stat> tuck stat 0 < [
|
2005-03-29 19:58:22 -05:00
|
|
|
drop f
|
|
|
|
] [
|
|
|
|
[
|
|
|
|
dup stat-mode dup S_ISDIR ,
|
|
|
|
S_IFMT bitnot bitand ,
|
|
|
|
dup stat-size ,
|
|
|
|
stat-mtime ,
|
|
|
|
] make-list
|
|
|
|
] ifte ;
|
|
|
|
|
|
|
|
: (directory) ( path -- list )
|
2005-04-17 18:34:09 -04:00
|
|
|
opendir [
|
2005-03-29 19:58:22 -05:00
|
|
|
[
|
2005-04-17 18:34:09 -04:00
|
|
|
[ dirent-name , ] [ dup readdir null>f ] while
|
|
|
|
] make-list swap closedir
|
2005-03-29 19:58:22 -05:00
|
|
|
] [
|
|
|
|
[ ]
|
|
|
|
] ifte* ;
|
|
|
|
|
|
|
|
: cwd ( -- str )
|
2005-04-17 18:34:09 -04:00
|
|
|
<string-box> dup 255 getcwd io-error string-box-value ;
|
2005-04-22 20:09:46 -04:00
|
|
|
|
|
|
|
IN: streams
|
|
|
|
|
|
|
|
: <file-reader> ( path -- stream ) open-read <reader> ;
|
|
|
|
|
|
|
|
: <file-writer> ( path -- stream ) open-write <writer> ;
|