Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
d4fa6f0e
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d4fa6f0e
编写于
9月 03, 2011
作者:
R
Rich Felker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implement fmemopen
testing so far has been minimal. may need further work.
上级
1e693764
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
67 addition
and
18 deletion
+67
-18
include/stdio.h
include/stdio.h
+1
-0
src/stdio/fmemopen.c
src/stdio/fmemopen.c
+66
-18
未找到文件。
include/stdio.h
浏览文件 @
d4fa6f0e
...
...
@@ -121,6 +121,7 @@ FILE *tmpfile(void);
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
FILE
*
fmemopen
(
void
*
,
size_t
,
const
char
*
);
FILE
*
open_memstream
(
char
**
,
size_t
*
);
FILE
*
fdopen
(
int
,
const
char
*
);
FILE
*
popen
(
const
char
*
,
const
char
*
);
...
...
src/stdio/fmemopen.c
浏览文件 @
d4fa6f0e
#if 0
#include "stdio_impl.h"
static ssize_t mread(FILE *f, unsigned char *buf, size_t len)
struct
cookie
{
size_t
pos
,
len
,
size
;
unsigned
char
*
buf
;
int
mode
;
};
static
off_t
mseek
(
FILE
*
f
,
off_t
off
,
int
whence
)
{
size_t rem = f->memsize - f->mempos;
ssize_t
base
;
struct
cookie
*
c
=
f
->
cookie
;
if
(
whence
>
2U
)
{
fail:
errno
=
EINVAL
;
return
-
1
;
}
base
=
(
size_t
[
3
]){
0
,
c
->
pos
,
c
->
len
}[
whence
];
if
(
off
<
-
base
||
off
>
SSIZE_MAX
-
base
)
goto
fail
;
return
c
->
pos
=
base
+
off
;
}
static
size_t
mread
(
FILE
*
f
,
unsigned
char
*
buf
,
size_t
len
)
{
struct
cookie
*
c
=
f
->
cookie
;
size_t
rem
=
c
->
size
-
c
->
pos
;
if
(
len
>
rem
)
len
=
rem
;
memcpy(buf, f->membuf+f->mempos, len);
f->mempos += len;
memcpy
(
buf
,
c
->
buf
+
c
->
pos
,
len
);
c
->
pos
+=
len
;
rem
-=
len
;
if
(
rem
>
f
->
buf_size
)
rem
=
f
->
buf_size
;
f
->
rpos
=
f
->
buf
;
f
->
rend
=
f
->
buf
+
rem
;
memcpy
(
f
->
rpos
,
c
->
buf
+
c
->
pos
,
rem
);
if
(
!
len
)
f
->
flags
|=
F_EOF
;
return
len
;
}
static s
s
ize_t mwrite(FILE *f, const unsigned char *buf, size_t len)
static
size_t
mwrite
(
FILE
*
f
,
const
unsigned
char
*
buf
,
size_t
len
)
{
struct
cookie
*
c
=
f
->
cookie
;
size_t
rem
;
if (f->memmode == 'a') f->mempos = f->memsize;
rem = f->memlim - f->mempos;
if (len > rem) len = rem;
memcpy(f->membuf+f->mempos, buf, len);
f->mempos += len;
if (f->mempos >= f->memsize) {
f->memsize = f->mempos;
size_t
len2
=
f
->
wpos
-
f
->
wbase
;
if
(
len2
)
{
f
->
wpos
=
f
->
wbase
;
if
(
mwrite
(
f
,
f
->
wpos
,
len2
)
<
len2
)
return
0
;
}
if
(
c
->
mode
==
'a'
)
c
->
pos
=
c
->
size
;
rem
=
c
->
size
-
c
->
pos
;
if
(
len
>
rem
)
len
=
rem
;
memcpy
(
c
->
buf
+
c
->
pos
,
buf
,
len
);
c
->
pos
+=
len
;
if
(
c
->
pos
>=
c
->
len
)
c
->
len
=
c
->
pos
;
c
->
buf
[
c
->
len
==
c
->
size
?
c
->
len
-
1
:
c
->
len
]
=
0
;
return
len
;
}
static
int
mclose
(
FILE
*
m
)
{
return
0
;
}
FILE
*
fmemopen
(
void
*
buf
,
size_t
size
,
const
char
*
mode
)
{
FILE
*
f
;
struct
cookie
*
c
;
int
plus
=
!!
strchr
(
mode
,
'+'
);
if
(
!
size
||
!
strchr
(
"rwa"
,
*
mode
))
{
...
...
@@ -39,23 +76,34 @@ FILE *fmemopen(void *buf, size_t size, const char *mode)
return
0
;
}
f = calloc(sizeof
(FILE)
+ UNGET + BUFSIZ + (buf?0:size), 1);
f
=
calloc
(
sizeof
*
f
+
sizeof
*
c
+
UNGET
+
BUFSIZ
+
(
buf
?
0
:
size
),
1
);
if
(
!
f
)
return
0
;
f
->
cookie
=
c
=
(
void
*
)(
f
+
1
);
f
->
fd
=
-
1
;
f
->
lbf
=
EOF
;
f->buf = (unsigned char *)(
f
+1) + UNGET;
f
->
buf
=
(
unsigned
char
*
)(
c
+
1
)
+
UNGET
;
f
->
buf_size
=
BUFSIZ
;
if
(
!
buf
)
buf
=
f
->
buf
+
BUFSIZ
;
c
->
buf
=
buf
;
c
->
size
=
size
;
c
->
mode
=
*
mode
;
if
(
!
plus
)
f
->
flags
=
(
*
mode
==
'r'
)
?
F_NOWR
:
F_NORD
;
if (*mode == 'a') f->mempos = strchr(buf, 0)-buf;
if
(
*
mode
==
'r'
)
c
->
len
=
size
;
else
if
(
*
mode
==
'a'
)
c
->
len
=
c
->
pos
=
strnlen
(
buf
,
size
);
f
->
read
=
mread
;
f
->
write
=
mwrite
;
f
->
seek
=
mseek
;
f->flush = mflush;
f
->
close
=
mclose
;
if
(
!
libc
.
threaded
)
{
f
->
lock
=
-
1
;
f
->
next
=
libc
.
ofl_head
;
if
(
libc
.
ofl_head
)
libc
.
ofl_head
->
prev
=
f
;
libc
.
ofl_head
=
f
;
}
return
f
;
}
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录