Add already opened file logic
This commit is contained in:
parent
cd292f8428
commit
94c0727e1d
|
@ -46,16 +46,22 @@ FileOpInfo GetFsOpInfo(void)
|
||||||
return g_fsOp;
|
return g_fsOp;
|
||||||
}
|
}
|
||||||
|
|
||||||
LittleFsHandleStruct *GetFreeFd(int *fd)
|
LittleFsHandleStruct *GetFreeFd(const char *fileName, int *fd)
|
||||||
{
|
{
|
||||||
|
int len = strlen() + 1;
|
||||||
|
|
||||||
pthread_mutex_lock(&g_FslocalMutex);
|
pthread_mutex_lock(&g_FslocalMutex);
|
||||||
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 == 0) {
|
if (g_handle[i].useFlag == 0) {
|
||||||
*fd = i;
|
*fd = i;
|
||||||
g_handle[i].useFlag = 1;
|
g_handle[i].useFlag = 1;
|
||||||
|
g_handle[i].pathName = (char *)malloc(len);
|
||||||
|
if (g_handle[i].pathName) {
|
||||||
|
memcpy_s(g_handle[i].pathName, len, fileName, len);
|
||||||
|
}
|
||||||
pthread_mutex_unlock(&g_FslocalMutex);
|
pthread_mutex_unlock(&g_FslocalMutex);
|
||||||
return &(g_handle[i]);
|
return &(g_handle[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&g_FslocalMutex);
|
pthread_mutex_unlock(&g_FslocalMutex);
|
||||||
*fd = INVALID_FD;
|
*fd = INVALID_FD;
|
||||||
|
@ -228,7 +234,7 @@ int LfsOpen(const char *pathName, int openFlag, int mode)
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
LittleFsHandleStruct *fsHandle = GetFreeFd(&fd);
|
LittleFsHandleStruct *fsHandle = GetFreeFd(pathName, &fd);
|
||||||
if (fd == INVALID_FD) {
|
if (fd == INVALID_FD) {
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue