?? fs_frename.c
字號:
/*----------------------------------------------------------------------------
* R T L - F l a s h F i l e S y s t e m
*----------------------------------------------------------------------------
* Name: FS_FRENAME.C
* Purpose: File Rename Function
* Rev.: V3.22
*----------------------------------------------------------------------------
* This code is part of the RealView Run-Time Library.
* Copyright (c) 2004-2008 KEIL - An ARM Company. All rights reserved.
*---------------------------------------------------------------------------*/
#include <string.h> /* string and memory functions */
#include "File_Config.h"
/*--------------------------- frename ---------------------------------------*/
int frename (const char *oldname, const char *newname) {
/* Rename a file from 'oldname' to 'newname'. */
IOB *fcb;
int handle;
int drv2;
int i;
char newname_w_path[81];
/* Find an unused _iob structure. */
if ((handle = fs_find_iob ()) == EOF) {
return (1);
}
fcb = &_iob[handle];
fcb->drive = fs_get_drive (oldname);
if (fcb->drive != DRV_NONE) {
/* Skip drive letter 'X:' */
oldname += 2;
}
else {
fcb->drive = _DEF_DRIVE;
}
drv2 = fs_get_drive (newname);
if (drv2 != DRV_NONE) {
newname += 2;
if (drv2 != fcb->drive) {
/* If provided, both drives must be the same. */
return (1);
}
}
if (fcb->drive == DRV_MCARD) {
/* Find path part of old name. */
for (i = (strlen(oldname) - 1); i >= 0; i --) {
if (oldname[i] == '\\') {
break;
}
}
if (i) {
/* If path exists, add path to new name to search if it exists. */
memcpy(newname_w_path, oldname, i + 1);
newname_w_path[i+1] = 0;
strcat(newname_w_path, newname);
} else {
memcpy(newname_w_path, newname, strlen(newname));
}
/* Rename a file located on Flash Memory Card. */
if (fat_find_file (newname_w_path, fcb) == __TRUE) {
/* File with 'newname' already exists */
return (1);
}
if (fat_rename (oldname, newname, fcb) == __TRUE) {
return (0);
}
return (1);
}
/* Set drive parameters. */
if (fs_set_params (fcb) == __FALSE) {
return (1);
}
if (fs_Find_File (newname, fcb) == 0) {
/* File with 'newname' already exists */
return (1);
}
if (fs_Find_File (oldname, fcb) == 0) {
return (_frename (newname, fcb));
}
/* File with 'oldname' not found */
return (1);
}
/*----------------------------------------------------------------------------
* end of file
*---------------------------------------------------------------------------*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -