Skip to content

Instantly share code, notes, and snippets.

@gsathya
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save gsathya/4421612211fb752ea6fb to your computer and use it in GitHub Desktop.

Select an option

Save gsathya/4421612211fb752ea6fb to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<unistd.h>
int main (int argc, char *argv[])
{
FILE *fp;
char test_buf[30];
fp = fopen("sdltest", "wb+");
if (!fp) {
printf("Could not open file\n");
return 0;
}
if (fwrite("1234567890", 10, 1, fp) != 1) {
printf("Could not write to file\n");
goto error;
}
fclose(fp);
fp = fopen("sdltest", "ab+");
if (!fp) {
printf("Could not open file\n");
return 0;
}
if (fwrite("1234567890", 10, 1, fp) != 1) {
printf("Could not write to file\n");
goto error;
}
fseek(fp, 0, SEEK_SET);
fread(test_buf, 20, 1, fp);
printf("Read %s\n", test_buf);
fseek(fp, -7, SEEK_END);
long len = ftell(fp);
if (len != 13) {
printf("Could not seek correctly\n");
printf("[DEBUG] len == %lu\n", len);
goto error;
}
error:
fclose(fp);
unlink("sdltest");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment