Skip to content

Instantly share code, notes, and snippets.

@rygorous
Created November 21, 2011 20:43
Show Gist options
  • Save rygorous/1383867 to your computer and use it in GitHub Desktop.
Save rygorous/1383867 to your computer and use it in GitHub Desktop.
Read implementation
ErrorCode Read(BufferedStream *s, void *buffer, size_t numBytes)
{
U8 *dest = (U8 *)buffer;
while (numBytes) {
if (s->cursor == s->end)
s->Refill(s);
size_t count = min(numBytes, (size_t)(s->end - s->cursor));
memcpy(dest, s->cursor, count);
dest += count;
s->cursor += count;
numBytes -= count;
}
return s->error;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment