3 /* Copyright 1998 by the Massachusetts Institute of Technology.
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for any purpose and without
7 * fee is hereby granted, provided that the above copyright
8 * notice appear in all copies and that both that copyright
9 * notice and this permission notice appear in supporting
10 * documentation, and that the name of M.I.T. not be used in
11 * advertising or publicity pertaining to distribution of the
12 * software without specific, written prior permission.
13 * M.I.T. makes no representations about the suitability of
14 * this software for any purpose. It is provided "as is"
15 * without express or implied warranty.
18 #include "ares_setup.h"
25 #include "ares_private.h"
28 ssize_t ares_writev(ares_socket_t s, const struct iovec *iov, int iovcnt)
42 /* Validate and find the sum of the iov_len values in the iov array */
43 for (i = 0; i < iovcnt; i++)
45 if (iov[i].iov_len > INT_MAX - bytes)
50 bytes += iov[i].iov_len;
56 /* Allocate a temporary buffer to hold the data */
57 buffer = ares_malloc(bytes);
64 /* Copy the data into buffer */
65 for (bp = buffer, i = 0; i < iovcnt; ++i)
67 memcpy (bp, iov[i].iov_base, iov[i].iov_len);
71 /* Send buffer contents */
72 result = swrite(s, buffer, bytes);