chore: do not use strdup in c99 (#4983)

Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
This commit is contained in:
Neo Xu
2023-12-12 02:50:13 +08:00
committed by GitHub
parent 3bb538b032
commit 2b53325f49
2 changed files with 1 additions and 4 deletions
+1
View File
@@ -282,6 +282,7 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
do {
entry = readdir(handle->dir_p);
if(entry) {
/*Note, DT_DIR is not defined in C99*/
if(entry->d_type == DT_DIR) snprintf(fn, strlen(entry->d_name), "/%s", entry->d_name);
else lv_strcpy(fn, entry->d_name);
}
-4
View File
@@ -78,16 +78,12 @@ int32_t lv_strcmp(const char * s1, const char * s2)
char * lv_strdup(const char * src)
{
/*strdup uses malloc, so use the lv_malloc when LV_USE_STDLIB_MALLOC is not LV_STDLIB_CLIB */
#if LV_USE_STDLIB_MALLOC != LV_STDLIB_CLIB
size_t len = lv_strlen(src) + 1;
char * dst = lv_malloc(len);
if(dst == NULL) return NULL;
lv_memcpy(dst, src, len); /*do memcpy is faster than strncpy when length is known*/
return dst;
#else
return strdup(src);
#endif
}
/**********************