Skip to content

Instantly share code, notes, and snippets.

@alsamitech
Last active May 20, 2021 15:52
Show Gist options
  • Select an option

  • Save alsamitech/286558325c16b44d2f183787e9c42738 to your computer and use it in GitHub Desktop.

Select an option

Save alsamitech/286558325c16b44d2f183787e9c42738 to your computer and use it in GitHub Desktop.
read_file - Reads a file from disk.
char* read_file(char* filenm, long unsigned int* len){
char* buf=0;
FILE* f=fopen(filenm, "rb");
if(f){
fseek(f,0,SEEK_END);
*len=ftell(f);
fseek(f,0,SEEK_SET);
buf=(char*)calloc(1, *len);
if(buf)
fread(buf, 1, *len, f);
fclose(f);
}
return buf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment