Re: [PATCHv2 2/8] util: fix saferead type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Nov 23, 2010 at 04:49:55PM -0700, Eric Blake wrote:
> * src/util/util.c (saferead): Fix return type.
> (safewrite): Fix indentation.
> ---
> 
> v2: new patch.  Not really essential to the series, so much as a
> trivial cleanup I noticed while in the area.
> 
>  src/util/util.c |   64 ++++++++++++++++++++++++++++--------------------------
>  src/util/util.h |    2 +-
>  2 files changed, 34 insertions(+), 32 deletions(-)
> 
> diff --git a/src/util/util.c b/src/util/util.c
> index 3a27c23..f6050de 100644
> --- a/src/util/util.c
> +++ b/src/util/util.c
> @@ -88,42 +88,44 @@ verify(sizeof(gid_t) <= sizeof (unsigned int) &&
>                               __FUNCTION__, __LINE__, __VA_ARGS__)
> 
>  /* Like read(), but restarts after EINTR */
> -int saferead(int fd, void *buf, size_t count)
> -{
> -        size_t nread = 0;
> -        while (count > 0) {
> -                ssize_t r = read(fd, buf, count);
> -                if (r < 0 && errno == EINTR)
> -                        continue;
> -                if (r < 0)
> -                        return r;
> -                if (r == 0)
> -                        return nread;
> -                buf = (char *)buf + r;
> -                count -= r;
> -                nread += r;
> -        }
> -        return nread;
> +ssize_t
> +saferead(int fd, void *buf, size_t count)
> +{
> +    size_t nread = 0;
> +    while (count > 0) {
> +        ssize_t r = read(fd, buf, count);
> +        if (r < 0 && errno == EINTR)
> +            continue;
> +        if (r < 0)
> +            return r;
> +        if (r == 0)
> +            return nread;
> +        buf = (char *)buf + r;
> +        count -= r;
> +        nread += r;
> +    }
> +    return nread;
>  }
> 
>  /* Like write(), but restarts after EINTR */
> -ssize_t safewrite(int fd, const void *buf, size_t count)
> -{
> -        size_t nwritten = 0;
> -        while (count > 0) {
> -                ssize_t r = write(fd, buf, count);
> -
> -                if (r < 0 && errno == EINTR)
> -                        continue;
> -                if (r < 0)
> -                        return r;
> -                if (r == 0)
> -                        return nwritten;
> -                buf = (const char *)buf + r;
> -                count -= r;
> -                nwritten += r;
> -        }
> -        return nwritten;
> +ssize_t
> +safewrite(int fd, const void *buf, size_t count)
> +{
> +    size_t nwritten = 0;
> +    while (count > 0) {
> +        ssize_t r = write(fd, buf, count);
> +
> +        if (r < 0 && errno == EINTR)
> +            continue;
> +        if (r < 0)
> +            return r;
> +        if (r == 0)
> +            return nwritten;
> +        buf = (const char *)buf + r;
> +        count -= r;
> +        nwritten += r;
> +    }
> +    return nwritten;
>  }
> 
>  #ifdef HAVE_POSIX_FALLOCATE
> diff --git a/src/util/util.h b/src/util/util.h
> index edbf01e..deaf8bb 100644
> --- a/src/util/util.h
> +++ b/src/util/util.h
> @@ -37,7 +37,7 @@
>  #  define MIN(a, b) ((a) < (b) ? (a) : (b))
>  # endif
> 
> -int saferead(int fd, void *buf, size_t count) ATTRIBUTE_RETURN_CHECK;
> +ssize_t saferead(int fd, void *buf, size_t count) ATTRIBUTE_RETURN_CHECK;
>  ssize_t safewrite(int fd, const void *buf, size_t count)
>      ATTRIBUTE_RETURN_CHECK;
>  int safezero(int fd, int flags, off_t offset, off_t len)

ACK

Daniel

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]