void copy_file(FILINFO *fs, uint_fast8_t dne)
{
- static char buf[MAXBSIZE];
FIL from_fd, to_fd;
UINT rcount, wcount;
//FILINFO to_stat;
//char *p;
FRESULT fr;
-debug("==== copy_file(): dne: %u\n", dne);
+ int buf_size = get_freemem() / 512 * 512;
+ uint8_t * buf = (uint8_t *) malloc(buf_size);
+ if (buf == NULL) {
+ free(buf);
+ err(PSTR("cp: Out of Memory!\n"));
+ return;
+ }
+
+debug("==== copy_file(): dne: %u, buf_zize: %d\n", dne, buf_size);
debug(" from:'%s' to:'%s'\n", from->p_path, to->p_path);
+
if ((fr = f_open(&from_fd, from->p_path, FA_READ)) != FR_OK) {
err(PSTR("%s: %S"), from->p_path, rctostr(fr));
return;
*/
if (!dne) {
if (flags & I_FLAG) {
- printf_P(PSTR("overwrite %s? "), to->p_path);
+ printf_P(PSTR("overwrite '%s'? "), to->p_path);
if (!confirm_yes()) {
f_close(&from_fd);
return;
return;
}
- while ((fr = f_read(&from_fd, buf, MAXBSIZE, &rcount)) == FR_OK &&
+ while ((fr = f_read(&from_fd, buf, buf_size, &rcount)) == FR_OK &&
rcount > 0) {
fr = f_write(&to_fd, buf, rcount, &wcount);
if (fr || wcount < rcount) {
command_ret_t do_pr_heap_avr(cmd_tbl_t *, uint_fast8_t, int, char * const []);
void printfreelist(const char * title);
+size_t get_freemem(void);
#ifdef DEBUG