Add already opened file logic
This commit is contained in:
parent
4aeaf030a2
commit
3a4a8b0680
|
@ -68,18 +68,16 @@ LittleFsHandleStruct *GetFreeFd(const char *fileName, int *fd)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckFileIsOpen(const char *fileName, int *fd)
|
bool CheckFileIsOpen(const char *fileName)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < LITTLE_FS_MAX_OPEN_FILES; i++) {
|
for (int i = 0; i < LITTLE_FS_MAX_OPEN_FILES; i++) {
|
||||||
if (g_handle[i].useFlag == 1) {
|
if (g_handle[i].useFlag == 1) {
|
||||||
if (strcmp(g_handle[i].pathName, fileName) == 0) {
|
if (strcmp(g_handle[i].pathName, fileName) == 0) {
|
||||||
*fd = i;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*fd = INVALID_FD;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,8 +228,9 @@ int LfsOpen(const char *pathName, int openFlag, int mode)
|
||||||
{
|
{
|
||||||
int fd = INVALID_FD;
|
int fd = INVALID_FD;
|
||||||
|
|
||||||
if (CheckFileIsOpen(pathName, &fd)) {
|
// if file is already open, return invalid fd
|
||||||
return fd;
|
if (CheckFileIsOpen(pathName)) {
|
||||||
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
LittleFsHandleStruct *fsHandle = GetFreeFd(pathName, &fd);
|
LittleFsHandleStruct *fsHandle = GetFreeFd(pathName, &fd);
|
||||||
|
|
Loading…
Reference in New Issue