mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Updated fopen. ZString.len does not output number of Char32. Add example.
This commit is contained in:
committed by
Christoffer Lerno
parent
b175b9318a
commit
f86aa136cb
@@ -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;
|
||||
}
|
||||
@@ -376,7 +376,7 @@ fn String ZString.as_str(ZString str)
|
||||
return ((char*)str)[:str.len()];
|
||||
}
|
||||
|
||||
fn usz ZString.len(ZString str)
|
||||
fn usz ZString.char_len(ZString str)
|
||||
{
|
||||
usz len = 0;
|
||||
char* ptr = (char*)str;
|
||||
@@ -387,3 +387,11 @@ fn usz ZString.len(ZString str)
|
||||
return len;
|
||||
}
|
||||
|
||||
fn usz ZString.len(ZString str)
|
||||
{
|
||||
usz len = 0;
|
||||
char* ptr = (char*)str;
|
||||
while (char c = ptr++[0]) len++;
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user