]> gitweb.factorcode.org Git - factor.git/commitdiff
system-info.linux: clean up and implement os-version
authorSlava Pestov <slava@factorcode.org>
Fri, 9 Sep 2011 04:59:03 +0000 (21:59 -0700)
committerSlava Pestov <slava@factorcode.org>
Fri, 9 Sep 2011 04:59:03 +0000 (21:59 -0700)
basis/system-info/linux/linux-tests.factor [new file with mode: 0644]
basis/system-info/linux/linux.factor

diff --git a/basis/system-info/linux/linux-tests.factor b/basis/system-info/linux/linux-tests.factor
new file mode 100644 (file)
index 0000000..48f4d01
--- /dev/null
@@ -0,0 +1,16 @@
+USING: system-info.linux strings splitting sequences
+tools.test ;
+IN: system-info.linux.tests
+
+[ 6 ] [ uname length ] unit-test
+
+[ t ] [ sysname    string? ] unit-test
+[ t ] [ nodename   string? ] unit-test
+[ t ] [ release    string? ] unit-test
+[ t ] [ version    string? ] unit-test
+[ t ] [ machine    string? ] unit-test
+[ t ] [ domainname string? ] unit-test
+
+[ t ] [
+    release "." split1 drop { "2" "3" } member?
+] unit-test
index d5ee9915be24ea64962eb1a2622b6488986c5c0b..13121a851e9b6d48084504447240db1649d0a716 100644 (file)
@@ -1,27 +1,22 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: unix alien alien.c-types kernel math sequences strings
-io.backend.unix splitting io.encodings.utf8 io.encodings.string
-specialized-arrays alien.syntax system-info ;
-SPECIALIZED-ARRAY: char
+USING: alien.c-types alien.syntax byte-arrays io
+io.encodings.string io.encodings.utf8 io.streams.byte-array
+kernel sequences splitting strings system system-info unix ;
 IN: system-info.linux
 
 FUNCTION-ALIAS: (uname)
     int uname ( c-string buf ) ;
 
 : uname ( -- seq )
-    65536 <char-array> [ (uname) io-error ] keep
-    "\0" split harvest [ utf8 decode ] map
-    6 "" pad-tail ;
+    65536 <byte-array> [ (uname) io-error ] keep >string
+    "\0" split harvest dup length 6 assert= ;
 
-: sysname ( -- string ) uname first ;
-: nodename ( -- string ) uname second ;
-: release ( -- string ) uname third ;
-: version ( -- string ) uname fourth ;
-: machine ( -- string ) uname 4 swap nth ;
-: domainname ( -- string ) uname 5 swap nth ;
+: sysname ( -- string ) 0 uname nth ;
+: nodename ( -- string ) 1 uname nth ;
+: release ( -- string ) 2 uname nth ;
+: version ( -- string ) 3 uname nth ;
+: machine ( -- string ) 4 uname nth ;
+: domainname ( -- string ) 5 uname nth ;
 
-: kernel-version ( -- seq )
-    release ".-" split harvest 5 "" pad-tail ;
-
-M: linux os-version f ;
\ No newline at end of file
+M: linux os-version release ;
\ No newline at end of file