Skip to content

Instantly share code, notes, and snippets.

@monokrome
Last active May 24, 2019 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monokrome/e97d381ca4842e38a364a4f79c36750e to your computer and use it in GitHub Desktop.
Save monokrome/e97d381ca4842e38a364a4f79c36750e to your computer and use it in GitHub Desktop.
Fast function for moving files.
/** this was posted as a fast function for moving files... lolwat!? **/
/*
* Fast function for moving files.
* — Unlimiter
*/
// This function has been tested with 'https://norvig.com/big.txt' which has the size of 6488666 bytes, and the execution time was very close to null.
// At that point, it is very comparable to the 'mv' command on Linux.
void move(char* src_path, char* dest_path) {
#include <stdio.h>
FILE* src = fopen(src_path, "rb");
FILE* dest = fopen(dest_path, "wb");
fseek(src, 0, SEEK_END);
unsigned long long src_size = ftell(src);
rewind(src);
char* buf;
fread(buf, 1, src_size, src);
fwrite(buf, 1, src_size, dest);
remove(src_path);
}
// Uncomment the main function for testing through the command line.
/*
int main(int argc, char** argv) {
if (argc > 2) {
move(argv[1], argv[2]);
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment