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

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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
bc3a502b 838d1452

+20 -5
+19 -5
tools/perf/util/util.c
··· 152 152 return value; 153 153 } 154 154 155 - /* 156 - * Read exactly 'n' bytes or return an error. 157 - */ 158 - ssize_t readn(int fd, void *buf, size_t n) 155 + static ssize_t ion(bool is_read, int fd, void *buf, size_t n) 159 156 { 160 157 void *buf_start = buf; 161 158 size_t left = n; 162 159 163 160 while (left) { 164 - ssize_t ret = read(fd, buf, left); 161 + ssize_t ret = is_read ? read(fd, buf, left) : 162 + write(fd, buf, left); 165 163 166 164 if (ret <= 0) 167 165 return ret; ··· 170 172 171 173 BUG_ON((size_t)(buf - buf_start) != n); 172 174 return n; 175 + } 176 + 177 + /* 178 + * Read exactly 'n' bytes or return an error. 179 + */ 180 + ssize_t readn(int fd, void *buf, size_t n) 181 + { 182 + return ion(true, fd, buf, n); 183 + } 184 + 185 + /* 186 + * Write exactly 'n' bytes or return an error. 187 + */ 188 + ssize_t writen(int fd, void *buf, size_t n) 189 + { 190 + return ion(false, fd, buf, n); 173 191 } 174 192 175 193 size_t hex_width(u64 v)
+1
tools/perf/util/util.h
··· 254 254 char *strxfrchar(char *s, char from, char to); 255 255 unsigned long convert_unit(unsigned long value, char *unit); 256 256 ssize_t readn(int fd, void *buf, size_t n); 257 + ssize_t writen(int fd, void *buf, size_t n); 257 258 258 259 struct perf_event_attr; 259 260