Cleaned up bugs with stream implementation

Principle was that we may have read all the content from the
underlying pipe (s.t. it set the EoF flag) but we haven't actually
iterated the content.
This commit is contained in:
2025-08-29 08:28:32 +01:00
parent cc56a2ee2b
commit 29d2453288
2 changed files with 12 additions and 5 deletions

13
main.c
View File

@@ -20,14 +20,18 @@
int main(void)
{
stream_t stream = {0};
// const char data[] = "Hello, world!";
// const sv_t sv = SV(data, ARRSIZE(data) - 1);
stream_t stream = {0};
const char data[] = "Hello, world!";
const sv_t sv = SV(data, ARRSIZE(data) - 1);
char filename[] = "test.txt";
// stream_init_string(&stream, NULL, sv);
// stream_init_file(&stream, "test.txt");
// FILE *fp = fopen(filename, "rb");
// stream_init_file(&stream, filename, fp);
stream_init_file(&stream, "stdin", stdin);
printf("[debug]: setup stream pipe\n");
do
{
@@ -36,5 +40,6 @@ int main(void)
} while (!stream_eoc(&stream));
printf("%lu/%lu\n", stream.position, stream_size(&stream));
stream_stop(&stream);
// fclose(fp);
return 0;
}

View File

@@ -142,7 +142,9 @@ char stream_next(stream_t *stream)
char stream_peek(stream_t *stream)
{
if (stream_eos(stream))
// If we've reached end of stream, and end of content, there's really nothing
// to check here.
if (stream_eoc(stream) && stream_eos(stream))
return '\0';
switch (stream->type)