]> gitweb.factorcode.org Git - factor.git/blob - extra/system-info/linux/linux.factor
8a943927c7174648c1713b9a6e8891afd1324488
[factor.git] / extra / system-info / linux / linux.factor
1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: unix alien alien.c-types kernel math sequences strings
4 io.backend.unix splitting io.encodings.utf8 io.encodings.string
5 specialized-arrays.char ;
6 IN: system-info.linux
7
8 : (uname) ( buf -- int )
9     "int" f "uname" { "char*" } alien-invoke ;
10
11 : uname ( -- seq )
12     65536 <char-array> [ (uname) io-error ] keep
13     "\0" split harvest [ utf8 decode ] map
14     6 "" pad-tail ;
15
16 : sysname ( -- string ) uname first ;
17 : nodename ( -- string ) uname second ;
18 : release ( -- string ) uname third ;
19 : version ( -- string ) uname fourth ;
20 : machine ( -- string ) uname 4 swap nth ;
21 : domainname ( -- string ) uname 5 swap nth ;
22
23 : kernel-version ( -- seq )
24     release ".-" split harvest 5 "" pad-tail ;