[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tip-bc3a502bc2bc78d03526d6abcc5697aab18d5ae9@git.kernel.org>
Date: Wed, 4 Dec 2013 07:40:32 -0800
From: tip-bot for Jiri Olsa <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, acme@...hat.com, hpa@...or.com,
mingo@...nel.org, peterz@...radead.org, efault@....de,
namhyung@...nel.org, jolsa@...hat.com, fweisbec@...il.com,
adrian.hunter@...el.com, dsahern@...il.com, tglx@...utronix.de
Subject: [tip:perf/core] perf tools: Add writen function
Commit-ID: bc3a502bc2bc78d03526d6abcc5697aab18d5ae9
Gitweb: http://git.kernel.org/tip/bc3a502bc2bc78d03526d6abcc5697aab18d5ae9
Author: Jiri Olsa <jolsa@...hat.com>
AuthorDate: Thu, 28 Nov 2013 11:30:16 +0100
Committer: Arnaldo Carvalho de Melo <acme@...hat.com>
CommitDate: Mon, 2 Dec 2013 09:22:46 -0300
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@...hat.com>
Requested-by: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: Adrian Hunter <adrian.hunter@...el.com>
Cc: David Ahern <dsahern@...il.com>
Cc: Frederic Weisbecker <fweisbec@...il.com>
Cc: Ingo Molnar <mingo@...nel.org>
Cc: Mike Galbraith <efault@....de>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Peter Zijlstra <peterz@...radead.org>
Link: http://lkml.kernel.org/r/1385634619-8129-5-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
---
tools/perf/util/util.c | 24 +++++++++++++++++++-----
tools/perf/util/util.h | 1 +
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 6ea0b4a..b1d5376 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;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 9f6b928..ce0f73d 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -254,6 +254,7 @@ int strtailcmp(const char *s1, const char *s2);
char *strxfrchar(char *s, char from, char to);
unsigned long convert_unit(unsigned long value, char *unit);
ssize_t readn(int fd, void *buf, size_t n);
+ssize_t writen(int fd, void *buf, size_t n);
struct perf_event_attr;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists