Skip to content

Instantly share code, notes, and snippets.

@snipsnipsnip
Last active May 11, 2022 00:17
Show Gist options
  • Save snipsnipsnip/306686 to your computer and use it in GitHub Desktop.
Save snipsnipsnip/306686 to your computer and use it in GitHub Desktop.
int rwgetc(SDL_RWops *rw)
/* 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)
{
int i;
buf[count - 1] = '\0';
for (i = 0; i < count - 1; i++)
{
if (SDL_RWread(rw, buf + i, 1, 1) != 1)
{
if (i == 0)
{
return NULL;
}
break;
}
if (buf[i] == '\n')
{
break;
}
}
buf[i] = '\0';
return buf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment