Updated fopen. ZString.len does not output number of Char32. Add example.

This commit is contained in:
Christoffer Lerno
2023-02-23 09:08:51 +01:00
committed by Christoffer Lerno
parent b175b9318a
commit f86aa136cb
7 changed files with 103 additions and 3 deletions

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by the MIT license
// a copy of which can be found in the LICENSE_STDLIB file.
module std::core::env;
import libc;
enum CompilerOptLevel
{
O0,
@@ -152,3 +152,56 @@ macro bool os_is_posix()
$endswitch;
}
/**
* @param [&in] name
* @require name.len > 0
**/
fn String! get_var(String name)
{
$if (COMPILER_LIBC_AVAILABLE && OS_TYPE != OsType.WIN32):
@pool()
{
ZString val = libc::getenv(name.zstrtcopy());
return val ? val.as_str() : SearchResult.MISSING!;
};
$else:
return "";
$endif;
}
/**
* @param [&in] name
* @param [&in] value
* @require name.len > 0
**/
fn void set_var(String name, String value, bool overwrite = true)
{
$if (COMPILER_LIBC_AVAILABLE && OS_TYPE != OsType.WIN32):
@pool()
{
if (libc::setenv(name.zstrtcopy(), value.zstrcopy(), (int)overwrite))
{
unreachable();
}
};
$endif;
}
/**
* @param [&in] name
* @require name.len > 0
**/
fn void clear_var(String name)
{
$if (COMPILER_LIBC_AVAILABLE && OS_TYPE != OsType.WIN32):
@pool()
{
if (libc::unsetenv(name.zstrtcopy()))
{
unreachable();
}
};
$endif;
}