Skip to content

Instantly share code, notes, and snippets.

@monokrome monokrome/move.c forked from Unlimiter/move.c
Last active May 24, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.