]> gitweb.factorcode.org Git - factor.git/blob - extra/system-info/linux/linux.factor
Specialized array overhaul
[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 ;
6 SPECIALIZED-ARRAY: char
7 IN: system-info.linux
8
9 : (uname) ( buf -- int )
10     "int" f "uname" { "char*" } alien-invoke ;
11
12 : uname ( -- seq )
13     65536 <char-array> [ (uname) io-error ] keep
14     "\0" split harvest [ utf8 decode ] map
15     6 "" pad-tail ;
16
17 : sysname ( -- string ) uname first ;
18 : nodename ( -- string ) uname second ;
19 : release ( -- string ) uname third ;
20 : version ( -- string ) uname fourth ;
21 : machine ( -- string ) uname 4 swap nth ;
22 : domainname ( -- string ) uname 5 swap nth ;
23
24 : kernel-version ( -- seq )
25     release ".-" split harvest 5 "" pad-tail ;