diff --git a/src/shuffle.c b/src/shuffle.c new file mode 100644 index 00000000..db9979e2 --- /dev/null +++ b/src/shuffle.c @@ -0,0 +1,24 @@ +#include "shuffle.h" + +#include +#include "string_utils.h" + +bool shuffle_file(char *filename) { + char *shuffle_command = NULL; + + #if defined(HAVE_SHUF) + shuffle_command = "shuf"; + #else + return false; + #endif + + char_array *command = char_array_new(); + + char_array_cat_printf(command, "%s -o %s %s", shuffle_command, filename, filename); + + int ret = system(char_array_get_string(command)); + + char_array_destroy(command); + + return ret == EXIT_SUCCESS; +} diff --git a/src/shuffle.h b/src/shuffle.h new file mode 100644 index 00000000..c715d08e --- /dev/null +++ b/src/shuffle.h @@ -0,0 +1,9 @@ +#ifndef HAVE_SHUFFLE_H +#define HAVE_SHUFFLE_H + +#include +#include + +bool shuffle_file(char *filename); + +#endif \ No newline at end of file