-
-
Save m1nuz/b08e113ca0a69694171a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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