mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
util: fix saferead type
* src/util/util.c (saferead): Fix return type. (safewrite): Fix indentation.
This commit is contained in:
parent
19240c3c00
commit
dbab6bb5cf
@ -88,42 +88,44 @@ verify(sizeof(gid_t) <= sizeof (unsigned int) &&
|
|||||||
__FUNCTION__, __LINE__, __VA_ARGS__)
|
__FUNCTION__, __LINE__, __VA_ARGS__)
|
||||||
|
|
||||||
/* Like read(), but restarts after EINTR */
|
/* Like read(), but restarts after EINTR */
|
||||||
int saferead(int fd, void *buf, size_t count)
|
ssize_t
|
||||||
|
saferead(int fd, void *buf, size_t count)
|
||||||
{
|
{
|
||||||
size_t nread = 0;
|
size_t nread = 0;
|
||||||
while (count > 0) {
|
while (count > 0) {
|
||||||
ssize_t r = read(fd, buf, count);
|
ssize_t r = read(fd, buf, count);
|
||||||
if (r < 0 && errno == EINTR)
|
if (r < 0 && errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
if (r == 0)
|
if (r == 0)
|
||||||
return nread;
|
return nread;
|
||||||
buf = (char *)buf + r;
|
buf = (char *)buf + r;
|
||||||
count -= r;
|
count -= r;
|
||||||
nread += r;
|
nread += r;
|
||||||
}
|
}
|
||||||
return nread;
|
return nread;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Like write(), but restarts after EINTR */
|
/* Like write(), but restarts after EINTR */
|
||||||
ssize_t safewrite(int fd, const void *buf, size_t count)
|
ssize_t
|
||||||
|
safewrite(int fd, const void *buf, size_t count)
|
||||||
{
|
{
|
||||||
size_t nwritten = 0;
|
size_t nwritten = 0;
|
||||||
while (count > 0) {
|
while (count > 0) {
|
||||||
ssize_t r = write(fd, buf, count);
|
ssize_t r = write(fd, buf, count);
|
||||||
|
|
||||||
if (r < 0 && errno == EINTR)
|
if (r < 0 && errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
if (r == 0)
|
if (r == 0)
|
||||||
return nwritten;
|
return nwritten;
|
||||||
buf = (const char *)buf + r;
|
buf = (const char *)buf + r;
|
||||||
count -= r;
|
count -= r;
|
||||||
nwritten += r;
|
nwritten += r;
|
||||||
}
|
}
|
||||||
return nwritten;
|
return nwritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_POSIX_FALLOCATE
|
#ifdef HAVE_POSIX_FALLOCATE
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
# define MIN(a, b) ((a) < (b) ? (a) : (b))
|
# define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
# endif
|
# 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)
|
ssize_t safewrite(int fd, const void *buf, size_t count)
|
||||||
ATTRIBUTE_RETURN_CHECK;
|
ATTRIBUTE_RETURN_CHECK;
|
||||||
int safezero(int fd, int flags, off_t offset, off_t len)
|
int safezero(int fd, int flags, off_t offset, off_t len)
|
||||||
|
Loading…
Reference in New Issue
Block a user