Skip to content

Instantly share code, notes, and snippets.

@m1nuz
Forked from snipsnipsnip/rwgetc.c
Last active August 29, 2015 14:09
Show Gist options
  • Save m1nuz/b08e113ca0a69694171a to your computer and use it in GitHub Desktop.
Save m1nuz/b08e113ca0a69694171a to your computer and use it in GitHub Desktop.
// feof equivalent for SDL_rwops
int rweof(SDL_RWops *ctx) {
return SDL_RWsize(ctx) == SDL_RWtell(ctx);
}
// fgetc equivalent for SDL_rwops
int rwgetc(SDL_RWops *rw) {
char c;
return SDL_RWread(rw, &c, 1, 1) == 1 ? c : EOF;
}
// fgets equivalent for SDL_rwops
char *rwgets(char *buf, int count, SDL_RWops *rw) {
Sint64 base = SDL_RWtell(rw);
SDL_RWread(rw, buf, count, 1);
char *end = strchr(buf, '\n');
ptrdiff_t offs = end - buf;
if (!end)
end = buf;
SDL_RWseek(rw, base + offs + 1, RW_SEEK_SET);
*end = '\0';
return buf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment