Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.