Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
03427d4e
Commit
03427d4e
authored
Dec 15, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
archive/bz2: simplified error handling, short read
Don't attempt to fill the whole buffer in the read() method, return whatever libbz2 provides with the first successful BZ2_bzDecompress().
parent
a627a703
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
34 deletions
+23
-34
bz2_plugin.c
src/archive/bz2_plugin.c
+23
-34
No files found.
src/archive/bz2_plugin.c
View file @
03427d4e
...
@@ -42,8 +42,9 @@ typedef struct {
...
@@ -42,8 +42,9 @@ typedef struct {
char
*
name
;
char
*
name
;
bool
reset
;
bool
reset
;
struct
input_stream
istream
;
struct
input_stream
istream
;
int
last_bz_result
;
int
last_parent_result
;
bool
eof
;
bz_stream
bzstream
;
bz_stream
bzstream
;
char
*
buffer
;
char
*
buffer
;
}
bz2_context
;
}
bz2_context
;
...
@@ -69,8 +70,6 @@ bz2_alloc(bz2_context *data)
...
@@ -69,8 +70,6 @@ bz2_alloc(bz2_context *data)
return
false
;
return
false
;
}
}
data
->
last_bz_result
=
BZ_OK
;
data
->
last_parent_result
=
0
;
return
true
;
return
true
;
}
}
...
@@ -169,6 +168,8 @@ bz2_open_stream(struct archive_file *file, struct input_stream *is,
...
@@ -169,6 +168,8 @@ bz2_open_stream(struct archive_file *file, struct input_stream *is,
return
false
;
return
false
;
}
}
context
->
eof
=
false
;
return
true
;
return
true
;
}
}
...
@@ -183,7 +184,7 @@ bz2_is_close(struct input_stream *is)
...
@@ -183,7 +184,7 @@ bz2_is_close(struct input_stream *is)
}
}
static
bool
static
bool
bz2_fillbuffer
(
bz2_context
*
context
,
size_t
length
)
bz2_fillbuffer
(
bz2_context
*
context
)
{
{
size_t
count
;
size_t
count
;
bz_stream
*
bzstream
;
bz_stream
*
bzstream
;
...
@@ -195,18 +196,11 @@ bz2_fillbuffer(bz2_context *context, size_t length)
...
@@ -195,18 +196,11 @@ bz2_fillbuffer(bz2_context *context, size_t length)
count
=
input_stream_read
(
&
context
->
istream
,
count
=
input_stream_read
(
&
context
->
istream
,
context
->
buffer
,
BZ_BUFSIZE
);
context
->
buffer
,
BZ_BUFSIZE
);
if
(
count
==
0
)
return
false
;
if
(
count
==
0
)
{
bzstream
->
next_in
=
context
->
buffer
;
if
(
bzstream
->
avail_out
==
length
)
bzstream
->
avail_in
=
count
;
return
false
;
if
(
!
input_stream_eof
(
&
context
->
istream
))
context
->
last_parent_result
=
1
;
}
else
{
bzstream
->
next_in
=
context
->
buffer
;
bzstream
->
avail_in
=
count
;
}
return
true
;
return
true
;
}
}
...
@@ -218,32 +212,31 @@ bz2_is_read(struct input_stream *is, void *ptr, size_t length)
...
@@ -218,32 +212,31 @@ bz2_is_read(struct input_stream *is, void *ptr, size_t length)
int
bz_result
;
int
bz_result
;
size_t
nbytes
=
0
;
size_t
nbytes
=
0
;
if
(
context
->
last_bz_result
!=
BZ_OK
)
if
(
context
->
eof
)
return
0
;
if
(
context
->
last_parent_result
!=
0
)
return
0
;
return
0
;
bzstream
=
&
context
->
bzstream
;
bzstream
=
&
context
->
bzstream
;
bzstream
->
next_out
=
ptr
;
bzstream
->
next_out
=
ptr
;
bzstream
->
avail_out
=
length
;
bzstream
->
avail_out
=
length
;
while
(
bzstream
->
avail_out
!=
0
)
{
do
{
if
(
!
bz2_fillbuffer
(
context
,
length
))
if
(
!
bz2_fillbuffer
(
context
))
{
break
;
is
->
error
=
-
1
;
return
0
;
}
bz_result
=
BZ2_bzDecompress
(
bzstream
);
bz_result
=
BZ2_bzDecompress
(
bzstream
);
if
(
context
->
last_bz_result
!=
BZ_OK
if
(
bz_result
==
BZ_STREAM_END
)
{
&&
bzstream
->
avail_out
==
length
)
{
context
->
eof
=
true
;
context
->
last_bz_result
=
bz_result
;
break
;
break
;
}
}
if
(
bz_result
==
BZ_STREAM_END
)
{
if
(
bz_result
!=
BZ_OK
)
{
context
->
last_bz_result
=
bz_result
;
is
->
error
=
bz_result
;
break
;
return
0
;
}
}
}
}
while
(
bzstream
->
avail_out
==
length
);
nbytes
=
length
-
bzstream
->
avail_out
;
nbytes
=
length
-
bzstream
->
avail_out
;
is
->
offset
+=
nbytes
;
is
->
offset
+=
nbytes
;
...
@@ -256,11 +249,7 @@ bz2_is_eof(struct input_stream *is)
...
@@ -256,11 +249,7 @@ bz2_is_eof(struct input_stream *is)
{
{
bz2_context
*
context
=
(
bz2_context
*
)
is
->
data
;
bz2_context
*
context
=
(
bz2_context
*
)
is
->
data
;
if
(
context
->
last_bz_result
==
BZ_STREAM_END
)
{
return
context
->
eof
;
return
true
;
}
return
false
;
}
}
/* exported structures */
/* exported structures */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment