]> gitweb.factorcode.org Git - factor.git/blob - basis/environment/unix/unix.factor
ec41e919d8e2ce9157ad4930481cfca12fcc86e4
[factor.git] / basis / environment / unix / unix.factor
1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien alien.c-types alien.data alien.strings
4 alien.syntax kernel layouts sequences system unix
5 environment io.encodings.utf8 unix.utilities vocabs.loader
6 combinators alien.accessors unix.ffi ;
7 IN: environment.unix
8
9 HOOK: environ os ( -- void* )
10
11 M: unix environ ( -- void* ) &: environ ;
12
13 M: unix os-env ( key -- value ) getenv ;
14
15 M: unix set-os-env ( value key -- ) swap 1 setenv io-error ;
16
17 M: unix unset-os-env ( key -- ) unsetenv io-error ;
18
19 M: unix (os-envs) ( -- seq )
20     environ *void* utf8 alien>strings ;
21
22 : set-void* ( value alien -- ) 0 set-alien-cell ;
23
24 M: unix (set-os-envs) ( seq -- )
25     utf8 strings>alien malloc-byte-array environ set-void* ;
26
27 os {
28     { macosx [ "environment.unix.macosx" require ] }
29     [ drop ]
30 } case