Skip to content

Commit bab3546

Browse files
authored
Merge pull request #2696 from HubertXie/master
[kservice][rt_kprintf]修复long long数据类型打印问题
2 parents 851e33a + edccf1c commit bab3546

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/kservice.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,26 @@ RTM_EXPORT(rt_show_version);
545545
/* private function */
546546
#define isdigit(c) ((unsigned)((c) - '0') < 10)
547547

548+
#ifdef RT_PRINTF_LONGLONG
549+
rt_inline int divide(long long *n, int base)
550+
{
551+
int res;
552+
553+
/* optimized for processor which does not support divide instructions. */
554+
if (base == 10)
555+
{
556+
res = (int)(((unsigned long long)*n) % 10U);
557+
*n = (long long)(((unsigned long long)*n) / 10U);
558+
}
559+
else
560+
{
561+
res = (int)(((unsigned long long)*n) % 16U);
562+
*n = (long long)(((unsigned long long)*n) / 16U);
563+
}
564+
565+
return res;
566+
}
567+
#else
548568
rt_inline int divide(long *n, int base)
549569
{
550570
int res;
@@ -563,6 +583,7 @@ rt_inline int divide(long *n, int base)
563583

564584
return res;
565585
}
586+
#endif
566587

567588
rt_inline int skip_atoi(const char **s)
568589
{
@@ -584,15 +605,23 @@ rt_inline int skip_atoi(const char **s)
584605
#ifdef RT_PRINTF_PRECISION
585606
static char *print_number(char *buf,
586607
char *end,
608+
#ifdef RT_PRINTF_LONGLONG
609+
long long num,
610+
#else
587611
long num,
612+
#endif
588613
int base,
589614
int s,
590615
int precision,
591616
int type)
592617
#else
593618
static char *print_number(char *buf,
594619
char *end,
620+
#ifdef RT_PRINTF_LONGLONG
621+
long long num,
622+
#else
595623
long num,
624+
#endif
596625
int base,
597626
int s,
598627
int type)

0 commit comments

Comments
 (0)