1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.c-types alien.data alien.syntax combinators
4 continuations io.encodings.string io.encodings.utf8 kernel
5 sequences strings unix calendar system accessors unix.time
6 calendar.unix vocabs.loader classes.struct ;
14 CONSTANT: INIT_PROCESS 5
15 CONSTANT: LOGIN_PROCESS 6
16 CONSTANT: USER_PROCESS 7
17 CONSTANT: DEAD_PROCESS 8
18 CONSTANT: ACCOUNTING 9
19 CONSTANT: SIGNATURE 10
20 CONSTANT: SHUTDOWN_TIME 11
22 FUNCTION: void setutxent ( ) ;
23 FUNCTION: void endutxent ( ) ;
24 FUNCTION: utmpx* getutxent ( ) ;
25 FUNCTION: utmpx* getutxid ( utmpx* id ) ;
26 FUNCTION: utmpx* getutxline ( utmpx* line ) ;
27 FUNCTION: utmpx* pututxline ( utmpx* utx ) ;
29 TUPLE: utmpx-record user id line pid type timestamp host ;
31 HOOK: new-utmpx-record os ( -- utmpx-record )
33 HOOK: utmpx>utmpx-record os ( utmpx -- utmpx-record )
35 : memory>string ( alien n -- string )
36 memory>byte-array utf8 decode [ 0 = ] trim-tail ;
38 M: unix new-utmpx-record
41 M: unix utmpx>utmpx-record ( utmpx -- utmpx-record )
42 [ new-utmpx-record ] dip \ utmpx memory>struct
44 [ ut_user>> _UTX_USERSIZE memory>string >>user ]
45 [ ut_id>> _UTX_IDSIZE memory>string >>id ]
46 [ ut_line>> _UTX_LINESIZE memory>string >>line ]
49 [ ut_tv>> timeval>unix-time >>timestamp ]
50 [ ut_host>> _UTX_HOSTSIZE memory>string >>host ]
53 : with-utmpx ( quot -- )
54 setutxent [ endutxent ] [ ] cleanup ; inline
56 : all-utmpx ( -- seq )
59 [ utmpx>utmpx-record ]
64 { macosx [ "unix.utmpx.macosx" require ] }
65 { netbsd [ "unix.utmpx.netbsd" require ] }