mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
setenv
and unsetenv
for windows fix
This commit is contained in:
parent
f5fa43d2fa
commit
e638e47af5
25
vlib/os/os.v
25
vlib/os/os.v
@ -106,7 +106,6 @@ fn parse_windows_cmd_line(cmd byteptr) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read_file reads the file in `path` and returns the contents.
|
// read_file reads the file in `path` and returns the contents.
|
||||||
//pub fn read_file(path string) ?string {
|
|
||||||
pub fn read_file(path string) ?string {
|
pub fn read_file(path string) ?string {
|
||||||
mut res := ''
|
mut res := ''
|
||||||
mut mode := 'rb'
|
mut mode := 'rb'
|
||||||
@ -293,21 +292,29 @@ pub fn getenv(key string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn setenv(name string, value string, overwrite bool) int {
|
pub fn setenv(name string, value string, overwrite bool) int {
|
||||||
$if windows {
|
$if windows {
|
||||||
|
format := '$name=$value'
|
||||||
|
|
||||||
}
|
if overwrite {
|
||||||
$else {
|
return C._putenv(format.cstr())
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
$else {
|
||||||
return C.setenv(name.cstr(), value.cstr(), overwrite)
|
return C.setenv(name.cstr(), value.cstr(), overwrite)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unsetenv(name string) int {
|
pub fn unsetenv(name string) int {
|
||||||
$if windows {
|
$if windows {
|
||||||
|
format := '${name}='
|
||||||
|
|
||||||
}
|
return C._putenv(format.cstr())
|
||||||
$else {
|
}
|
||||||
|
$else {
|
||||||
return C.unsetenv(name.cstr())
|
return C.unsetenv(name.cstr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// `file_exists` returns true if `path` exists.
|
// `file_exists` returns true if `path` exists.
|
||||||
|
Loading…
Reference in New Issue
Block a user