diff --git a/source3/lib/sys_rw_data.c b/source3/lib/sys_rw_data.c index e4f9a16345f..353dbe75c2d 100644 --- a/source3/lib/sys_rw_data.c +++ b/source3/lib/sys_rw_data.c @@ -105,3 +105,25 @@ ssize_t write_data(int fd, const void *buffer, size_t n) iov.iov_len = n; return write_data_iov(fd, &iov, 1); } + +/* + * Blocking read n bytes from a fd + */ + +ssize_t read_data(int fd, void *buffer, size_t n) +{ + ssize_t nread; + + nread = 0; + + while (nread < n) { + ssize_t ret; + ret = sys_read(fd, ((char *)buffer) + nread, n - nread); + if (ret <= 0) { + return ret; + } + nread += ret; + } + + return nread; +} diff --git a/source3/lib/sys_rw_data.h b/source3/lib/sys_rw_data.h index 5d1995b3342..bda3795d051 100644 --- a/source3/lib/sys_rw_data.h +++ b/source3/lib/sys_rw_data.h @@ -29,5 +29,6 @@ struct iovec; ssize_t write_data_iov(int fd, const struct iovec *iov, int iovcnt); ssize_t write_data(int fd, const void *buffer, size_t n); +ssize_t read_data(int fd, void *buffer, size_t n); #endif