|
@@ -327,3 +327,36 @@ void os_end_high_performance(os_performance_token_t *token)
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
+int os_copyfile(const char *file_path_in, const char *file_path_out)
|
|
|
+{
|
|
|
+ FILE *file_out = NULL;
|
|
|
+ FILE *file_in = NULL;
|
|
|
+ uint8_t data[4096];
|
|
|
+ int ret = -1;
|
|
|
+ size_t size;
|
|
|
+
|
|
|
+ if (os_file_exists(file_path_out))
|
|
|
+ return -1;
|
|
|
+
|
|
|
+ file_in = fopen(file_path_in, "rb");
|
|
|
+ if (!file_in)
|
|
|
+ return -1;
|
|
|
+
|
|
|
+ file_out = fopen(file_path_out, "ab+");
|
|
|
+ if (!file_out)
|
|
|
+ goto error;
|
|
|
+
|
|
|
+ do {
|
|
|
+ size = fread(data, 1, sizeof(data), file_in);
|
|
|
+ if (size)
|
|
|
+ size = fwrite(data, 1, size, file_out);
|
|
|
+ } while (size == sizeof(data));
|
|
|
+
|
|
|
+ ret = feof(file_in) ? 0 : -1;
|
|
|
+
|
|
|
+error:
|
|
|
+ if (file_out)
|
|
|
+ fclose(file_out);
|
|
|
+ fclose(file_in);
|
|
|
+ return ret;
|
|
|
+}
|