mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 08:06:32 +00:00
🐛 修复printf的bug
This commit is contained in:
@ -9,6 +9,22 @@
|
||||
static char *write_num(char *str, uint64_t num, int base, int field_width, int precision, int flags);
|
||||
static char *write_float_point_num(char *str, double num, int field_width, int precision, int flags);
|
||||
|
||||
|
||||
static int skip_and_atoi(const char **s)
|
||||
{
|
||||
/**
|
||||
* @brief 获取连续的一段字符对应整数的值
|
||||
* @param:**s 指向 指向字符串的指针 的指针
|
||||
*/
|
||||
int ans = 0;
|
||||
while (is_digit(**s))
|
||||
{
|
||||
ans = ans * 10 + (**s) - '0';
|
||||
++(*s);
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 往屏幕上输出字符串
|
||||
*
|
||||
@ -138,7 +154,7 @@ int vsprintf(char *buf, const char *fmt, va_list args)
|
||||
}
|
||||
else if (is_digit(*fmt))
|
||||
{
|
||||
field_width = atoi(&fmt);
|
||||
field_width = skip_and_atoi(&fmt);
|
||||
if (field_width < 0)
|
||||
{
|
||||
field_width = -field_width;
|
||||
@ -158,7 +174,7 @@ int vsprintf(char *buf, const char *fmt, va_list args)
|
||||
}
|
||||
else if is_digit (*fmt)
|
||||
{
|
||||
precision = atoi(&fmt);
|
||||
precision = skip_and_atoi(&fmt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <libc/unistd.h>
|
||||
#include <libc/stdlib.h>
|
||||
#include <libc/ctype.h>
|
||||
|
||||
int abs(int i)
|
||||
{
|
||||
|
@ -14,15 +14,11 @@ long syscall_invoke(uint64_t syscall_id, uint64_t arg0, uint64_t arg1, uint64_t
|
||||
"movq %8, %%r14 \n\t"
|
||||
"movq %9, %%r15 \n\t"
|
||||
"int $0x80 \n\t"
|
||||
"movq %%rax, %0 \n\t"
|
||||
: "=m"(err_code)
|
||||
// "movq %%rax, %0 \n\t"
|
||||
: "=a"(err_code)
|
||||
: "a"(syscall_id), "m"(arg0), "m"(arg1), "m"(arg2), "m"(arg3), "m"(arg4), "m"(arg5), "m"(arg6), "m"(arg7)
|
||||
: "memory", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "rcx", "rdx");
|
||||
errno = err_code;
|
||||
if (syscall_id == SYS_BRK || syscall_id == SYS_OPEN)
|
||||
{
|
||||
printf("retval = %#018lx\n", (uint64_t)err_code);
|
||||
printf("errcode = %d\n", err_code);
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
Reference in New Issue
Block a user