mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-12 13:55:32 +00:00
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>
This commit is contained in:
parent
838d145202
commit
bc3a502bc2
2 changed files with 20 additions and 5 deletions
|
@ -152,16 +152,14 @@ unsigned long convert_unit(unsigned long value, char *unit)
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static ssize_t ion(bool is_read, int fd, void *buf, size_t n)
|
||||||
* Read exactly 'n' bytes or return an error.
|
|
||||||
*/
|
|
||||||
ssize_t readn(int fd, void *buf, size_t n)
|
|
||||||
{
|
{
|
||||||
void *buf_start = buf;
|
void *buf_start = buf;
|
||||||
size_t left = n;
|
size_t left = n;
|
||||||
|
|
||||||
while (left) {
|
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)
|
if (ret <= 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -174,6 +172,22 @@ ssize_t readn(int fd, void *buf, size_t n)
|
||||||
return 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 hex_width(u64 v)
|
||||||
{
|
{
|
||||||
size_t n = 1;
|
size_t n = 1;
|
||||||
|
|
|
@ -254,6 +254,7 @@ int strtailcmp(const char *s1, const char *s2);
|
||||||
char *strxfrchar(char *s, char from, char to);
|
char *strxfrchar(char *s, char from, char to);
|
||||||
unsigned long convert_unit(unsigned long value, char *unit);
|
unsigned long convert_unit(unsigned long value, char *unit);
|
||||||
ssize_t readn(int fd, void *buf, size_t n);
|
ssize_t readn(int fd, void *buf, size_t n);
|
||||||
|
ssize_t writen(int fd, void *buf, size_t n);
|
||||||
|
|
||||||
struct perf_event_attr;
|
struct perf_event_attr;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue