mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-04-21 12:05:00 +00:00
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
c53c466484
commit
fdea75a555
2 changed files with 18 additions and 0 deletions
|
@ -19,3 +19,18 @@ process_check_success(process_t proc, const char *name, bool close) {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -91,6 +91,9 @@ is_regular_file(const char *path);
|
|||
ssize_t
|
||||
read_pipe(pipe_t pipe, char *data, size_t len);
|
||||
|
||||
ssize_t
|
||||
read_pipe_all(pipe_t pipe, char *data, size_t len);
|
||||
|
||||
void
|
||||
close_pipe(pipe_t pipe);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue