diff options
| author | Adrian Hunter <[email protected]> | 2022-05-20 15:56:04 +0000 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <[email protected]> | 2022-05-23 13:11:12 +0000 |
| commit | 618ee7838e409513635320ca9c4c8d52c44f2dd0 (patch) | |
| tree | e6d84ca947db644cbcd7816056989b0de8a8e35f /tools/lib/perf/lib.c | |
| parent | perf header: Add ability to keep feature sections (diff) | |
| download | kernel-618ee7838e409513635320ca9c4c8d52c44f2dd0.tar.gz kernel-618ee7838e409513635320ca9c4c8d52c44f2dd0.zip | |
libperf: Add preadn()
Add preadn() to provide pread() and readn() semantics.
Signed-off-by: Adrian Hunter <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Diffstat (limited to 'tools/lib/perf/lib.c')
| -rw-r--r-- | tools/lib/perf/lib.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/lib/perf/lib.c b/tools/lib/perf/lib.c index 18658931fc71..696fb0ea67c6 100644 --- a/tools/lib/perf/lib.c +++ b/tools/lib/perf/lib.c @@ -38,6 +38,26 @@ ssize_t readn(int fd, void *buf, size_t n) return ion(true, fd, buf, n); } +ssize_t preadn(int fd, void *buf, size_t n, off_t offs) +{ + size_t left = n; + + while (left) { + ssize_t ret = pread(fd, buf, left, offs); + + if (ret < 0 && errno == EINTR) + continue; + if (ret <= 0) + return ret; + + left -= ret; + buf += ret; + offs += ret; + } + + return n; +} + /* * Write exactly 'n' bytes or return an error. */ |
