#1924 - Copy function implemented on Taranis - Uses around 64bytes in

RAM
This commit is contained in:
bsongis
2015-01-20 21:48:14 +01:00
parent 4e9ac498d0
commit bbae10fae1
8 changed files with 121 additions and 38 deletions
+44
View File
@@ -141,3 +141,47 @@ bool listSdFiles(const char *path, const char *extension, const uint8_t maxlen,
return s_menu_count;
}
const char *fileCopy(const char *filename, const char *srcDir, const char *destDir)
{
FIL srcFile;
FIL dstFile;
char buf[256];
UINT read = sizeof(buf);
UINT written = sizeof(buf);
char path[2*CLIPBOARD_PATH_LEN+1];
char *tmp = strAppend(path, srcDir, CLIPBOARD_PATH_LEN);
*tmp++ = '/';
strAppend(tmp, filename, CLIPBOARD_PATH_LEN);
FRESULT result = f_open(&srcFile, path, FA_OPEN_EXISTING | FA_READ);
if (result != FR_OK) {
return SDCARD_ERROR(result);
}
tmp = strAppend(path, destDir, CLIPBOARD_PATH_LEN);
*tmp++ = '/';
strAppend(tmp, filename, CLIPBOARD_PATH_LEN);
result = f_open(&dstFile, path, FA_CREATE_ALWAYS | FA_WRITE);
if (result != FR_OK) {
return SDCARD_ERROR(result);
}
while (result==FR_OK && read==sizeof(buf) && written==sizeof(buf)) {
result = f_read(&srcFile, buf, sizeof(buf), &read);
if (result == FR_OK) {
result = f_write(&dstFile, buf, read, &written);
}
}
f_close(&dstFile);
f_close(&srcFile);
if (result != FR_OK) {
return SDCARD_ERROR(result);
}
return NULL;
}