Skip to content

Instantly share code, notes, and snippets.

@YellowAfterlife
Created May 10, 2014 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YellowAfterlife/12301418236eee311f86 to your computer and use it in GitHub Desktop.
Save YellowAfterlife/12301418236eee311f86 to your computer and use it in GitHub Desktop.
dllx char* file_text_get(char* file) {
FILE *f;
char *r;
long fl;
fopen_s(&f, file, "r");
if (f) {
fseek(f, 0L, SEEK_END);
fl = ftell(f);
rewind(f);
if (r = (char*)calloc(1, fl + 1)) {
if (fread(r, fl, 1, f)) {
return r;
} else free(r);
}
fclose(f);
}
// errors yield empty strings:
r = (char*)calloc(1, 1);
r[0] = 0;
return r;
}
dllx double file_text_put(char* file, char* text) {
FILE *f;
fopen_s(&f, file, "w");
if (f) {
if (fputs(text, f)) {
return 1;
}
fclose(f);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment