system-info.linux: clean up and implement os-version
parent
c57c26b3be
commit
d06f97eb99
|
@ -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
|
|
@ -1,27 +1,22 @@
|
||||||
! Copyright (C) 2008 Doug Coleman.
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: unix alien alien.c-types kernel math sequences strings
|
USING: alien.c-types alien.syntax byte-arrays io
|
||||||
io.backend.unix splitting io.encodings.utf8 io.encodings.string
|
io.encodings.string io.encodings.utf8 io.streams.byte-array
|
||||||
specialized-arrays alien.syntax system-info ;
|
kernel sequences splitting strings system system-info unix ;
|
||||||
SPECIALIZED-ARRAY: char
|
|
||||||
IN: system-info.linux
|
IN: system-info.linux
|
||||||
|
|
||||||
FUNCTION-ALIAS: (uname)
|
FUNCTION-ALIAS: (uname)
|
||||||
int uname ( c-string buf ) ;
|
int uname ( c-string buf ) ;
|
||||||
|
|
||||||
: uname ( -- seq )
|
: uname ( -- seq )
|
||||||
65536 <char-array> [ (uname) io-error ] keep
|
65536 <byte-array> [ (uname) io-error ] keep >string
|
||||||
"\0" split harvest [ utf8 decode ] map
|
"\0" split harvest dup length 6 assert= ;
|
||||||
6 "" pad-tail ;
|
|
||||||
|
|
||||||
: sysname ( -- string ) uname first ;
|
: sysname ( -- string ) 0 uname nth ;
|
||||||
: nodename ( -- string ) uname second ;
|
: nodename ( -- string ) 1 uname nth ;
|
||||||
: release ( -- string ) uname third ;
|
: release ( -- string ) 2 uname nth ;
|
||||||
: version ( -- string ) uname fourth ;
|
: version ( -- string ) 3 uname nth ;
|
||||||
: machine ( -- string ) uname 4 swap nth ;
|
: machine ( -- string ) 4 uname nth ;
|
||||||
: domainname ( -- string ) uname 5 swap nth ;
|
: domainname ( -- string ) 5 uname nth ;
|
||||||
|
|
||||||
: kernel-version ( -- seq )
|
M: linux os-version release ;
|
||||||
release ".-" split harvest 5 "" pad-tail ;
|
|
||||||
|
|
||||||
M: linux os-version f ;
|
|
Loading…
Reference in New Issue