From 7a3d4314d12d641baa0666385a3e47856e6dd35d Mon Sep 17 00:00:00 2001 From: armink Date: Mon, 19 Dec 2016 11:15:23 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E3=80=90=E5=A2=9E=E5=8A=A0=E3=80=91e?= =?UTF-8?q?log=5Fmemcpy=20=E6=96=B9=E6=B3=95=EF=BC=8C=E6=8F=90=E5=8D=87?= =?UTF-8?q?=E4=BA=86=20Flash=20=E6=8F=92=E4=BB=B6=E8=B7=A8=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E7=9A=84=E5=85=BC=E5=AE=B9=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: armink --- easylogger/inc/elog.h | 3 ++- easylogger/plugins/flash/elog_flash.c | 6 +++--- easylogger/plugins/flash/elog_flash.h | 2 +- easylogger/src/elog_utils.c | 24 +++++++++++++++++++++++- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/easylogger/inc/elog.h b/easylogger/inc/elog.h index 85801f0..fd81886 100644 --- a/easylogger/inc/elog.h +++ b/easylogger/inc/elog.h @@ -50,7 +50,7 @@ extern "C" { #define ELOG_LVL_TOTAL_NUM 6 /* EasyLogger software version number */ -#define ELOG_SW_VERSION "1.11.25" +#define ELOG_SW_VERSION "1.12.19" /* EasyLogger assert for developer. */ #ifdef ELOG_ASSERT_ENABLE @@ -206,6 +206,7 @@ size_t elog_async_get_line_log(char *log, size_t size); /* elog_utils.c */ size_t elog_strcpy(size_t cur_len, char *dst, const char *src); size_t elog_cpyln(char *line, const char *log, size_t len); +void *elog_memcpy(void *dst, const void *src, size_t count); #ifdef __cplusplus } diff --git a/easylogger/plugins/flash/elog_flash.c b/easylogger/plugins/flash/elog_flash.c index caf61cf..a75bda1 100644 --- a/easylogger/plugins/flash/elog_flash.c +++ b/easylogger/plugins/flash/elog_flash.c @@ -179,7 +179,7 @@ void elog_flash_write(const char *log, size_t size) { while (true) { if (cur_buf_size + size > ELOG_FLASH_BUF_SIZE) { write_size = ELOG_FLASH_BUF_SIZE - cur_buf_size; - memcpy(log_buf + cur_buf_size, log + write_index, write_size); + elog_memcpy(log_buf + cur_buf_size, log + write_index, write_size); write_index += write_size; size -= write_size; cur_buf_size += write_size; @@ -190,7 +190,7 @@ void elog_flash_write(const char *log, size_t size) { /* lock flash log buffer */ log_buf_lock(); } else { - memcpy(log_buf + cur_buf_size, log + write_index, size); + elog_memcpy(log_buf + cur_buf_size, log + write_index, size); cur_buf_size += size; break; } @@ -202,7 +202,7 @@ void elog_flash_write(const char *log, size_t size) { result = ef_log_write((uint32_t *) log, write_size_temp); /* write last word alignment data */ if ((result == EF_NO_ERR) && (write_size_temp != size)) { - memcpy(write_overage_c, log + write_size_temp, size - write_size_temp); + elog_memcpy(write_overage_c, log + write_size_temp, size - write_size_temp); ef_log_write((uint32_t *) write_overage_c, 4); } #endif diff --git a/easylogger/plugins/flash/elog_flash.h b/easylogger/plugins/flash/elog_flash.h index 60f2c46..5300b22 100644 --- a/easylogger/plugins/flash/elog_flash.h +++ b/easylogger/plugins/flash/elog_flash.h @@ -41,7 +41,7 @@ extern "C" { #endif /* EasyLogger flash log plugin's software version number */ -#define ELOG_FLASH_SW_VERSION "1.10.11" +#define ELOG_FLASH_SW_VERSION "1.12.19" /* elog_flash.c */ ElogErrCode elog_flash_init(void); diff --git a/easylogger/src/elog_utils.c b/easylogger/src/elog_utils.c index c4f9754..3817d7e 100644 --- a/easylogger/src/elog_utils.c +++ b/easylogger/src/elog_utils.c @@ -80,8 +80,8 @@ size_t elog_strcpy(size_t cur_len, char *dst, const char *src) { size_t elog_cpyln(char *line, const char *log, size_t len) { size_t newline_len = strlen(ELOG_NEWLINE_SIGN), copy_size = 0; - assert(log); assert(line); + assert(log); while (len--) { *line++ = *log++; @@ -92,3 +92,25 @@ size_t elog_cpyln(char *line, const char *log, size_t len) { } return copy_size; } + +/** + * This function will copy memory content from source address to destination + * address. + * + * @param dst the address of destination memory + * @param src the address of source memory + * @param count the copied length + * + * @return the address of destination memory + */ +void *elog_memcpy(void *dst, const void *src, size_t count) { + char *tmp = (char *) dst, *s = (char *) src; + + assert(dst); + assert(src); + + while (count--) + *tmp++ = *s++; + + return dst; +}