Last active
May 24, 2019 21:50
-
-
Save monokrome/e97d381ca4842e38a364a4f79c36750e to your computer and use it in GitHub Desktop.
Fast function for moving files.
This file contains hidden or 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
/** 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