]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/io/files/info/unix/unix.factor
use radix literals
[factor.git] / basis / io / files / info / unix / unix.factor
index eedf8de47ae35e93ef859a46bd6e359fd83902b2..8b1701cfeae1ea5e42c89e1db0c695d7d663ebb1 100644 (file)
@@ -1,13 +1,13 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel system math math.bitwise strings arrays
-sequences combinators combinators.short-circuit alien.c-types
-vocabs.loader calendar calendar.unix io.files.info
-io.files.types io.backend io.directories unix unix.stat
-unix.time unix.users unix.groups classes.struct
-specialized-arrays literals ;
-SPECIALIZED-ARRAY: timeval
+USING: accessors alien.c-types alien.data arrays calendar
+calendar.unix classes.struct combinators
+combinators.short-circuit io.backend io.directories
+io.files.info io.files.types kernel literals math math.bitwise
+sequences specialized-arrays strings system unix unix.ffi
+unix.groups unix.stat unix.time unix.users vocabs ;
 IN: io.files.info.unix
+SPECIALIZED-ARRAY: timeval
 
 TUPLE: unix-file-system-info < file-system-info
 block-size preferred-block-size
@@ -17,7 +17,7 @@ name-max flags id ;
 
 HOOK: new-file-system-info os ( --  file-system-info )
 
-M: unix new-file-system-info ( -- ) unix-file-system-info new ;
+M: unix new-file-system-info unix-file-system-info new ;
 
 HOOK: file-system-statfs os ( path -- statfs )
 
@@ -109,7 +109,7 @@ M: unix stat>type ( stat -- type )
 
 : chmod-set-bit ( path mask ? -- )
     [ dup stat-mode ] 2dip
-    [ bitor ] [ unmask ] if chmod io-error ;
+    [ bitor ] [ unmask ] if [ chmod ] unix-system-call drop ;
 
 GENERIC# file-mode? 1 ( obj mask -- ? )
 
@@ -119,24 +119,24 @@ M: file-info file-mode? [ permissions>> ] dip mask? ;
 
 PRIVATE>
 
-CONSTANT: UID           OCT: 0004000
-CONSTANT: GID           OCT: 0002000
-CONSTANT: STICKY        OCT: 0001000
-CONSTANT: USER-ALL      OCT: 0000700
-CONSTANT: USER-READ     OCT: 0000400
-CONSTANT: USER-WRITE    OCT: 0000200
-CONSTANT: USER-EXECUTE  OCT: 0000100
-CONSTANT: GROUP-ALL     OCT: 0000070
-CONSTANT: GROUP-READ    OCT: 0000040
-CONSTANT: GROUP-WRITE   OCT: 0000020
-CONSTANT: GROUP-EXECUTE OCT: 0000010
-CONSTANT: OTHER-ALL     OCT: 0000007
-CONSTANT: OTHER-READ    OCT: 0000004
-CONSTANT: OTHER-WRITE   OCT: 0000002
-CONSTANT: OTHER-EXECUTE OCT: 0000001
-CONSTANT: ALL-READ      OCT: 0000444
-CONSTANT: ALL-WRITE     OCT: 0000222
-CONSTANT: ALL-EXECUTE   OCT: 0000111
+CONSTANT: UID           0o0004000
+CONSTANT: GID           0o0002000
+CONSTANT: STICKY        0o0001000
+CONSTANT: USER-ALL      0o0000700
+CONSTANT: USER-READ     0o0000400
+CONSTANT: USER-WRITE    0o0000200
+CONSTANT: USER-EXECUTE  0o0000100
+CONSTANT: GROUP-ALL     0o0000070
+CONSTANT: GROUP-READ    0o0000040
+CONSTANT: GROUP-WRITE   0o0000020
+CONSTANT: GROUP-EXECUTE 0o0000010
+CONSTANT: OTHER-ALL     0o0000007
+CONSTANT: OTHER-READ    0o0000004
+CONSTANT: OTHER-WRITE   0o0000002
+CONSTANT: OTHER-EXECUTE 0o0000001
+CONSTANT: ALL-READ      0o0000444
+CONSTANT: ALL-WRITE     0o0000222
+CONSTANT: ALL-EXECUTE   0o0000111
 
 : uid? ( obj -- ? ) UID file-mode? ;
 : gid? ( obj -- ? ) GID file-mode? ;
@@ -174,7 +174,7 @@ CONSTANT: ALL-EXECUTE   OCT: 0000111
 : set-other-execute ( path ? -- ) OTHER-EXECUTE swap chmod-set-bit ;
 
 : set-file-permissions ( path n -- )
-    [ normalize-path ] dip chmod io-error ;
+    [ normalize-path ] dip [ chmod ] unix-system-call drop ;
 
 : file-permissions ( path -- n )
     normalize-path file-info permissions>> ;
@@ -195,14 +195,14 @@ M: unix copy-file-and-info ( from to -- )
 
 : timestamps>byte-array ( timestamps -- byte-array )
     [ [ timestamp>timeval ] [ \ timeval <struct> ] if* ] map
-    >timeval-array ;
+    timeval >c-array ;
 
 PRIVATE>
 
 : set-file-times ( path timestamps -- )
     #! set access, write
     [ normalize-path ] dip
-    timestamps>byte-array utimes io-error ;
+    timestamps>byte-array [ utimes ] unix-system-call drop ;
 
 : set-file-access-time ( path timestamp -- )
     f 2array set-file-times ;
@@ -211,7 +211,8 @@ PRIVATE>
     f swap 2array set-file-times ;
 
 : set-file-ids ( path uid gid -- )
-    [ normalize-path ] 2dip [ -1 or ] bi@ chown io-error ;
+    [ normalize-path ] 2dip [ -1 or ] bi@
+    [ chown ] unix-system-call drop ;
 
 GENERIC: set-file-user ( path string/id -- )
 
@@ -285,3 +286,5 @@ PRIVATE>
         { +regular-file+ [ file-type>executable ] }
         [ drop file-type>executable ]
     } case ;
+
+"io.files.info.unix." os name>> append require