- fr = f_open(&to_fd, to->p_path, FA_WRITE|FA_CREATE_ALWAYS);
- } else
- fr = f_open(&to_fd, to->p_path, FA_WRITE|FA_CREATE_NEW);
+ if (flags & F_FLAG) {
+ /* Remove existing destination file name create a new file. */
+ f_chmod(to->p_path,0, AM_RDO);
+ f_unlink(to->p_path);
+ open_mode = FA_WRITE|FA_CREATE_NEW;
+ } else {
+ /* Overwrite existing destination file name. */
+ open_mode = FA_WRITE|FA_CREATE_ALWAYS;
+ }
+ } else {
+ open_mode = FA_WRITE|FA_CREATE_NEW;
+ }
+ fr = f_open(&to_fd, to->p_path, open_mode);