1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00
samba-mirror/lib/ccan/read_write_all/read_write_all.c
Rusty Russell 361f3ea9ee lib/ccan: import failtest and required ccan modules for TDB2 unit tests.
New modules: failtest, list, time, read_write_all and tlist.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2012-03-07 13:16:16 +11:00

39 lines
663 B
C

/* Licensed under LGPLv2+ - see LICENSE file for details */
#include "read_write_all.h"
#include <unistd.h>
#include <errno.h>
bool write_all(int fd, const void *data, size_t size)
{
while (size) {
ssize_t done;
done = write(fd, data, size);
if (done < 0 && errno == EINTR)
continue;
if (done <= 0)
return false;
data = (const char *)data + done;
size -= done;
}
return true;
}
bool read_all(int fd, void *data, size_t size)
{
while (size) {
ssize_t done;
done = read(fd, data, size);
if (done < 0 && errno == EINTR)
continue;
if (done <= 0)
return false;
data = (char *)data + done;
size -= done;
}
return true;
}