Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
adb47574
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看板
未验证
提交
adb47574
编写于
6月 04, 2023
作者:
O
openharmony_ci
提交者:
Gitee
6月 04, 2023
浏览文件
操作
浏览文件
下载
差异文件
!932 fix wirte optimization which fail to write pipe
Merge pull request !932 from Wang Yaofeng/write_optimization_come_back
上级
bc5220a7
008b87ee
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
121 addition
and
1 deletion
+121
-1
libc-test/src/functionalext/supplement/stdio/fwrite.c
libc-test/src/functionalext/supplement/stdio/fwrite.c
+36
-1
musl_src.gni
musl_src.gni
+2
-0
porting/linux/user/src/internal/stdio_impl.h
porting/linux/user/src/internal/stdio_impl.h
+1
-0
porting/linux/user/src/stdio/__stdio_write.c
porting/linux/user/src/stdio/__stdio_write.c
+64
-0
porting/linux/user/src/stdio/__stdout_write.c
porting/linux/user/src/stdio/__stdout_write.c
+18
-0
未找到文件。
libc-test/src/functionalext/supplement/stdio/fwrite.c
浏览文件 @
adb47574
...
...
@@ -14,6 +14,9 @@
*/
#include "functionalext.h"
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
const
char
*
path
=
"/data/test.txt"
;
...
...
@@ -71,10 +74,42 @@ void fwrite_0300(void)
remove
(
path
);
}
void
fwrite_0400
(
void
)
{
pid_t
childPid
=
0
;
int
fds
[
2
]
=
{
0
};
pipe
(
fds
);
int
pipeRead
=
0
;
int
pipeWrite
=
1
;
char
buf
[
1024
]
=
{
0
};
childPid
=
fork
();
EXPECT_NE
(
"fwrite_0400"
,
childPid
,
-
1
);
if
(
childPid
==
0
)
{
// childr
dup2
(
fds
[
pipeWrite
],
STDOUT_FILENO
);
dup2
(
fds
[
pipeRead
],
STDIN_FILENO
);
close
(
fds
[
pipeWrite
]);
close
(
fds
[
pipeRead
]);
// exec
execl
(
"/bin/sh"
,
"/bin/sh"
,
"-c"
,
"/system/bin/bm get -u"
,
NULL
);
exit
(
0
);
}
else
{
// parent
close
(
fds
[
pipeWrite
]);
fcntl
(
fds
[
pipeRead
],
F_SETFD
,
F_DUPFD_CLOEXEC
);
int
cn
=
read
(
fds
[
pipeRead
],
buf
,
sizeof
(
buf
));
EXPECT_MT
(
"fwrite_0400"
,
cn
,
0
);
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
fwrite_0100
();
fwrite_0200
();
fwrite_0300
();
return
t_status
;
}
\ No newline at end of file
}
musl_src.gni
浏览文件 @
adb47574
...
...
@@ -2167,6 +2167,8 @@ musl_src_porting_file = [
"src/stdio/__fdopen.c",
"src/stdio/vfprintf.c",
"src/stdio/__stdio_read.c",
"src/stdio/__stdio_write.c",
"src/stdio/__stdout_write.c",
"src/stdio/fread.c",
"src/stdio/fmemopen.c",
"src/stdio/freopen.c",
...
...
porting/linux/user/src/internal/stdio_impl.h
浏览文件 @
adb47574
...
...
@@ -63,6 +63,7 @@ hidden off_t __stdio_seek(FILE *, off_t, int);
hidden
int
__stdio_close
(
FILE
*
);
hidden
int
__fill_buffer
(
FILE
*
f
);
hidden
ssize_t
__flush_buffer
(
FILE
*
f
);
hidden
int
__toread
(
FILE
*
);
hidden
int
__towrite
(
FILE
*
);
...
...
porting/linux/user/src/stdio/__stdio_write.c
0 → 100644
浏览文件 @
adb47574
#include "stdio_impl.h"
#include <sys/uio.h>
#include <string.h>
ssize_t
__flush_buffer
(
FILE
*
f
)
{
ssize_t
cnt
=
0
;
char
*
wbase
=
(
char
*
)
f
->
wbase
;
size_t
rem
=
f
->
wpos
-
f
->
wbase
;
while
(
rem
>
0
)
{
cnt
=
syscall
(
SYS_write
,
f
->
fd
,
wbase
,
rem
);
if
(
cnt
<
0
)
{
f
->
wpos
=
f
->
wbase
=
f
->
wend
=
0
;
f
->
flags
|=
F_ERR
;
return
cnt
;
}
wbase
+=
cnt
;
rem
-=
cnt
;
}
/* reset file buffer */
f
->
wend
=
f
->
buf
+
f
->
buf_size
;
f
->
wpos
=
f
->
wbase
=
f
->
buf
;
return
cnt
;
}
size_t
__stdio_write
(
FILE
*
f
,
const
unsigned
char
*
buf
,
size_t
len
)
{
size_t
rem
=
len
;
unsigned
char
*
wbuf
=
(
unsigned
char
*
)
buf
;
/* flush buffer first */
ssize_t
cnt
=
__flush_buffer
(
f
);
if
(
cnt
<
0
)
{
return
0
;
}
for
(;;)
{
if
(
f
->
lbf
<
0
&&
rem
<=
f
->
wend
-
f
->
wpos
)
{
memcpy
(
f
->
wpos
,
wbuf
,
rem
);
f
->
wpos
+=
rem
;
return
len
;
}
/* write directly if
* 1. file buffer < rem
* 2. line buffer mode
*/
cnt
=
syscall
(
SYS_write
,
f
->
fd
,
wbuf
,
rem
);
if
(
cnt
<
0
)
{
f
->
wpos
=
f
->
wbase
=
f
->
wend
=
0
;
f
->
flags
|=
F_ERR
;
return
len
-
rem
;
}
rem
-=
cnt
;
wbuf
+=
cnt
;
if
(
rem
==
0
)
{
break
;
}
}
return
len
;
}
porting/linux/user/src/stdio/__stdout_write.c
0 → 100644
浏览文件 @
adb47574
#include "stdio_impl.h"
#include <sys/ioctl.h>
size_t
__stdout_write
(
FILE
*
f
,
const
unsigned
char
*
buf
,
size_t
len
)
{
struct
winsize
wsz
;
f
->
write
=
__stdio_write
;
/*
* write directly at first time.
* check f->flags & tty, and take effect later.
*/
size_t
cnt
=
__stdio_write
(
f
,
buf
,
len
);
if
(
!
(
f
->
flags
&
F_SVB
)
&&
__syscall
(
SYS_ioctl
,
f
->
fd
,
TIOCGWINSZ
,
&
wsz
))
f
->
lbf
=
-
1
;
return
cnt
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录