#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
+#include <io.h>
#endif
#ifdef _EVENT_HAVE_VASPRINTF
chain = buf->first;
- if (size == -1)
+ if (size < 0)
size = buf->total_len;
/* if size > buf->total_len, we cannot guarantee to the user that she
* is going to have a long enough buffer afterwards; so we return
* NULL */
- if (size == 0 || size > buf->total_len)
+ if (size == 0 || (size_t)size > buf->total_len)
goto done;
/* No need to pull up anything; the first size bytes are
* already here. */
- if (chain->off >= size) {
+ if (chain->off >= (size_t)size) {
result = chain->buffer + chain->misalign;
goto done;
}
/* Make sure that none of the chains we need to copy from is pinned. */
remaining = size - chain->off;
+ assert(remaining >= 0);
for (tmp=chain->next; tmp; tmp=tmp->next) {
if (CHAIN_PINNED(tmp))
goto done;
- if (tmp->off >= remaining)
+ if (tmp->off >= (size_t)remaining)
break;
remaining -= tmp->off;
}
tmp->off = size;
size -= old_off;
chain = chain->next;
- } else if (chain->buffer_len - chain->misalign >= size) {
+ } else if (chain->buffer_len - chain->misalign >= (size_t)size) {
/* already have enough space in the first chain */
size_t old_off = chain->off;
buffer = chain->buffer + chain->misalign + chain->off;
/* TODO(niels): deal with buffers that point to NULL like sendfile */
/* Copy and free every chunk that will be entirely pulled into tmp */
- for (; chain != NULL && size >= chain->off; chain = next) {
+ for (; chain != NULL && (size_t)size >= chain->off; chain = next) {
next = chain->next;
memcpy(buffer, chain->buffer + chain->misalign, chain->off);
evbuffer_strchr(struct evbuffer_iterator *it, const char chr)
{
struct evbuffer_chain *chain = it->chain;
- int i = it->off, count = 0;
+ unsigned i = it->off;
+ int count = 0;
while (chain != NULL) {
char *buffer = (char *)chain->buffer + chain->misalign;
for (; i < chain->off; ++i, ++count) {
evbuffer_strpbrk(struct evbuffer_iterator *it, const char *chrset)
{
struct evbuffer_chain *chain = it->chain;
- int i = it->off, count = 0;
+ unsigned i = it->off;
+ int count = 0;
while (chain != NULL) {
char *buffer = (char *)chain->buffer + chain->misalign;
for (; i < chain->off; ++i, ++count) {
static inline int
evbuffer_strspn(
- struct evbuffer_chain *chain, int i, const char *chrset)
+ struct evbuffer_chain *chain, unsigned i, const char *chrset)
{
int count = 0;
while (chain != NULL) {
struct evbuffer_chain *chain = it->chain;
int off = it->off;
- while (off >= chain->off) {
+ while ((size_t)off >= chain->off) {
off -= chain->off;
chain = chain->next;
if (chain == NULL)
buf->total_len += datlen;
buf->n_add_for_cb += datlen;
goto out;
- } else if (chain->misalign >= datlen && !CHAIN_PINNED(chain)) {
+ } else if ((size_t)chain->misalign >= datlen && !CHAIN_PINNED(chain)) {
/* we can fit the data into the misalignment */
evbuffer_chain_align(chain);
/* we cannot touch immutable buffers */
if ((chain->flags & EVBUFFER_IMMUTABLE) == 0) {
- if (chain->misalign >= datlen) {
+ if ((size_t)chain->misalign >= datlen) {
/* we have enough space */
memcpy(chain->buffer + chain->misalign - datlen,
data, datlen);
struct evbuffer_chain *chain;
int nvecs;
+ if (howmuch < 0)
+ return -1;
+
chain = buf->last;
if (chain->off == 0 && buf->previous_to_last &&
vecs[0].IOV_LEN_FIELD = CHAIN_SPACE_LEN(prev);
vecs[1].IOV_PTR_FIELD = CHAIN_SPACE_PTR(chain);
vecs[1].IOV_LEN_FIELD = CHAIN_SPACE_LEN(chain);
- if (vecs[0].IOV_LEN_FIELD >= howmuch) {
+ if (vecs[0].IOV_LEN_FIELD >= (size_t)howmuch) {
/* The next-to-last chain has enough
* space on its own. */
chain = prev;
/* We'll need both chains. */
chain = prev;
nvecs = 2;
- if (vecs[0].IOV_LEN_FIELD + vecs[1].IOV_LEN_FIELD > howmuch) {
+ if (vecs[0].IOV_LEN_FIELD + vecs[1].IOV_LEN_FIELD > (size_t)howmuch) {
vecs[1].IOV_LEN_FIELD = howmuch - vecs[0].IOV_LEN_FIELD;
}
}
nvecs = 1;
vecs[0].IOV_PTR_FIELD = CHAIN_SPACE_PTR(chain);
vecs[0].IOV_LEN_FIELD = CHAIN_SPACE_LEN(chain);
- if (vecs[0].IOV_LEN_FIELD > howmuch)
+ if (vecs[0].IOV_LEN_FIELD > (size_t)howmuch)
vecs[0].IOV_LEN_FIELD = howmuch;
}
*/
if (chain == NULL || n < EVBUFFER_MAX_READ)
n = EVBUFFER_MAX_READ;
- else if (n > chain->buffer_len << 2)
+ else if ((size_t)n > chain->buffer_len << 2)
n = chain->buffer_len << 2;
}
#endif
#ifdef USE_IOVEC_IMPL
if (nvecs == 2) {
- size_t space = CHAIN_SPACE_LEN(chain);
+ ssize_t space = CHAIN_SPACE_LEN(chain);
if (space < n) {
chain->off += space;
chain->next->off += n-space;
struct evbuffer_chain *chain = buffer->first;
int n, i = 0;
+ if (howmuch < 0)
+ return -1;
+
ASSERT_EVBUFFER_LOCKED(buffer);
/* XXX make this top out at some maximal data length? if the
* buffer has (say) 1MB in it, split over 128 chains, there's
break;
#endif
iov[i].IOV_PTR_FIELD = chain->buffer + chain->misalign;
- if (howmuch >= chain->off) {
+ if ((size_t)howmuch >= chain->off) {
iov[i++].IOV_LEN_FIELD = chain->off;
howmuch -= chain->off;
} else {
if (sz < 0)
goto done;
- if (sz < space) {
+ if ((size_t)sz < space) {
chain->off += sz;
buf->total_len += sz;
buf->n_add_for_cb += sz;
if (tmp == NULL)
return (-1);
+#ifdef WIN32
+#define lseek _lseek
+#endif
if (lseek(fd, offset, SEEK_SET) == -1) {
evbuffer_free(tmp);
return (-1);
evbuffer_add_buffer(outbuf, tmp);
evbuffer_free(tmp);
+#ifdef WIN32
+#define close _close
+#endif
close(fd);
}
}