Created
May 10, 2014 13:19
-
-
Save YellowAfterlife/12301418236eee311f86 to your computer and use it in GitHub Desktop.
This file contains 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
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