Add read_pipe_all()
Add a convenience function to read from a pipe until all requested data has been read.
This commit is contained in:
parent
96b18dabaa
commit
0681480809
2 changed files with 18 additions and 0 deletions
|
@ -61,3 +61,18 @@ get_local_file_path(const char *name) {
|
||||||
|
|
||||||
return file_path;
|
return file_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssize_t
|
||||||
|
read_pipe_all(pipe_t pipe, char *data, size_t len) {
|
||||||
|
size_t copied = 0;
|
||||||
|
while (len > 0) {
|
||||||
|
ssize_t r = read_pipe(pipe, data, len);
|
||||||
|
if (r <= 0) {
|
||||||
|
return copied ? (ssize_t) copied : r;
|
||||||
|
}
|
||||||
|
len -= r;
|
||||||
|
data += r;
|
||||||
|
copied += r;
|
||||||
|
}
|
||||||
|
return copied;
|
||||||
|
}
|
||||||
|
|
|
@ -96,6 +96,9 @@ is_regular_file(const char *path);
|
||||||
ssize_t
|
ssize_t
|
||||||
read_pipe(pipe_t pipe, char *data, size_t len);
|
read_pipe(pipe_t pipe, char *data, size_t len);
|
||||||
|
|
||||||
|
ssize_t
|
||||||
|
read_pipe_all(pipe_t pipe, char *data, size_t len);
|
||||||
|
|
||||||
void
|
void
|
||||||
close_pipe(pipe_t pipe);
|
close_pipe(pipe_t pipe);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue