mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-28 05:26:18 +08:00
chore: do not use strdup in c99 (#4983)
Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
This commit is contained in:
@@ -282,6 +282,7 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
|
|||||||
do {
|
do {
|
||||||
entry = readdir(handle->dir_p);
|
entry = readdir(handle->dir_p);
|
||||||
if(entry) {
|
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);
|
if(entry->d_type == DT_DIR) snprintf(fn, strlen(entry->d_name), "/%s", entry->d_name);
|
||||||
else lv_strcpy(fn, entry->d_name);
|
else lv_strcpy(fn, entry->d_name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,16 +78,12 @@ int32_t lv_strcmp(const char * s1, const char * s2)
|
|||||||
char * lv_strdup(const char * src)
|
char * lv_strdup(const char * src)
|
||||||
{
|
{
|
||||||
/*strdup uses malloc, so use the lv_malloc when LV_USE_STDLIB_MALLOC is not LV_STDLIB_CLIB */
|
/*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;
|
size_t len = lv_strlen(src) + 1;
|
||||||
char * dst = lv_malloc(len);
|
char * dst = lv_malloc(len);
|
||||||
if(dst == NULL) return NULL;
|
if(dst == NULL) return NULL;
|
||||||
|
|
||||||
lv_memcpy(dst, src, len); /*do memcpy is faster than strncpy when length is known*/
|
lv_memcpy(dst, src, len); /*do memcpy is faster than strncpy when length is known*/
|
||||||
return dst;
|
return dst;
|
||||||
#else
|
|
||||||
return strdup(src);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
|
|||||||
Reference in New Issue
Block a user