]> gitweb.factorcode.org Git - factor.git/blob - basis/environment/windows/windows.factor
2ff126c8871eec40aaa7bc4c7aacbd338b52930f
[factor.git] / basis / environment / windows / windows.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 windows.types system
5 environment alien.data sequences windows.errors
6 io.streams.memory io.encodings io specialized-arrays ;
7 SPECIALIZED-ARRAY: TCHAR
8 IN: environment.windows
9
10 M: windows os-env
11     MAX_UNICODE_PATH TCHAR <c-array>
12     [ dup length GetEnvironmentVariable ] keep over 0 = [
13         2drop f
14     ] [
15         nip alien>native-string
16     ] if ;
17
18 M: windows set-os-env
19     swap SetEnvironmentVariable win32-error=0/f ;
20
21 M: windows unset-os-env
22     f SetEnvironmentVariable 0 = [
23         GetLastError ERROR_ENVVAR_NOT_FOUND =
24         [ win32-error ] unless
25     ] when ;
26
27 M: windows (os-envs)
28     GetEnvironmentStrings [
29         [
30             utf16n decode-input
31             [ "\0" read-until drop dup empty? not ] [ ] produce nip
32         ] with-memory-reader
33     ] [ FreeEnvironmentStrings win32-error=0/f ] bi ;