aboutsummaryrefslogtreecommitdiff
path: root/tools/perf/util/util.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2013-11-28 11:30:16 +0100
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-12-02 09:22:46 -0300
commitbc3a502bc2bc78d03526d6abcc5697aab18d5ae9 (patch)
tree9811125522636d12b6c2bb67d8ef4e8c69f6511c /tools/perf/util/util.c
parent838d14520267769648fb2fc2a637107a1d102590 (diff)
perf tools: Add writen function
Adding 'writen' function as a synchronous wrapper for write syscall with following prototype: ssize_t writen(int fd, void *buf, size_t n) Returns the number of bytes written on success or -1 in case of err. Signed-off-by: Jiri Olsa <jolsa@redhat.com> Requested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1385634619-8129-5-git-send-email-jolsa@redhat.com 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.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 6ea0b4ae956..b1d5376b9dd 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -152,16 +152,14 @@ unsigned long convert_unit(unsigned long value, char *unit)
return value;
}
-/*
- * Read exactly 'n' bytes or return an error.
- */
-ssize_t readn(int fd, void *buf, size_t n)
+static ssize_t ion(bool is_read, int fd, void *buf, size_t n)
{
void *buf_start = buf;
size_t left = n;
while (left) {
- ssize_t ret = read(fd, buf, left);
+ ssize_t ret = is_read ? read(fd, buf, left) :
+ write(fd, buf, left);
if (ret <= 0)
return ret;
@@ -174,6 +172,22 @@ ssize_t readn(int fd, void *buf, size_t n)
return n;
}
+/*
+ * Read exactly 'n' bytes or return an error.
+ */
+ssize_t readn(int fd, void *buf, size_t n)
+{
+ return ion(true, fd, buf, n);
+}
+
+/*
+ * Write exactly 'n' bytes or return an error.
+ */
+ssize_t writen(int fd, void *buf, size_t n)
+{
+ return ion(false, fd, buf, n);
+}
+
size_t hex_width(u64 v)
{
size_t n = 1;