mirror of
https://github.com/lvgl/lvgl.git
synced 2026-09-24 15:45:54 +08:00
refacter(conf): use defines for standard includes (#5767)
Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com> Co-authored-by: Neo Xu <neo.xu1990@gmail.com>
This commit is contained in:
co-authored by
Gabor Kiss-Vamosi
Neo Xu
parent
393c24c6e9
commit
352420cd54
@@ -171,6 +171,17 @@ void * LV_ATTRIBUTE_FAST_MEM lv_memmove(void * dst, const void * src, size_t len
|
||||
return dst;
|
||||
}
|
||||
|
||||
int32_t lv_memcmp(const void * p1, const void * p2, size_t len)
|
||||
{
|
||||
const char * s1 = (const char *) p1;
|
||||
const char * s2 = (const char *) p2;
|
||||
while(--len > 0 && (*s1 == *s2)) {
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
return *s1 - *s2;
|
||||
}
|
||||
|
||||
/* See https://en.cppreference.com/w/c/string/byte/strlen for reference */
|
||||
size_t lv_strlen(const char * str)
|
||||
{
|
||||
@@ -212,10 +223,20 @@ char * lv_strdup(const char * src)
|
||||
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*/
|
||||
lv_memcpy(dst, src, len); /*memcpy is faster than strncpy when length is known*/
|
||||
return dst;
|
||||
}
|
||||
|
||||
char * lv_strcat(char * dst, const char * src)
|
||||
{
|
||||
char * tmp = dst;
|
||||
while(*dst != '\0') {
|
||||
dst++;
|
||||
}
|
||||
lv_strcpy(dst, src);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "../../lv_conf_internal.h"
|
||||
#if LV_USE_STDLIB_MALLOC == LV_STDLIB_BUILTIN
|
||||
|
||||
#include <limits.h>
|
||||
#include "lv_tlsf.h"
|
||||
#include "../../stdlib/lv_string.h"
|
||||
#include "../../misc/lv_log.h"
|
||||
#include "../../misc/lv_assert.h"
|
||||
#include "../../misc/lv_types.h"
|
||||
|
||||
#undef printf
|
||||
#define printf LV_LOG_ERROR
|
||||
|
||||
@@ -41,10 +41,9 @@
|
||||
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "../../osal/lv_os.h"
|
||||
#include "../../misc/lv_ll.h"
|
||||
#include "../../misc/lv_types.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
|
||||
@@ -50,6 +50,11 @@ void * LV_ATTRIBUTE_FAST_MEM lv_memmove(void * dst, const void * src, size_t len
|
||||
return memmove(dst, src, len);
|
||||
}
|
||||
|
||||
int32_t lv_memcmp(const void * p1, const void * p2, size_t len)
|
||||
{
|
||||
return memcmp(p1, p2, len);
|
||||
}
|
||||
|
||||
size_t lv_strlen(const char * str)
|
||||
{
|
||||
return strlen(str);
|
||||
@@ -86,6 +91,11 @@ char * lv_strdup(const char * src)
|
||||
return dst;
|
||||
}
|
||||
|
||||
char * lv_strcat(char * dst, const char * src)
|
||||
{
|
||||
return strcat(dst, src);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
+1
-3
@@ -15,9 +15,7 @@ extern "C" {
|
||||
*********************/
|
||||
#include "../lv_conf_internal.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include "lv_string.h"
|
||||
|
||||
#include "../misc/lv_types.h"
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#define _LV_SPRINTF_H_
|
||||
|
||||
#if defined(__has_include)
|
||||
#if __has_include(<inttypes.h>)
|
||||
#include <inttypes.h>
|
||||
#if __has_include(LV_INTTYPES_INCLUDE)
|
||||
#include LV_INTTYPES_INCLUDE
|
||||
/* platform-specific printf format for int32_t, usually "d" or "ld" */
|
||||
#define LV_PRId32 PRId32
|
||||
#define LV_PRIu32 PRIu32
|
||||
@@ -28,9 +28,7 @@
|
||||
#define LV_PRIX32 "X"
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include "../misc/lv_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+19
-2
@@ -14,8 +14,7 @@ extern "C" {
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "../lv_conf_internal.h"
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "../misc/lv_types.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@@ -57,6 +56,15 @@ void lv_memset(void * dst, uint8_t v, size_t len);
|
||||
*/
|
||||
void * lv_memmove(void * dst, const void * src, size_t len);
|
||||
|
||||
/**
|
||||
* @brief This function will compare two memory blocks
|
||||
* @param p1 Pointer to the first memory block
|
||||
* @param p2 Pointer to the second memory block
|
||||
* @param len Number of bytes to compare
|
||||
* @return The difference between the value of the first unmatching byte.
|
||||
*/
|
||||
int32_t lv_memcmp(const void * p1, const void * p2, size_t len);
|
||||
|
||||
/**
|
||||
* Same as `memset(dst, 0x00, len)`.
|
||||
* @param dst pointer to the destination buffer
|
||||
@@ -107,6 +115,15 @@ int32_t lv_strcmp(const char * s1, const char * s2);
|
||||
*/
|
||||
char * lv_strdup(const char * src);
|
||||
|
||||
/**
|
||||
* @brief Copies the string pointed to by src, including the terminating null character,
|
||||
* to the end of the string pointed to by dst.
|
||||
* @param dst Pointer to the destination string where the content is to be appended.
|
||||
* @param src Pointer to the source of data to be copied.
|
||||
* @return A pointer to the destination string, which is dst.
|
||||
*/
|
||||
char * lv_strcat(char * dst, const char * src);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
@@ -55,6 +55,11 @@ size_t lv_strlen(const char * str)
|
||||
return rt_strlen(str);
|
||||
}
|
||||
|
||||
int32_t lv_memcmp(const void * p1, const void * p2, size_t len)
|
||||
{
|
||||
return rt_memcmp(p1, p2, len);
|
||||
}
|
||||
|
||||
char * lv_strncpy(char * dst, const char * src, size_t dest_size)
|
||||
{
|
||||
return rt_strncpy(dst, src, dest_size);
|
||||
@@ -72,17 +77,17 @@ int32_t lv_strcmp(const char * s1, const char * s2)
|
||||
|
||||
char * lv_strdup(const char * src)
|
||||
{
|
||||
/*strdup uses rt_malloc, so use the lv_malloc when LV_USE_STDLIB_MALLOC is not LV_STDLIB_RTTHREAD */
|
||||
#if LV_USE_STDLIB_MALLOC != LV_STDLIB_RTTHREAD
|
||||
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*/
|
||||
lv_memcpy(dst, src, len); /*memcpy is faster than strncpy when length is known*/
|
||||
return dst;
|
||||
#else
|
||||
return rt_strdup(src);
|
||||
#endif
|
||||
}
|
||||
|
||||
char * lv_strcat(char * dst, const char * src)
|
||||
{
|
||||
return strcat(dst, src);
|
||||
}
|
||||
|
||||
/**********************
|
||||
|
||||
Reference in New Issue
Block a user