Add already opened file logic

This commit is contained in:
li_zan 2021-05-08 17:00:11 +08:00
parent 96d2f2910e
commit 602c9f6dfa
1 changed files with 4 additions and 4 deletions

View File

@ -46,7 +46,7 @@ FileOpInfo GetFsOpInfo(void)
return g_fsOp;
}
LittleFsHandleStruct *GetFreeFd(const char *fileName, int *fd)
LittleFsHandleStruct *LfsAllocFd(const char *fileName, int *fd)
{
int len = strlen(fileName) + 1;
@ -229,11 +229,11 @@ int LfsOpen(const char *pathName, int openFlag, int mode)
int fd = INVALID_FD;
// if file is already open, return invalid fd
if (CheckFileIsOpen(pathName)) {
if (pathName == NULL || CheckFileIsOpen(pathName)) {
goto errout;
}
LittleFsHandleStruct *fsHandle = GetFreeFd(pathName, &fd);
LittleFsHandleStruct *fsHandle = LfsAllocFd(pathName, &fd);
if (fd == INVALID_FD) {
goto errout;
}
@ -283,8 +283,8 @@ int LfsClose(int fd)
return ret;
}
ret = lfs_file_close(&g_lfs, &(g_handle[fd].file));
pthread_mutex_lock(&g_FslocalMutex);
ret = lfs_file_close(&g_lfs, &(g_handle[fd].file));
g_handle[fd].useFlag = 0;
if (g_handle[fd].pathName != NULL) {
free(g_handle[fd].pathName);