From edccf1c07d6cf12a17ebb30e636f2ce6b6e19f6c Mon Sep 17 00:00:00 2001 From: HubretXie Date: Thu, 16 May 2019 10:24:54 +0800 Subject: [PATCH] Update kservice.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复rt_kprintf输出long long类型数据问题 --- src/kservice.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/kservice.c b/src/kservice.c index c940e86d0b..322fb61e28 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -545,6 +545,26 @@ RTM_EXPORT(rt_show_version); /* private function */ #define isdigit(c) ((unsigned)((c) - '0') < 10) +#ifdef RT_PRINTF_LONGLONG +rt_inline int divide(long long *n, int base) +{ + int res; + + /* optimized for processor which does not support divide instructions. */ + if (base == 10) + { + res = (int)(((unsigned long long)*n) % 10U); + *n = (long long)(((unsigned long long)*n) / 10U); + } + else + { + res = (int)(((unsigned long long)*n) % 16U); + *n = (long long)(((unsigned long long)*n) / 16U); + } + + return res; +} +#else rt_inline int divide(long *n, int base) { int res; @@ -563,6 +583,7 @@ rt_inline int divide(long *n, int base) return res; } +#endif rt_inline int skip_atoi(const char **s) { @@ -584,7 +605,11 @@ rt_inline int skip_atoi(const char **s) #ifdef RT_PRINTF_PRECISION static char *print_number(char *buf, char *end, +#ifdef RT_PRINTF_LONGLONG + long long num, +#else long num, +#endif int base, int s, int precision, @@ -592,7 +617,11 @@ static char *print_number(char *buf, #else static char *print_number(char *buf, char *end, +#ifdef RT_PRINTF_LONGLONG + long long num, +#else long num, +#endif int base, int s, int type)