--- /dev/null
+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
! 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