aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/util.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2019-07-21 07:24:47 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-07-29 17:34:46 -0400
commitc03538b1f1a7e0e996a8d6feb20cf001d4b14939 (patch)
tree792c570d6799972d174c4f847d83373f6e0c39d1 /tools/perf/util/util.c
parent5643b1a59e581ac3f66d36caba8124313cc446c0 (diff)
libperf: Adopt the readn()/writen() functions from tools/perf
Move the readn()/writen() functions into libperf. Keep those non-namespaced names because they will be shared only between perf and libperf. Again, these are not exported functions. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexey Budankov <alexey.budankov@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Michael Petlan <mpetlan@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20190721112506.12306-61-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/util.c')
-rw-r--r--tools/perf/util/util.c40
1 files changed, 0 insertions, 40 deletions
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index a61535cf1bca..9c3c97697387 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -384,46 +384,6 @@ int copyfile(const char *from, const char *to)
384 return copyfile_mode(from, to, 0755); 384 return copyfile_mode(from, to, 0755);
385} 385}
386 386
387static ssize_t ion(bool is_read, int fd, void *buf, size_t n)
388{
389 void *buf_start = buf;
390 size_t left = n;
391
392 while (left) {
393 /* buf must be treated as const if !is_read. */
394 ssize_t ret = is_read ? read(fd, buf, left) :
395 write(fd, buf, left);
396
397 if (ret < 0 && errno == EINTR)
398 continue;
399 if (ret <= 0)
400 return ret;
401
402 left -= ret;
403 buf += ret;
404 }
405
406 BUG_ON((size_t)(buf - buf_start) != n);
407 return n;
408}
409
410/*
411 * Read exactly 'n' bytes or return an error.
412 */
413ssize_t readn(int fd, void *buf, size_t n)
414{
415 return ion(true, fd, buf, n);
416}
417
418/*
419 * Write exactly 'n' bytes or return an error.
420 */
421ssize_t writen(int fd, const void *buf, size_t n)
422{
423 /* ion does not modify buf. */
424 return ion(false, fd, (void *)buf, n);
425}
426
427size_t hex_width(u64 v) 387size_t hex_width(u64 v)
428{ 388{
429 size_t n = 1; 389 size_t n = 1;