if ((req->type == EVHTTP_REQ_POST || req->type == EVHTTP_REQ_PUT) &&
evhttp_find_header(req->output_headers, "Content-Length") == NULL){
char size[22];
- evutil_snprintf(size, sizeof(size), "%ld",
- (long)evbuffer_get_length(req->output_buffer));
+ evutil_snprintf(size, sizeof(size), EV_SIZE_FMT,
+ EV_SIZE_ARG(evbuffer_get_length(req->output_buffer)));
evhttp_add_header(req->output_headers, "Content-Length", size);
}
}
* unless it already has a content-length or transfer-encoding header. */
static void
evhttp_maybe_add_content_length_header(struct evkeyvalq *headers,
- long content_length) /* XXX use size_t or int64, not long. */
+ size_t content_length)
{
if (evhttp_find_header(headers, "Transfer-Encoding") == NULL &&
evhttp_find_header(headers, "Content-Length") == NULL) {
char len[22];
- evutil_snprintf(len, sizeof(len), "%ld", content_length);
+ evutil_snprintf(len, sizeof(len), EV_SIZE_FMT,
+ EV_SIZE_ARG(content_length));
evhttp_add_header(headers, "Content-Length", len);
}
}
*/
evhttp_maybe_add_content_length_header(
req->output_headers,
- (long)evbuffer_get_length(req->output_buffer));
+ evbuffer_get_length(req->output_buffer));
}
}
input = bufferevent_get_input(evcon->bufev);
total_len = evbuffer_get_length(input);
- event_debug(("%s: read %d bytes in EVCON_IDLE state,"
- " resetting connection",
- __func__, (int)total_len));
+ event_debug(("%s: read "EV_SIZE_FMT
+ " bytes in EVCON_IDLE state,"
+ " resetting connection",
+ __func__, EV_SIZE_ARG(total_len)));
#endif
evhttp_connection_reset(evcon);
req->ntoread = ntoread;
}
- event_debug(("%s: bytes to read: %ld (in buffer %ld)\n",
- __func__, (long)req->ntoread,
- evbuffer_get_length(bufferevent_get_input(req->evcon->bufev))));
+ event_debug(("%s: bytes to read: "EV_I64_FMT" (in buffer "EV_SIZE_FMT")\n",
+ __func__, EV_I64_ARG(req->ntoread),
+ EV_SIZE_ARG(evbuffer_get_length(bufferevent_get_input(req->evcon->bufev)))));
return (0);
}
{
char buf[16];
int r;
+ ev_uint64_t u64 = ((ev_uint64_t)1000000000)*200;
+ ev_uint64_t i64 = -1 * (ev_int64_t) u64;
+ size_t size = 8000;
+ ev_ssize_t ssize = -9000;
+
r = evutil_snprintf(buf, sizeof(buf), "%d %d", 50, 100);
tt_str_op(buf, ==, "50 100");
tt_int_op(r, ==, 6);
tt_str_op(buf, ==, "longish 1234567");
tt_int_op(r, ==, 18);
+ r = evutil_snprintf(buf, sizeof(buf), EV_U64_FMT, EV_U64_ARG(u64));
+ tt_str_op(buf, ==, "200000000000");
+ tt_int_op(r, ==, 12);
+
+ r = evutil_snprintf(buf, sizeof(buf), EV_I64_FMT, EV_I64_ARG(i64));
+ tt_str_op(buf, ==, "-200000000000");
+ tt_int_op(r, ==, 13);
+
+ r = evutil_snprintf(buf, sizeof(buf), EV_SIZE_FMT" "EV_SSIZE_FMT,
+ EV_SIZE_ARG(size), EV_SSIZE_ARG(ssize));
+ tt_str_op(buf, ==, "8000 -9000");
+ tt_int_op(r, ==, 10);
+
end:
;
}
HANDLE evutil_load_windows_system_library(const TCHAR *library_name);
#endif
+#ifndef EV_SIZE_FMT
+#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
+#define EV_U64_FMT "%I64u"
+#define EV_I64_FMT "%I64d"
+#define EV_I64_ARG(x) ((__int64)(x))
+#define EV_U64_ARG(x) ((unsigned __int64)(x))
+#else
+#define EV_U64_FMT "%llu"
+#define EV_I64_FMT "%lld"
+#define EV_I64_ARG(x) ((long long)(x))
+#define EV_U64_ARG(x) ((unsigned long long)(x))
+#endif
+#endif
+
+#if defined(__STDC__) && defined(__STDC_VERSION__)
+#if (__STDC_VERSION__ >= 199901L)
+#define EV_SIZE_FMT "%zu"
+#define EV_SSIZE_FMT "%zd"
+#define EV_SIZE_ARG(x) (x)
+#define EV_SSIZE_ARG(x) (x)
+#endif
+#endif
+
+#ifndef EV_SIZE_FMT
+#if (_EVENT_SIZEOF_SIZE_T <= _EVENT_SIZEOF_LONG)
+#define EV_SIZE_FMT "%lu"
+#define EV_SSIZE_FMT "%ld"
+#define EV_SIZE_ARG(x) ((unsigned long)(x))
+#define EV_SSIZE_ARG(x) ((long)(x))
+#else
+#define EV_SIZE_FMT EV_U64_FMT
+#define EV_SSIZE_FMT EV_I64_FMT
+#define EV_SIZE_ARG(x) EV_U64_ARG(x)
+#define EV_SSIZE_ARG(x) EV_I64_ARG(x)
+#endif
+#endif
+
#ifdef __cplusplus
}
#endif