Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libperf: Add preadn()

Add preadn() to provide pread() and readn() semantics.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/ab8918a4-7ac8-a37e-2e2c-28438c422d87@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
618ee783 237c96b8

+22
+2
tools/lib/perf/include/internal/lib.h
··· 9 9 ssize_t readn(int fd, void *buf, size_t n); 10 10 ssize_t writen(int fd, const void *buf, size_t n); 11 11 12 + ssize_t preadn(int fd, void *buf, size_t n, off_t offs); 13 + 12 14 #endif /* __LIBPERF_INTERNAL_CPUMAP_H */
+20
tools/lib/perf/lib.c
··· 38 38 return ion(true, fd, buf, n); 39 39 } 40 40 41 + ssize_t preadn(int fd, void *buf, size_t n, off_t offs) 42 + { 43 + size_t left = n; 44 + 45 + while (left) { 46 + ssize_t ret = pread(fd, buf, left, offs); 47 + 48 + if (ret < 0 && errno == EINTR) 49 + continue; 50 + if (ret <= 0) 51 + return ret; 52 + 53 + left -= ret; 54 + buf += ret; 55 + offs += ret; 56 + } 57 + 58 + return n; 59 + } 60 + 41 61 /* 42 62 * Write exactly 'n' bytes or return an error. 43 63 */