Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
alpine
apk-tools
Commits
dbb64220
Commit
dbb64220
authored
Jun 17, 2013
by
Timo Teräs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
io: fix splice for copying unknown lengths
parent
f79e3946
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
9 deletions
+22
-9
src/apk_io.h
src/apk_io.h
+13
-2
src/io.c
src/io.c
+3
-1
src/url.c
src/url.c
+6
-6
No files found.
src/apk_io.h
View file @
dbb64220
...
...
@@ -77,9 +77,11 @@ struct apk_ostream *apk_ostream_counter(off_t *);
struct
apk_istream
*
apk_istream_from_fd_pid
(
int
fd
,
pid_t
pid
,
int
(
*
translate_status
)(
int
));
struct
apk_istream
*
apk_istream_from_file
(
int
atfd
,
const
char
*
file
);
struct
apk_istream
*
apk_istream_from_file_gz
(
int
atfd
,
const
char
*
file
);
struct
apk_istream
*
apk_istream_from_url
(
const
char
*
url
);
struct
apk_istream
*
apk_istream_from_
fd_
url
(
int
atfd
,
const
char
*
url
);
struct
apk_istream
*
apk_istream_from_url_gz
(
const
char
*
url
);
size_t
apk_istream_skip
(
struct
apk_istream
*
istream
,
size_t
size
);
#define APK_SPLICE_ALL 0xffffffff
size_t
apk_istream_splice
(
void
*
stream
,
int
fd
,
size_t
size
,
apk_progress_cb
cb
,
void
*
cb_ctx
);
...
...
@@ -87,11 +89,15 @@ static inline struct apk_istream *apk_istream_from_fd(int fd)
{
return
apk_istream_from_fd_pid
(
fd
,
0
,
NULL
);
}
static
inline
struct
apk_istream
*
apk_istream_from_url
(
const
char
*
url
)
{
return
apk_istream_from_fd_url
(
-
1
,
url
);
}
struct
apk_bstream
*
apk_bstream_from_istream
(
struct
apk_istream
*
istream
);
struct
apk_bstream
*
apk_bstream_from_fd_pid
(
int
fd
,
pid_t
pid
,
int
(
*
translate_status
)(
int
));
struct
apk_bstream
*
apk_bstream_from_file
(
int
atfd
,
const
char
*
file
);
struct
apk_bstream
*
apk_bstream_from_url
(
const
char
*
url
);
struct
apk_bstream
*
apk_bstream_from_
fd_
url
(
int
atfd
,
const
char
*
url
);
struct
apk_bstream
*
apk_bstream_tee
(
struct
apk_bstream
*
from
,
int
atfd
,
const
char
*
to
);
static
inline
struct
apk_bstream
*
apk_bstream_from_fd
(
int
fd
)
...
...
@@ -99,6 +105,11 @@ static inline struct apk_bstream *apk_bstream_from_fd(int fd)
return
apk_bstream_from_fd_pid
(
fd
,
0
,
NULL
);
}
static
inline
struct
apk_bstream
*
apk_bstream_from_url
(
const
char
*
url
)
{
return
apk_bstream_from_fd_url
(
-
1
,
url
);
}
struct
apk_ostream
*
apk_ostream_to_fd
(
int
fd
);
struct
apk_ostream
*
apk_ostream_to_file
(
int
atfd
,
const
char
*
file
,
const
char
*
tmpfile
,
mode_t
mode
);
struct
apk_ostream
*
apk_ostream_to_file_gz
(
int
atfd
,
const
char
*
file
,
const
char
*
tmpfile
,
mode_t
mode
);
...
...
src/io.c
View file @
dbb64220
...
...
@@ -138,7 +138,7 @@ size_t apk_istream_splice(void *stream, int fd, size_t size,
bufsz
=
size
;
if
(
size
>
128
*
1024
)
{
if
(
ftruncate
(
fd
,
size
)
==
0
)
if
(
size
!=
APK_SPLICE_ALL
&&
ftruncate
(
fd
,
size
)
==
0
)
mmapbase
=
mmap
(
NULL
,
size
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
fd
,
0
);
if
(
bufsz
>
2
*
1024
*
1024
)
...
...
@@ -165,6 +165,8 @@ size_t apk_istream_splice(void *stream, int fd, size_t size,
r
=
is
->
read
(
is
,
buf
,
togo
);
if
(
r
<
0
)
goto
err
;
if
(
r
==
0
)
break
;
if
(
mmapbase
==
MAP_FAILED
)
{
if
(
write
(
fd
,
buf
,
r
)
!=
r
)
{
...
...
src/url.c
View file @
dbb64220
...
...
@@ -86,13 +86,13 @@ static int fork_wget(const char *url, pid_t *ppid)
return
fds
[
0
];
}
struct
apk_istream
*
apk_istream_from_url
(
const
char
*
url
)
struct
apk_istream
*
apk_istream_from_
fd_
url
(
int
atfd
,
const
char
*
url
)
{
pid_t
pid
;
int
fd
;
if
(
apk_url_local_file
(
url
)
!=
NULL
)
return
apk_istream_from_file
(
AT_FDCWD
,
apk_url_local_file
(
url
));
if
(
atfd
>=
0
&&
apk_url_local_file
(
url
)
!=
NULL
)
return
apk_istream_from_file
(
atfd
,
apk_url_local_file
(
url
));
fd
=
fork_wget
(
url
,
&
pid
);
return
apk_istream_from_fd_pid
(
fd
,
pid
,
translate_wget
);
...
...
@@ -103,13 +103,13 @@ struct apk_istream *apk_istream_from_url_gz(const char *file)
return
apk_bstream_gunzip
(
apk_bstream_from_url
(
file
));
}
struct
apk_bstream
*
apk_bstream_from_url
(
const
char
*
url
)
struct
apk_bstream
*
apk_bstream_from_
fd_
url
(
int
atfd
,
const
char
*
url
)
{
pid_t
pid
;
int
fd
;
if
(
apk_url_local_file
(
url
))
return
apk_bstream_from_file
(
AT_FDCWD
,
url
);
if
(
atfd
>=
0
&&
apk_url_local_file
(
url
))
return
apk_bstream_from_file
(
atfd
,
url
);
fd
=
fork_wget
(
url
,
&
pid
);
return
apk_bstream_from_fd_pid
(
fd
,
pid
,
translate_wget
);
...
...
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