/ Published in: C
loadfile(filename); returns NULL on fail or a pointer that should be free()d when no longer needed.
savefile(filename,data,dataSize); returns 0 on fail or 1 on success.
Expand |
Embed | Plain Text
void*loadfile(const char*const s){ FILE*f=fopen(s,"rb"); if(f){ fseek(f,0,SEEK_END); { const int ml=ftell(f); if(ml){ char*m=malloc(ml); if(m){ rewind(f); fread(m,1,ml,f); fclose(f); return m; } } } } return 0; } int savefile(const char*const s,const void*const m,const int ml){ FILE*f=fopen(s,"wb"); if(f){ int ok=fwrite(m,1,ml,f)==ml; fclose(f); return ok; } return 0; }
You need to login to post a comment.
