Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Zlib
提交
44dfd831
T
Third Party Zlib
项目概览
OpenHarmony
/
Third Party Zlib
1 年多 前同步成功
通知
16
Star
112
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Zlib
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
44dfd831
编写于
12月 04, 2016
作者:
M
Mark Adler
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add gzfread(), duplicating the interface of fread().
上级
3f8c7687
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
126 addition
and
40 deletion
+126
-40
gzread.c
gzread.c
+97
-39
zlib.h
zlib.h
+29
-1
未找到文件。
gzread.c
浏览文件 @
44dfd831
...
...
@@ -12,6 +12,7 @@ local int gz_look OF((gz_statep));
local
int
gz_decomp
OF
((
gz_statep
));
local
int
gz_fetch
OF
((
gz_statep
));
local
int
gz_skip
OF
((
gz_statep
,
z_off64_t
));
local
z_size_t
gz_read
OF
((
gz_statep
,
voidp
,
z_size_t
));
/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
state->fd, and update state->eof, state->err, and state->msg as appropriate.
...
...
@@ -284,33 +285,17 @@ local int gz_skip(state, len)
return
0
;
}
/* -- see zlib.h -- */
int
ZEXPORT
gzread
(
file
,
buf
,
len
)
gzFile
file
;
/* Read len bytes into buf from file, or less than len up to the end of the
input. Return the number of bytes read. If zero is returned, either the
end of file was reached, or there was an error. state->err must be
consulted in that case to determine which. */
local
z_size_t
gz_read
(
state
,
buf
,
len
)
gz_statep
state
;
voidp
buf
;
unsigned
len
;
z_size_t
len
;
{
unsigned
got
,
n
;
gz_statep
state
;
z_streamp
strm
;
/* get internal structure */
if
(
file
==
NULL
)
return
-
1
;
state
=
(
gz_statep
)
file
;
strm
=
&
(
state
->
strm
);
/* check that we're reading and that there's no (serious) error */
if
(
state
->
mode
!=
GZ_READ
||
(
state
->
err
!=
Z_OK
&&
state
->
err
!=
Z_BUF_ERROR
))
return
-
1
;
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids the flaw in the interface) */
if
((
int
)
len
<
0
)
{
gz_error
(
state
,
Z_DATA_ERROR
,
"requested length does not fit in int"
);
return
-
1
;
}
z_size_t
got
;
unsigned
n
;
/* if len is zero, avoid unnecessary operations */
if
(
len
==
0
)
...
...
@@ -320,32 +305,38 @@ int ZEXPORT gzread(file, buf, len)
if
(
state
->
seek
)
{
state
->
seek
=
0
;
if
(
gz_skip
(
state
,
state
->
skip
)
==
-
1
)
return
-
1
;
return
0
;
}
/* get len bytes to buf, or less than len if at the end */
got
=
0
;
do
{
/* set n to the maximum amount of len that fits in an unsigned int */
n
=
-
1
;
if
(
n
>
len
)
n
=
len
;
/* first just try copying data from the output buffer */
if
(
state
->
x
.
have
)
{
n
=
state
->
x
.
have
>
len
?
len
:
state
->
x
.
have
;
if
(
state
->
x
.
have
<
n
)
n
=
state
->
x
.
have
;
memcpy
(
buf
,
state
->
x
.
next
,
n
);
state
->
x
.
next
+=
n
;
state
->
x
.
have
-=
n
;
}
/* output buffer empty -- return if we're at the end of the input */
else
if
(
state
->
eof
&&
st
rm
->
avail_in
==
0
)
{
else
if
(
state
->
eof
&&
st
ate
->
strm
.
avail_in
==
0
)
{
state
->
past
=
1
;
/* tried to read past end */
break
;
}
/* need output data -- for small len or new stream load up our output
buffer */
else
if
(
state
->
how
==
LOOK
||
le
n
<
(
state
->
size
<<
1
))
{
else
if
(
state
->
how
==
LOOK
||
n
<
(
state
->
size
<<
1
))
{
/* get more output, looking for header if required */
if
(
gz_fetch
(
state
)
==
-
1
)
return
-
1
;
return
0
;
continue
;
/* no progress yet -- go back to copy above */
/* the copy above assures that we will leave with space in the
output buffer, allowing at least one gzungetc() to succeed */
...
...
@@ -353,16 +344,16 @@ int ZEXPORT gzread(file, buf, len)
/* large len -- read directly into user buffer */
else
if
(
state
->
how
==
COPY
)
{
/* read directly */
if
(
gz_load
(
state
,
(
unsigned
char
*
)
buf
,
le
n
,
&
n
)
==
-
1
)
return
-
1
;
if
(
gz_load
(
state
,
(
unsigned
char
*
)
buf
,
n
,
&
n
)
==
-
1
)
return
0
;
}
/* large len -- decompress directly into user buffer */
else
{
/* state->how == GZIP */
st
rm
->
avail_out
=
le
n
;
st
rm
->
next_out
=
(
unsigned
char
*
)
buf
;
st
ate
->
strm
.
avail_out
=
n
;
st
ate
->
strm
.
next_out
=
(
unsigned
char
*
)
buf
;
if
(
gz_decomp
(
state
)
==
-
1
)
return
-
1
;
return
0
;
n
=
state
->
x
.
have
;
state
->
x
.
have
=
0
;
}
...
...
@@ -374,8 +365,75 @@ int ZEXPORT gzread(file, buf, len)
state
->
x
.
pos
+=
n
;
}
while
(
len
);
/* return number of bytes read into user buffer (will fit in int) */
return
(
int
)
got
;
/* return number of bytes read into user buffer */
return
got
;
}
/* -- see zlib.h -- */
int
ZEXPORT
gzread
(
file
,
buf
,
len
)
gzFile
file
;
voidp
buf
;
unsigned
len
;
{
gz_statep
state
;
/* get internal structure */
if
(
file
==
NULL
)
return
-
1
;
state
=
(
gz_statep
)
file
;
/* check that we're reading and that there's no (serious) error */
if
(
state
->
mode
!=
GZ_READ
||
(
state
->
err
!=
Z_OK
&&
state
->
err
!=
Z_BUF_ERROR
))
return
-
1
;
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids a flaw in the interface) */
if
((
int
)
len
<
0
)
{
gz_error
(
state
,
Z_STREAM_ERROR
,
"request does not fit in an int"
);
return
-
1
;
}
/* read len or fewer bytes to buf */
len
=
gz_read
(
state
,
buf
,
len
);
/* check for an error */
if
(
len
==
0
&&
state
->
err
!=
Z_OK
&&
state
->
err
!=
Z_BUF_ERROR
)
return
-
1
;
/* return the number of bytes read (this is assured to fit in an int) */
return
(
int
)
len
;
}
/* -- see zlib.h -- */
z_size_t
ZEXPORT
gzfread
(
buf
,
size
,
nitems
,
file
)
voidp
buf
;
z_size_t
size
;
z_size_t
nitems
;
gzFile
file
;
{
z_size_t
len
;
gz_statep
state
;
/* get internal structure */
if
(
file
==
NULL
)
return
0
;
state
=
(
gz_statep
)
file
;
/* check that we're reading and that there's no (serious) error */
if
(
state
->
mode
!=
GZ_READ
||
(
state
->
err
!=
Z_OK
&&
state
->
err
!=
Z_BUF_ERROR
))
return
0
;
/* compute bytes to read -- error on overflow */
len
=
nitems
*
size
;
if
(
size
&&
len
/
size
!=
nitems
)
{
gz_error
(
state
,
Z_STREAM_ERROR
,
"request does not fit in a size_t"
);
return
0
;
}
/* read len or fewer bytes to buf, return the number of full items read */
return
len
?
gz_read
(
state
,
buf
,
len
)
/
size
:
0
;
}
/* -- see zlib.h -- */
...
...
@@ -408,8 +466,8 @@ int ZEXPORT gzgetc(file)
return
*
(
state
->
x
.
next
)
++
;
}
/* nothing there -- try gzread() */
ret
=
gz
read
(
fil
e
,
buf
,
1
);
/* nothing there -- try gz
_
read() */
ret
=
gz
_read
(
stat
e
,
buf
,
1
);
return
ret
<
1
?
-
1
:
buf
[
0
];
}
...
...
zlib.h
浏览文件 @
44dfd831
...
...
@@ -1388,7 +1388,35 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
case.
gzread returns the number of uncompressed bytes actually read, less than
len for end of file, or -1 for error.
len for end of file, or -1 for error. If len is too large to fit in an int,
then nothing is read, -1 is returned, and the error state is set to
Z_STREAM_ERROR.
*/
ZEXTERN
z_size_t
ZEXPORT
gzfread
OF
((
voidp
buf
,
z_size_t
size
,
z_size_t
nitems
,
gzFile
file
));
/*
Read up to nitems items of size size from file to buf, otherwise operating
as gzread() does. This duplicates the interface of stdio's fread(), with
size_t request and return types. If the library defines size_t, then
z_size_t is identical to size_t. If not, then z_size_t is an unsigned
integer type that can contain a pointer.
gzfread() returns the number of full items read of size size, or zero if
the end of the file was reached and a full item could not be read, or if
there was an error. gzerror() must be consulted if zero is returned in
order to determine if there was an error. If the multiplication of size and
nitems overflows, i.e. the product does not fit in a z_size_t, then nothing
is read, zero is returned, and the error state is set to Z_STREAM_ERROR.
In the event that the end of file is reached and only a partial item is
available at the end, i.e. the remaining uncompressed data length is not a
multiple of size, then the final partial item is nevetheless read into buf
and the end-of-file flag is set. The length of the partial item read is not
provided, but could be inferred from the result of gztell(). This behavior
is the same as the behavior of fread() implementations in common libraries,
but it prevents the direct use of gzfread() to read a concurrently written
file, reseting and retrying on end-of-file, when size is not 1.
*/
ZEXTERN
int
ZEXPORT
gzwrite
OF
((
gzFile
file
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录