]> gitweb.factorcode.org Git - factor.git/blob - basis/unix/utmpx/utmpx.factor
git: fix tests
[factor.git] / basis / unix / utmpx / utmpx.factor
1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.c-types alien.data alien.syntax
4 continuations io.encodings.string io.encodings.utf8 kernel
5 sequences system unix.ffi vocabs ;
6 IN: unix.utmpx
7
8 CONSTANT: EMPTY 0
9 CONSTANT: RUN_LVL 1
10 CONSTANT: BOOT_TIME 2
11 CONSTANT: OLD_TIME 3
12 CONSTANT: NEW_TIME 4
13 CONSTANT: INIT_PROCESS 5
14 CONSTANT: LOGIN_PROCESS 6
15 CONSTANT: USER_PROCESS 7
16 CONSTANT: DEAD_PROCESS 8
17 CONSTANT: ACCOUNTING 9
18 CONSTANT: SIGNATURE 10
19 CONSTANT: SHUTDOWN_TIME 11
20
21 FUNCTION: void setutxent ( )
22 FUNCTION: void endutxent ( )
23 FUNCTION: utmpx* getutxent ( )
24 FUNCTION: utmpx* getutxid ( utmpx* id )
25 FUNCTION: utmpx* getutxline ( utmpx* line )
26 FUNCTION: utmpx* pututxline ( utmpx* utx )
27
28 TUPLE: utmpx-record user id line pid type timestamp host ;
29
30 HOOK: new-utmpx-record os ( -- utmpx-record )
31
32 HOOK: utmpx>utmpx-record os ( utmpx -- utmpx-record )
33
34 : memory>string ( alien n -- string )
35     memory>byte-array utf8 decode [ 0 = ] trim-tail ;
36
37 M: unix new-utmpx-record
38     utmpx-record new ;
39
40 : with-utmpx ( quot -- )
41     setutxent [ endutxent ] finally ; inline
42
43 : all-utmpx ( -- seq )
44     [
45         [ getutxent dup ]
46         [ utmpx>utmpx-record ]
47         produce nip
48     ] with-utmpx ;
49
50 "unix.utmpx." os name>> append require