vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / net / sock / writen.c
blob1cd10431cc41851a5fb46b6964be1f9fd49a8fbb
1 /* -*- c-basic-offset: 8; -*- */
2 /* include writen */
3 #include "sock.h"
5 ssize_t /* Write "n" bytes to a descriptor. */
6 writen(int fd, const void *vptr, size_t n)
8 size_t nleft;
9 ssize_t nwritten;
10 const char *ptr;
12 ptr = vptr;
13 nleft = n;
14 while (nleft > 0) {
15 if ( (nwritten = write(fd, ptr, nleft)) <= 0) {
16 if (errno == EINTR)
17 nwritten = 0; /* and call write() again */
18 else
19 return(-1); /* error */
22 nleft -= nwritten;
23 ptr += nwritten;
25 return(n);
27 /* end writen */