Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
dd0adf17
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看板
未验证
提交
dd0adf17
编写于
5月 17, 2023
作者:
O
openharmony_ci
提交者:
Gitee
5月 17, 2023
浏览文件
操作
浏览文件
下载
差异文件
!902 Optimize musl I/O function fread
Merge pull request !902 from Wang Yaofeng/master
上级
9959e363
0b1a046b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
224 addition
and
0 deletion
+224
-0
musl_src.gni
musl_src.gni
+3
-0
porting/linux/user/src/internal/stdio_impl.h
porting/linux/user/src/internal/stdio_impl.h
+115
-0
porting/linux/user/src/stdio/__fdopen.c
porting/linux/user/src/stdio/__fdopen.c
+1
-0
porting/linux/user/src/stdio/__stdio_read.c
porting/linux/user/src/stdio/__stdio_read.c
+31
-0
porting/linux/user/src/stdio/fread.c
porting/linux/user/src/stdio/fread.c
+74
-0
未找到文件。
musl_src.gni
浏览文件 @
dd0adf17
...
...
@@ -2165,6 +2165,9 @@ musl_src_porting_file = [
"src/ldso/riscv64/dlvsym.s",
"src/ldso/x86_64/dlvsym.s",
"src/stdio/__fdopen.c",
"src/stdio/__stdio_read.c",
"src/stdio/fread.c",
"src/internal/stdio_impl.h",
"src/internal/vdso.c",
"src/time/clock_gettime.c",
"src/time/clock_getres.c",
...
...
porting/linux/user/src/internal/stdio_impl.h
0 → 100644
浏览文件 @
dd0adf17
#ifndef _STDIO_IMPL_H
#define _STDIO_IMPL_H
#include <stdio.h>
#include "syscall.h"
#define UNGET 8
#define FFINALLOCK(f) ((f)->lock>=0 ? __lockfile((f)) : 0)
#define FLOCK(f) int __need_unlock = ((f)->lock>=0 ? __lockfile((f)) : 0)
#define FUNLOCK(f) do { if (__need_unlock) __unlockfile((f)); } while (0)
#define F_PERM 1
#define F_NORD 4
#define F_NOWR 8
#define F_EOF 16
#define F_ERR 32
#define F_SVB 64
#define F_APP 128
struct
_IO_FILE
{
unsigned
flags
;
unsigned
char
*
rpos
,
*
rend
;
int
(
*
close
)(
FILE
*
);
unsigned
char
*
wend
,
*
wpos
;
unsigned
char
*
mustbezero_1
;
unsigned
char
*
wbase
;
size_t
(
*
read
)(
FILE
*
,
unsigned
char
*
,
size_t
);
size_t
(
*
readx
)(
FILE
*
,
unsigned
char
*
,
size_t
);
size_t
(
*
write
)(
FILE
*
,
const
unsigned
char
*
,
size_t
);
off_t
(
*
seek
)(
FILE
*
,
off_t
,
int
);
unsigned
char
*
buf
;
size_t
buf_size
;
FILE
*
prev
,
*
next
;
int
fd
;
int
pipe_pid
;
long
lockcount
;
int
mode
;
volatile
int
lock
;
int
lbf
;
void
*
cookie
;
off_t
off
;
char
*
getln_buf
;
void
*
mustbezero_2
;
unsigned
char
*
shend
;
off_t
shlim
,
shcnt
;
FILE
*
prev_locked
,
*
next_locked
;
struct
__locale_struct
*
locale
;
};
extern
hidden
FILE
*
volatile
__stdin_used
;
extern
hidden
FILE
*
volatile
__stdout_used
;
extern
hidden
FILE
*
volatile
__stderr_used
;
hidden
int
__lockfile
(
FILE
*
);
hidden
void
__unlockfile
(
FILE
*
);
hidden
size_t
__stdio_read
(
FILE
*
,
unsigned
char
*
,
size_t
);
hidden
size_t
__stdio_readx
(
FILE
*
,
unsigned
char
*
,
size_t
);
hidden
size_t
__stdio_write
(
FILE
*
,
const
unsigned
char
*
,
size_t
);
hidden
size_t
__stdout_write
(
FILE
*
,
const
unsigned
char
*
,
size_t
);
hidden
off_t
__stdio_seek
(
FILE
*
,
off_t
,
int
);
hidden
int
__stdio_close
(
FILE
*
);
hidden
int
__fill_buffer
(
FILE
*
f
);
hidden
int
__toread
(
FILE
*
);
hidden
int
__towrite
(
FILE
*
);
hidden
void
__stdio_exit
(
void
);
hidden
void
__stdio_exit_needed
(
void
);
#if defined(__PIC__) && (100*__GNUC__+__GNUC_MINOR__ >= 303)
__attribute__
((
visibility
(
"protected"
)))
#endif
int
__overflow
(
FILE
*
,
int
),
__uflow
(
FILE
*
);
hidden
int
__fseeko
(
FILE
*
,
off_t
,
int
);
hidden
int
__fseeko_unlocked
(
FILE
*
,
off_t
,
int
);
hidden
off_t
__ftello
(
FILE
*
);
hidden
off_t
__ftello_unlocked
(
FILE
*
);
hidden
size_t
__fwritex
(
const
unsigned
char
*
,
size_t
,
FILE
*
);
hidden
int
__putc_unlocked
(
int
,
FILE
*
);
hidden
FILE
*
__fdopen
(
int
,
const
char
*
);
hidden
int
__fmodeflags
(
const
char
*
);
hidden
FILE
*
__ofl_add
(
FILE
*
f
);
hidden
FILE
**
__ofl_lock
(
void
);
hidden
void
__ofl_unlock
(
void
);
struct
__pthread
;
hidden
void
__register_locked_file
(
FILE
*
,
struct
__pthread
*
);
hidden
void
__unlist_locked_file
(
FILE
*
);
hidden
void
__do_orphaned_stdio_locks
(
void
);
#define MAYBE_WAITERS 0x40000000
hidden
void
__getopt_msg
(
const
char
*
,
const
char
*
,
const
char
*
,
size_t
);
#define feof(f) ((f)->flags & F_EOF)
#define ferror(f) ((f)->flags & F_ERR)
#define getc_unlocked(f) \
( ((f)->rpos != (f)->rend) ? *(f)->rpos++ : __uflow((f)) )
#define putc_unlocked(c, f) \
( (((unsigned char)(c)!=(f)->lbf && (f)->wpos!=(f)->wend)) \
? *(f)->wpos++ = (unsigned char)(c) \
: __overflow((f),(unsigned char)(c)) )
/* Caller-allocated FILE * operations */
hidden
FILE
*
__fopen_rb_ca
(
const
char
*
,
FILE
*
,
unsigned
char
*
,
size_t
);
hidden
int
__fclose_ca
(
FILE
*
);
#endif
porting/linux/user/src/stdio/__fdopen.c
浏览文件 @
dd0adf17
...
...
@@ -93,6 +93,7 @@ FILE *__fdopen(int fd, const char *mode)
f
->
write
=
__stdio_write
;
f
->
seek
=
__stdio_seek
;
f
->
close
=
__stdio_close
;
f
->
readx
=
__stdio_readx
;
if
(
!
libc
.
threaded
)
{
f
->
lock
=
-
1
;
...
...
porting/linux/user/src/stdio/__stdio_read.c
0 → 100644
浏览文件 @
dd0adf17
#include "stdio_impl.h"
#include <sys/uio.h>
size_t
__stdio_readx
(
FILE
*
f
,
unsigned
char
*
buf
,
size_t
len
)
{
return
syscall
(
SYS_read
,
f
->
fd
,
buf
,
len
);
}
size_t
__stdio_read
(
FILE
*
f
,
unsigned
char
*
buf
,
size_t
len
)
{
struct
iovec
iov_buf
[
2
]
=
{
{
.
iov_base
=
buf
,
.
iov_len
=
len
-
!!
f
->
buf_size
},
{
.
iov_base
=
f
->
buf
,
.
iov_len
=
f
->
buf_size
}
};
ssize_t
cnt
;
cnt
=
iov_buf
[
0
].
iov_len
?
syscall
(
SYS_readv
,
f
->
fd
,
iov_buf
,
2
)
:
syscall
(
SYS_read
,
f
->
fd
,
iov_buf
[
1
].
iov_base
,
iov_buf
[
1
].
iov_len
);
if
(
cnt
<=
0
)
{
f
->
flags
|=
cnt
?
F_ERR
:
F_EOF
;
return
0
;
}
if
(
cnt
<=
iov_buf
[
0
].
iov_len
)
{
return
cnt
;
}
cnt
-=
iov_buf
[
0
].
iov_len
;
f
->
rpos
=
f
->
buf
;
f
->
rend
=
f
->
buf
+
cnt
;
if
(
f
->
buf_size
)
buf
[
len
-
1
]
=
*
f
->
rpos
++
;
return
len
;
}
porting/linux/user/src/stdio/fread.c
0 → 100644
浏览文件 @
dd0adf17
#include "stdio_impl.h"
#include <string.h>
#define MIN(a,b) ((a)<(b) ? (a) : (b))
int
__fill_buffer
(
FILE
*
f
)
{
int
r
=
__toread
(
f
);
if
(
r
!=
0
)
{
return
r
;
}
int
k
=
f
->
readx
(
f
,
f
->
buf
,
f
->
buf_size
);
if
(
k
<=
0
)
{
f
->
flags
|=
(
k
==
0
)
?
F_EOF
:
F_ERR
;
f
->
rpos
=
f
->
rend
;
return
k
;
}
f
->
rpos
=
f
->
buf
;
f
->
rend
=
f
->
rpos
+
k
;
return
0
;
}
size_t
fread
(
void
*
restrict
destv
,
size_t
size
,
size_t
nmemb
,
FILE
*
restrict
f
)
{
unsigned
char
*
dest
=
destv
;
size_t
len
=
size
*
nmemb
,
l
=
len
,
k
;
if
(
!
size
)
{
nmemb
=
0
;
}
FLOCK
(
f
);
f
->
mode
|=
f
->
mode
-
1
;
while
(
l
>
0
)
{
if
(
f
->
rpos
!=
f
->
rend
)
{
/* First exhaust the buffer. */
k
=
MIN
(
f
->
rend
-
f
->
rpos
,
l
);
memcpy
(
dest
,
f
->
rpos
,
k
);
f
->
rpos
+=
k
;
dest
+=
k
;
l
-=
k
;
}
/* done */
if
(
l
==
0
)
{
goto
exit
;
}
/* if user buffer is longer than file buffer, read directly */
if
(
l
>
f
->
buf_size
)
{
break
;
}
if
(
__fill_buffer
(
f
))
{
goto
exit
;
}
}
/* Read the remainder directly */
for
(;
l
;
l
-=
k
,
dest
+=
k
)
{
k
=
f
->
readx
(
f
,
dest
,
l
);
if
(
k
<=
0
)
{
f
->
flags
|=
(
k
==
0
?
F_EOF
:
F_ERR
);
break
;
}
}
exit:
FUNLOCK
(
f
);
return
(
len
-
l
)
/
size
;
}
weak_alias
(
fread
,
fread_unlocked
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录