system-info.linux: clean up and implement os-version

db4
Slava Pestov 2011-09-08 21:59:03 -07:00
parent c57c26b3be
commit d06f97eb99
2 changed files with 28 additions and 17 deletions

View File

@ -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

View 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 ;
M: linux os-version release ;