Skip to content

Instantly share code, notes, and snippets.

@yuikns
Last active August 29, 2015 13:57
Show Gist options
  • Save yuikns/9807331 to your computer and use it in GitHub Desktop.
Save yuikns/9807331 to your computer and use it in GitHub Desktop.
void file_copy(const char * dest, const char* src)
{
FILE * fsrc = fopen(src,"rb");
FILE * fdest = fopen(dest,"wb");
fseek(fsrc,0L,SEEK_END);
long sz = ftell(fsrc);
rewind(fsrc);
unsigned char * buff = (unsigned char *)malloc(sizeof(unsigned char) * sz);
fread(buff,sz,sizeof(unsigned char),fsrc);
fwrite(buff,sz,sizeof(unsigned char),fdest);
free(buff);
fclose(fsrc);
fclose(fdest);
}
void file_copy2(const char * dest, const char* src)
{
FILE * fsrc = fopen(src,"rb");
FILE * fdest = fopen(dest,"wb");
rewind(fsrc);
unsigned char buff[1024];
size_t sz;
while((sz = fread(buff,1,1024,fsrc)) > 0 )
{
fwrite(buff,1,sz,fdest);
}
fclose(fsrc);
fclose(fdest);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment