Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
72969671
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
1 年多 前同步成功
通知
37
Star
125
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Musl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
72969671
编写于
7月 24, 2023
作者:
O
openharmony_ci
提交者:
Gitee
7月 24, 2023
浏览文件
操作
浏览文件
下载
差异文件
!995 optimize vsnprintf
Merge pull request !995 from Wang Yaofeng/vsnprintf_opt
上级
e033d572
7724ed6c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
92 addition
and
18 deletion
+92
-18
libc-test/src/functionalext/supplement/stdio/vsnprintf.c
libc-test/src/functionalext/supplement/stdio/vsnprintf.c
+23
-1
libc-test/src/functionalext/supplement/stdio/vsprintf.c
libc-test/src/functionalext/supplement/stdio/vsprintf.c
+8
-8
musl_src.gni
musl_src.gni
+1
-0
porting/linux/user/src/internal/stdio_impl.h
porting/linux/user/src/internal/stdio_impl.h
+1
-0
porting/linux/user/src/stdio/vfprintf.c
porting/linux/user/src/stdio/vfprintf.c
+12
-9
porting/linux/user/src/stdio/vsnprintf.c
porting/linux/user/src/stdio/vsnprintf.c
+47
-0
未找到文件。
libc-test/src/functionalext/supplement/stdio/vsnprintf.c
浏览文件 @
72969671
...
...
@@ -18,6 +18,7 @@
#include <stdarg.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
void
vsnprintf_test
(
char
*
str
,
size_t
n
,
char
*
fmt
,
const
char
*
func_name
,
...)
{
...
...
@@ -49,6 +50,14 @@ void vsnprintf_zeron(char *str, char *fmt, const char *func_name, ...)
}
}
void
vsnprintf_zeron_all
(
char
*
str
,
char
*
fmt
,
const
char
*
func_name
,
...)
{
va_list
ap
;
va_start
(
ap
,
func_name
);
int
result
=
vsnprintf
(
0
,
0
,
fmt
,
ap
);
va_end
(
ap
);
EXPECT_EQ
(
func_name
,
result
,
strlen
(
str
));
}
int
main
(
int
argc
,
char
*
argv
[])
{
/**
...
...
@@ -75,5 +84,18 @@ int main(int argc, char *argv[])
* @tc.level : Level 2
*/
vsnprintf_zeron
(
"value is use"
,
"value is %s"
,
"vsnprintf_0400"
,
"use"
);
/**
* @tc.name : vsnprintf_0500
* @tc.desc : truncate buffer, and bits to 0
* @tc.level : Level 3
*/
vsnprintf_zeron_all
(
"value is use"
,
"value is %s"
,
"vsnprintf_0500"
,
"use"
);
/**
* @tc.name : vsnprintf_0600
* @tc.desc : The number of bits to be 1
* @tc.level : Level 2
*/
vsnprintf_test
(
""
,
1
,
"value is %s"
,
"vsnprintf_0600"
,
"use"
);
return
t_status
;
}
\ No newline at end of file
}
libc-test/src/functionalext/supplement/stdio/vsprintf.c
浏览文件 @
72969671
...
...
@@ -25,7 +25,7 @@
*/
void
vsprintf_0100
(
char
*
format
,
...)
{
char
buffer
[
20
];
char
buffer
[
20
]
=
{
0
}
;
va_list
aptr
;
va_start
(
aptr
,
format
);
int
result
=
vsprintf
(
buffer
,
format
,
aptr
);
...
...
@@ -34,7 +34,7 @@ void vsprintf_0100(char *format, ...)
t_error
(
"%s vsprintf get result is less than 0"
,
__func__
);
}
if
(
strcmp
(
buffer
,
"1"
))
{
t_error
(
"%s wrong string written to buf
"
,
__func__
);
t_error
(
"%s wrong string written to buf
%s
\n
"
,
__func__
,
buffer
);
}
}
...
...
@@ -45,16 +45,16 @@ void vsprintf_0100(char *format, ...)
*/
void
vsprintf_0200
(
char
*
format
,
...)
{
char
buffer
[
20
];
char
buffer
[
20
]
=
{
0
}
;
va_list
aptr
;
va_start
(
aptr
,
format
);
int
result
=
vsprintf
(
buffer
,
format
,
aptr
);
va_end
(
aptr
);
if
(
result
<
0
)
{
t_error
(
"%s vsprintf get result is less than 0"
,
__func__
);
t_error
(
"%s vsprintf get result is less than 0
\n
"
,
__func__
);
}
if
(
strncmp
(
buffer
,
"3.0"
,
3
))
{
t_error
(
"%s wrong string written to buf
"
,
__func__
);
t_error
(
"%s wrong string written to buf
%s
\n
"
,
__func__
,
buffer
);
}
}
...
...
@@ -71,10 +71,10 @@ void vsprintf_0300(char *format, ...)
int
result
=
vsprintf
(
buffer
,
format
,
aptr
);
va_end
(
aptr
);
if
(
result
<
0
)
{
t_error
(
"%s vsprintf get result is less than 0"
,
__func__
);
t_error
(
"%s vsprintf get result is less than 0
\n
"
,
__func__
);
}
if
(
strcmp
(
buffer
,
"vsprintf test"
))
{
t_error
(
"%s wrong string written to buf
"
,
__func__
);
t_error
(
"%s wrong string written to buf
%s
\n
"
,
__func__
,
buffer
);
}
}
...
...
@@ -87,4 +87,4 @@ int main(int argc, char *argv[])
vsprintf_0200
(
"%f"
,
f
);
vsprintf_0300
(
"%s"
,
str
);
return
t_status
;
}
\ No newline at end of file
}
musl_src.gni
浏览文件 @
72969671
...
...
@@ -2189,6 +2189,7 @@ musl_src_porting_file = [
"src/stdio/__towrite.c",
"src/stdio/stderr.c",
"src/stdio/fgets.c",
"src/stdio/vsnprintf.c",
"src/internal/stdio_impl.h",
"src/internal/vdso.c",
"src/time/clock_gettime.c",
...
...
porting/linux/user/src/internal/stdio_impl.h
浏览文件 @
72969671
...
...
@@ -18,6 +18,7 @@
#define F_SVB 64
#define F_APP 128
#define F_NOBUF 256
#define F_PBUF 512
struct
_IO_FILE
{
unsigned
flags
;
...
...
porting/linux/user/src/stdio/vfprintf.c
浏览文件 @
72969671
...
...
@@ -132,7 +132,14 @@ static void pop_arg(union arg *arg, int type, va_list *ap)
static
void
out
(
FILE
*
f
,
const
char
*
s
,
size_t
l
)
{
if
(
!
(
f
->
flags
&
F_ERR
))
__fwritex
((
void
*
)
s
,
l
,
f
);
/* write to file buffer if flag F_PBUF is available */
if
(
!
(
f
->
flags
&
F_ERR
)
&&
!
(
f
->
flags
&
F_PBUF
))
{
__fwritex
((
void
*
)
s
,
l
,
f
);
return
;
}
/* otherwise, copy to buffer directly */
f
->
write
(
f
,
(
void
*
)
s
,
l
);
}
static
void
pad
(
FILE
*
f
,
char
c
,
int
w
,
int
l
,
int
fl
)
...
...
@@ -675,13 +682,7 @@ int vfprintf(FILE *restrict f, const char *restrict fmt, va_list ap)
olderr
=
f
->
flags
&
F_ERR
;
if
(
f
->
mode
<
1
)
f
->
flags
&=
~
F_ERR
;
/* allocate file buffer if need */
if
(
__falloc_buf
(
f
)
<
0
)
{
f
->
flags
|=
F_ERR
;
ret
=
-
1
;
}
if
(
!
f
->
buf_size
)
{
if
(
!
f
->
buf_size
&&
f
->
buf
!=
NULL
)
{
saved_buf
=
f
->
buf
;
f
->
buf
=
internal_buf
;
f
->
buf_size
=
sizeof
internal_buf
;
...
...
@@ -690,7 +691,9 @@ int vfprintf(FILE *restrict f, const char *restrict fmt, va_list ap)
if
(
!
f
->
wend
&&
__towrite
(
f
))
ret
=
-
1
;
else
ret
=
printf_core
(
f
,
fmt
,
&
ap2
,
nl_arg
,
nl_type
,
0
);
if
(
saved_buf
)
{
f
->
write
(
f
,
0
,
0
);
if
(
!
(
f
->
flags
&
F_PBUF
))
{
f
->
write
(
f
,
0
,
0
);
}
if
(
!
f
->
wpos
)
ret
=
-
1
;
f
->
buf
=
saved_buf
;
f
->
buf_size
=
0
;
...
...
porting/linux/user/src/stdio/vsnprintf.c
0 → 100644
浏览文件 @
72969671
#include "stdio_impl.h"
#include <limits.h>
#include <string.h>
#include <errno.h>
#include <stdint.h>
struct
cookie
{
char
*
s
;
size_t
n
;
};
#define MIN(a, b) ((a) < (b) ? (a) : (b))
static
size_t
sn_write
(
FILE
*
f
,
const
unsigned
char
*
s
,
size_t
l
)
{
struct
cookie
*
c
=
f
->
cookie
;
size_t
already_size
=
f
->
wpos
-
f
->
wbase
;
if
(
already_size
<=
c
->
n
)
{
size_t
k
=
MIN
(
l
,
c
->
n
-
already_size
);
memcpy
(
f
->
wpos
,
s
,
k
);
f
->
wpos
+=
k
;
*
f
->
wpos
=
'\0'
;
}
/* pretend to succeed, even if we discarded extra data */
return
l
;
}
int
vsnprintf
(
char
*
restrict
s
,
size_t
n
,
const
char
*
restrict
fmt
,
va_list
ap
)
{
unsigned
char
dummy
[
1
];
struct
cookie
c
=
{
.
s
=
n
?
s
:
dummy
,
.
n
=
n
?
n
-
1
:
0
};
FILE
f
=
{
.
lbf
=
EOF
,
.
lock
=
-
1
,
.
buf
=
(
unsigned
char
*
)(
n
?
s
:
dummy
),
.
buf_size
=
n
?
n
-
1
:
0
,
.
flags
=
F_PBUF
,
.
cookie
=
&
c
,
.
write
=
sn_write
,
};
if
(
n
>
INT_MAX
)
{
errno
=
EOVERFLOW
;
return
-
1
;
}
return
vfprintf
(
&
f
,
fmt
,
ap
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录