]> gitweb.factorcode.org Git - factor.git/blob - basis/environment/winnt/winnt.factor
518a7d5d7a29d44be485cfe9438354f958ce3aa6
[factor.git] / basis / environment / winnt / winnt.factor
1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.strings fry io.encodings.utf16n kernel
4 splitting windows windows.kernel32 system environment
5 alien.c-types sequences windows.errors io.streams.memory
6 io.encodings io ;
7 IN: environment.winnt
8
9 << "TCHAR" require-c-array >>
10
11 M: winnt os-env ( key -- value )
12     MAX_UNICODE_PATH "TCHAR" <c-array>
13     [ dup length GetEnvironmentVariable ] keep over 0 = [
14         2drop f
15     ] [
16         nip utf16n alien>string
17     ] if ;
18
19 M: winnt set-os-env ( value key -- )
20     swap SetEnvironmentVariable win32-error=0/f ;
21
22 M: winnt unset-os-env ( key -- )
23     f SetEnvironmentVariable 0 = [
24         GetLastError ERROR_ENVVAR_NOT_FOUND =
25         [ win32-error ] unless
26     ] when ;
27
28 M: winnt (os-envs) ( -- seq )
29     GetEnvironmentStrings [
30         <memory-stream> [
31             utf16n decode-input
32             [ "\0" read-until drop dup empty? not ] [ ] produce nip
33         ] with-input-stream*
34     ] [ FreeEnvironmentStrings win32-error=0/f ] bi ;