lambda-calc-1/istream/file/read.c
2025-01-20 13:40:51 -06:00

49 lines
836 B
C

#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
#include <debug.h>
#include "struct.h"
#include "read.h"
void file_istream_read(
struct istream* super)
{
ENTER;
struct file_istream* this = (void*) super;
if (this->i < this->n)
{
super->c = this->buffer[this->i++];
dpvc(super->c);
}
else
{
ssize_t read_retval = read(this->fd, this->buffer, sizeof(this->buffer));
if (read_retval < 0)
{
TODO;
}
else if (!read_retval)
{
super->c = 0;
}
else
{
this->i = 0;
this->n = (size_t) read_retval;
super->c = this->buffer[this->i++];
dpvc(super->c);
}
}
EXIT;
}