Update lv_fs_pc.c

This commit is contained in:
fvanroie 2021-02-06 19:36:11 +01:00
parent c71203439b
commit 3618305d42

View File

@ -3,7 +3,6 @@
*
*/
/*********************
* INCLUDES
*********************/
@ -24,7 +23,7 @@
*********************/
#ifndef LV_FS_PC_PATH
#ifndef WIN32
# define LV_FS_PC_PATH "./" /*Projet root*/
#define LV_FS_PC_PATH "/fs" /*Projet root*/
#else
#define LV_FS_PC_PATH ".\\" /*Projet root*/
#endif
@ -44,7 +43,6 @@ typedef DIR * dir_t;
typedef HANDLE dir_t;
#endif
/**********************
* STATIC PROTOTYPES
**********************/
@ -130,23 +128,29 @@ static lv_fs_res_t fs_open (lv_fs_drv_t * drv, void * file_p, const char * path,
const char * flags = "";
if(mode == LV_FS_MODE_WR) flags = "wb";
else if(mode == LV_FS_MODE_RD) flags = "rb";
else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD)) flags = "rb+";
if(mode == LV_FS_MODE_WR)
flags = "wb";
else if(mode == LV_FS_MODE_RD)
flags = "rb";
else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD))
flags = "rb+";
/*Make the path relative to the current directory (the projects root folder)*/
#ifndef WIN32
char buf[256];
sprintf(buf, LV_FS_PC_PATH "/%s", path);
printf("%s\n", buf);
#else
char buf[256];
sprintf(buf, LV_FS_PC_PATH "\\%s", path);
#endif
file_t f = fopen(buf, flags);
if(f == NULL) return LV_FS_RES_UNKNOWN;
if(f == NULL) {
printf("Failed to open %s\n", buf);
return LV_FS_RES_UNKNOWN;
}
/*Be sure we are the beginning of the file*/
fseek(f, 0, SEEK_SET);
@ -158,7 +162,6 @@ static lv_fs_res_t fs_open (lv_fs_drv_t * drv, void * file_p, const char * path,
return LV_FS_RES_OK;
}
/**
* Close an opened file
* @param drv pointer to a driver where this function belongs
@ -293,7 +296,7 @@ static lv_fs_res_t fs_trunc (lv_fs_drv_t * drv, void * file_p)
fflush(*fp); /*If not syncronized fclose can write the truncated part*/
uint32_t p = ftell(*fp);
ftruncate(fileno(*fp), p);
// ftruncate(fileno(*fp), p);
return LV_FS_RES_OK;
}
@ -315,8 +318,10 @@ static lv_fs_res_t fs_rename (lv_fs_drv_t * drv, const char * oldname, const cha
int r = rename(old, new);
if(r == 0) return LV_FS_RES_OK;
else return LV_FS_RES_UNKNOWN;
if(r == 0)
return LV_FS_RES_OK;
else
return LV_FS_RES_UNKNOWN;
}
/**
@ -337,7 +342,6 @@ static lv_fs_res_t fs_free (lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * fr
return res;
}
#ifdef WIN32
static char next_fn[256];
#endif
@ -380,8 +384,7 @@ static lv_fs_res_t fs_dir_open (lv_fs_drv_t * drv, void * dir_p, const char *pat
continue;
} else {
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
sprintf(next_fn, "/%s", fdata.cFileName);
} else {
sprintf(next_fn, "%s", fdata.cFileName);
@ -417,8 +420,10 @@ static lv_fs_res_t fs_dir_read (lv_fs_drv_t * drv, void * dir_p, char *fn)
entry = readdir(*dp);
if(entry) {
if(entry->d_type == DT_DIR) sprintf(fn, "/%s", entry->d_name);
else strcpy(fn, entry->d_name);
if(entry->d_type == DT_DIR)
sprintf(fn, "/%s", entry->d_name);
else
strcpy(fn, entry->d_name);
} else {
strcpy(fn, "");
}
@ -435,8 +440,7 @@ static lv_fs_res_t fs_dir_read (lv_fs_drv_t * drv, void * dir_p, char *fn)
continue;
} else {
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
sprintf(next_fn, "/%s", fdata.cFileName);
} else {
sprintf(next_fn, "%s", fdata.cFileName);