mirror of
git://git.suckless.org/sbase
synced 2024-12-22 23:13:44 +00:00
5cb3a1eba1
writeall makes successive write calls to write an entire buffer to the output file descriptor. It returns the number of bytes written, or -1 on the first error.
22 lines
318 B
C
22 lines
318 B
C
/* See LICENSE file for copyright and license details. */
|
|
#include <unistd.h>
|
|
|
|
#include "../util.h"
|
|
|
|
ssize_t
|
|
writeall(int fd, const void *buf, size_t len)
|
|
{
|
|
const char *p = buf;
|
|
ssize_t n;
|
|
|
|
while (len) {
|
|
n = write(fd, p, len);
|
|
if (n <= 0)
|
|
return n;
|
|
p += n;
|
|
len -= n;
|
|
}
|
|
|
|
return p - (const char *)buf;
|
|
}
|