Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
b3dea7ca
提交
b3dea7ca
3月 25, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Buffer char writes for printf, fprintf, and die.
This results in fewer garbaled userspace console outputs.
上级
b27ae5e9
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
45 行增加
和
7 行删除
+45
-7
printf.cc
lib/printf.cc
+45
-7
没有找到文件。
lib/printf.cc
浏览文件 @
b3dea7ca
...
@@ -3,33 +3,67 @@
...
@@ -3,33 +3,67 @@
#include "user.h"
#include "user.h"
#include <stdarg.h>
#include <stdarg.h>
#include "fmt.hh"
#include "fmt.hh"
#include "lib.h"
struct
outbuf
{
char
b
[
128
];
int
n
;
int
fd
;
};
static
void
flushoutbuf
(
struct
outbuf
*
b
)
{
int
i
=
0
;
int
r
;
while
(
b
->
n
!=
0
)
{
r
=
write
(
b
->
fd
,
&
b
->
b
[
i
],
b
->
n
);
if
(
r
==
0
||
r
<
0
)
{
b
->
n
=
0
;
}
else
{
b
->
n
-=
r
;
i
+=
r
;
}
}
}
// Print to the given fd.
static
void
static
void
write
c
(
int
c
,
void
*
arg
)
write
outbuf
(
int
c
,
void
*
arg
)
{
{
int
fd
=
(
int
)
(
u64
)
arg
;
struct
outbuf
*
b
=
(
struct
outbuf
*
)
arg
;
write
(
fd
,
&
c
,
1
);
if
(
b
->
n
==
NELEM
(
b
->
b
))
flushoutbuf
(
b
);
b
->
b
[
b
->
n
]
=
c
;
b
->
n
++
;
}
}
void
void
fprintf
(
int
fd
,
const
char
*
fmt
,
...)
fprintf
(
int
fd
,
const
char
*
fmt
,
...)
{
{
struct
outbuf
b
;
va_list
ap
;
va_list
ap
;
b
.
n
=
0
;
b
.
fd
=
fd
;
va_start
(
ap
,
fmt
);
va_start
(
ap
,
fmt
);
vprintfmt
(
write
c
,
(
void
*
)
(
u64
)
fd
,
fmt
,
ap
);
vprintfmt
(
write
outbuf
,
(
void
*
)
&
b
,
fmt
,
ap
);
va_end
(
ap
);
va_end
(
ap
);
flushoutbuf
(
&
b
);
}
}
void
void
printf
(
const
char
*
fmt
,
...)
printf
(
const
char
*
fmt
,
...)
{
{
struct
outbuf
b
;
va_list
ap
;
va_list
ap
;
b
.
n
=
0
;
b
.
fd
=
1
;
va_start
(
ap
,
fmt
);
va_start
(
ap
,
fmt
);
vprintfmt
(
write
c
,
(
void
*
)
1
,
fmt
,
ap
);
vprintfmt
(
write
outbuf
,
(
void
*
)
&
b
,
fmt
,
ap
);
va_end
(
ap
);
va_end
(
ap
);
flushoutbuf
(
&
b
);
}
}
// Print to a buffer.
// Print to a buffer.
...
@@ -69,11 +103,15 @@ snprintf(char *buf, u32 n, const char *fmt, ...)
...
@@ -69,11 +103,15 @@ snprintf(char *buf, u32 n, const char *fmt, ...)
void
__attribute__
((
noreturn
))
void
__attribute__
((
noreturn
))
die
(
const
char
*
errstr
,
...)
die
(
const
char
*
errstr
,
...)
{
{
struct
outbuf
b
;
va_list
ap
;
va_list
ap
;
b
.
n
=
0
;
b
.
fd
=
2
;
va_start
(
ap
,
errstr
);
va_start
(
ap
,
errstr
);
vprintfmt
(
write
c
,
(
void
*
)
(
u64
)
1
,
errstr
,
ap
);
vprintfmt
(
write
outbuf
,
(
void
*
)
&
b
,
errstr
,
ap
);
va_end
(
ap
);
va_end
(
ap
);
flushoutbuf
(
&
b
);
fprintf
(
2
,
"
\n
"
);
fprintf
(
2
,
"
\n
"
);
exit
();
exit
();
}
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论