Re: [PATCH v2 01/13] perf header: encapsulate read and swap

From: Namhyung Kim
Date: Wed May 24 2017 - 11:36:34 EST


On Tue, May 23, 2017 at 12:48:41AM -0700, David Carrillo-Cisneros wrote:
> Most callers of readn in perf header read either a 32 or a 64 bits
> number, error check it and swap it, if necessary.
>
> Create do_read_u32 and do_read_u64 to simplify this usage.
>
> Signed-off-by: David Carrillo-Cisneros <davidcc@xxxxxxxxxx>
> ---
> tools/perf/util/header.c | 212 +++++++++++++++++------------------------------
> 1 file changed, 76 insertions(+), 136 deletions(-)
>
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index 948b2c5efb65..1dd4dbe13f88 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -117,27 +117,56 @@ static int do_write_string(int fd, const char *str)
> return write_padded(fd, str, olen, len);
> }
>
> +static int __do_read(int fd, void *addr, ssize_t size)
> +{
> + ssize_t ret = readn(fd, addr, size);
> +
> + if (ret != (ssize_t)size)

The 'size' is already ssize_t.

Thanks,
Namhyung


> + return ret < 0 ? (int)ret : -1;
> + return 0;
> +}