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 * INCLUDES
*********************/ *********************/
@ -24,7 +23,7 @@
*********************/ *********************/
#ifndef LV_FS_PC_PATH #ifndef LV_FS_PC_PATH
#ifndef WIN32 #ifndef WIN32
# define LV_FS_PC_PATH "./" /*Projet root*/ #define LV_FS_PC_PATH "/fs" /*Projet root*/
#else #else
#define LV_FS_PC_PATH ".\\" /*Projet root*/ #define LV_FS_PC_PATH ".\\" /*Projet root*/
#endif #endif
@ -44,7 +43,6 @@ typedef DIR * dir_t;
typedef HANDLE dir_t; typedef HANDLE dir_t;
#endif #endif
/********************** /**********************
* STATIC PROTOTYPES * 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 = ""; const char * flags = "";
if(mode == LV_FS_MODE_WR) flags = "wb"; if(mode == LV_FS_MODE_WR)
else if(mode == LV_FS_MODE_RD) flags = "rb"; flags = "wb";
else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD)) flags = "rb+"; 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)*/ /*Make the path relative to the current directory (the projects root folder)*/
#ifndef WIN32 #ifndef WIN32
char buf[256]; char buf[256];
sprintf(buf, LV_FS_PC_PATH "/%s", path); sprintf(buf, LV_FS_PC_PATH "/%s", path);
printf("%s\n", buf);
#else #else
char buf[256]; char buf[256];
sprintf(buf, LV_FS_PC_PATH "\\%s", path); sprintf(buf, LV_FS_PC_PATH "\\%s", path);
#endif #endif
file_t f = fopen(buf, flags); 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*/ /*Be sure we are the beginning of the file*/
fseek(f, 0, SEEK_SET); 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; return LV_FS_RES_OK;
} }
/** /**
* Close an opened file * Close an opened file
* @param drv pointer to a driver where this function belongs * @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*/ fflush(*fp); /*If not syncronized fclose can write the truncated part*/
uint32_t p = ftell(*fp); uint32_t p = ftell(*fp);
ftruncate(fileno(*fp), p); // ftruncate(fileno(*fp), p);
return LV_FS_RES_OK; 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); int r = rename(old, new);
if(r == 0) return LV_FS_RES_OK; if(r == 0)
else return LV_FS_RES_UNKNOWN; 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; return res;
} }
#ifdef WIN32 #ifdef WIN32
static char next_fn[256]; static char next_fn[256];
#endif #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; continue;
} else { } else {
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) if(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
{
sprintf(next_fn, "/%s", fdata.cFileName); sprintf(next_fn, "/%s", fdata.cFileName);
} else { } else {
sprintf(next_fn, "%s", fdata.cFileName); 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); entry = readdir(*dp);
if(entry) { if(entry) {
if(entry->d_type == DT_DIR) sprintf(fn, "/%s", entry->d_name); if(entry->d_type == DT_DIR)
else strcpy(fn, entry->d_name); sprintf(fn, "/%s", entry->d_name);
else
strcpy(fn, entry->d_name);
} else { } else {
strcpy(fn, ""); 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; continue;
} else { } else {
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) if(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
{
sprintf(next_fn, "/%s", fdata.cFileName); sprintf(next_fn, "/%s", fdata.cFileName);
} else { } else {
sprintf(next_fn, "%s", fdata.cFileName); sprintf(next_fn, "%s", fdata.cFileName);