mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Upgrade of mingw in CI. Fix problems using reflection on interface types #1203. Improved debug information on defer. $foreach doesn't create an implicit syntactic scope. Error if `@if` depends on `@if`. Updated Linux stacktrace. Fix of default argument stacktrace. Allow linking libraries directly by file path. Improve inlining warning messages. Added `index_of_char_from`. Compiler crash using enum nameof from different module #1205. Removed unused fields in find_msvc. Use vswhere to find msvc. Update tests for LLVM 19
44 lines
929 B
C
44 lines
929 B
C
module std::io;
|
|
|
|
struct LimitReader (InStream)
|
|
{
|
|
InStream wrapped_stream;
|
|
usz limit;
|
|
}
|
|
|
|
/**
|
|
* @param [&inout] wrapped_stream "The stream to read from"
|
|
* @param limit "The max limit to read"
|
|
**/
|
|
fn LimitReader* LimitReader.init(&self, InStream wrapped_stream, usz limit)
|
|
{
|
|
*self = { .wrapped_stream = wrapped_stream, .limit = limit };
|
|
return self;
|
|
}
|
|
|
|
fn void! LimitReader.close(&self) @dynamic
|
|
{
|
|
if (&self.wrapped_stream.close) return self.wrapped_stream.close();
|
|
}
|
|
|
|
|
|
fn usz! LimitReader.read(&self, char[] bytes) @dynamic
|
|
{
|
|
if (self.limit == 0) return IoError.EOF?;
|
|
usz m = min(bytes.len, self.limit);
|
|
usz n = self.wrapped_stream.read(bytes[:m])!;
|
|
self.limit -= n;
|
|
return n;
|
|
}
|
|
|
|
fn char! LimitReader.read_byte(&self) @dynamic
|
|
{
|
|
if (self.limit == 0) return IoError.EOF?;
|
|
defer try self.limit--;
|
|
return self.wrapped_stream.read_byte();
|
|
}
|
|
|
|
fn usz! LimitReader.available(&self) @inline @dynamic
|
|
{
|
|
return self.limit;
|
|
} |