mirror of
https://github.com/cesanta/mongoose.git
synced 2025-01-14 01:38:01 +08:00
Get rid of va_copy
This commit is contained in:
parent
1237185bb4
commit
ebd931f7af
@ -650,7 +650,7 @@ mg_send(c, "hi", 2); // Append string "hi" to the output buffer
|
||||
|
||||
```c
|
||||
int mg_printf(struct mg_connection *, const char *fmt, ...);
|
||||
int mg_vprintf(struct mg_connection *, const char *fmt, va_list ap);
|
||||
int mg_vprintf(struct mg_connection *, const char *fmt, va_list *ap);
|
||||
```
|
||||
|
||||
Same as `mg_send()`, but formats data using `printf()` semantics. Return
|
||||
|
19
mongoose.c
19
mongoose.c
@ -1607,13 +1607,10 @@ int mg_http_parse(const char *s, size_t len, struct mg_http_message *hm) {
|
||||
}
|
||||
|
||||
static void mg_http_vprintf_chunk(struct mg_connection *c, const char *fmt,
|
||||
va_list ap) {
|
||||
va_list *ap) {
|
||||
size_t len = c->send.len;
|
||||
va_list tmp;
|
||||
mg_send(c, " \r\n", 10);
|
||||
va_copy(tmp, ap);
|
||||
mg_vxprintf(mg_pfn_iobuf, &c->send, fmt, &tmp);
|
||||
va_end(tmp);
|
||||
mg_vxprintf(mg_pfn_iobuf, &c->send, fmt, ap);
|
||||
if (c->send.len >= len + 10) {
|
||||
mg_snprintf((char *) c->send.buf + len, 9, "%08lx", c->send.len - len - 10);
|
||||
c->send.buf[len + 8] = '\r';
|
||||
@ -1625,7 +1622,7 @@ static void mg_http_vprintf_chunk(struct mg_connection *c, const char *fmt,
|
||||
void mg_http_printf_chunk(struct mg_connection *c, const char *fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
mg_http_vprintf_chunk(c, fmt, ap);
|
||||
mg_http_vprintf_chunk(c, fmt, &ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
@ -3277,12 +3274,9 @@ struct mg_connection *mg_mqtt_listen(struct mg_mgr *mgr, const char *url,
|
||||
|
||||
|
||||
|
||||
size_t mg_vprintf(struct mg_connection *c, const char *fmt, va_list ap) {
|
||||
size_t mg_vprintf(struct mg_connection *c, const char *fmt, va_list *ap) {
|
||||
size_t old = c->send.len;
|
||||
va_list tmp;
|
||||
va_copy(tmp, ap);
|
||||
mg_vxprintf(mg_pfn_iobuf, &c->send, fmt, &tmp);
|
||||
va_end(tmp);
|
||||
mg_vxprintf(mg_pfn_iobuf, &c->send, fmt, ap);
|
||||
return c->send.len - old;
|
||||
}
|
||||
|
||||
@ -3290,7 +3284,7 @@ size_t mg_printf(struct mg_connection *c, const char *fmt, ...) {
|
||||
size_t len = 0;
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
len = mg_vprintf(c, fmt, ap);
|
||||
len = mg_vprintf(c, fmt, &ap);
|
||||
va_end(ap);
|
||||
return len;
|
||||
}
|
||||
@ -6765,7 +6759,6 @@ static void rx_dhcp(struct mip_if *ifp, struct pkt *pkt) {
|
||||
uint32_t lease = 0;
|
||||
memcpy(&lease, p + 2, sizeof(lease));
|
||||
ifp->lease_expire = ifp->now + mg_ntohl(lease) * 1000;
|
||||
// MG_INFO(("LEASEEEEEE %lld", ifp->lease_expire - ifp->now));
|
||||
}
|
||||
p += p[1] + 2;
|
||||
}
|
||||
|
13
mongoose.h
13
mongoose.h
@ -98,10 +98,6 @@ extern "C" {
|
||||
#include <nx_port.h>
|
||||
#include <tx_port.h>
|
||||
|
||||
#ifdef __REDLIB__
|
||||
#define va_copy(d, s) __builtin_va_copy(d, s)
|
||||
#endif
|
||||
|
||||
#define PATH_MAX FX_MAXIMUM_PATH
|
||||
#define MG_DIRSEP '\\'
|
||||
|
||||
@ -563,13 +559,6 @@ typedef int socklen_t;
|
||||
#define sleep(x) Sleep(x)
|
||||
#define mkdir(a, b) _mkdir(a)
|
||||
|
||||
#ifndef va_copy
|
||||
#ifdef __va_copy
|
||||
#define va_copy __va_copy
|
||||
#else
|
||||
#define va_copy(x, y) (x) = (y)
|
||||
#endif
|
||||
#endif
|
||||
#ifndef S_ISDIR
|
||||
#define S_ISDIR(x) (((x) &_S_IFMT) == _S_IFDIR)
|
||||
#endif
|
||||
@ -1095,7 +1084,7 @@ struct mg_connection *mg_wrapfd(struct mg_mgr *mgr, int fd,
|
||||
void mg_connect_resolved(struct mg_connection *);
|
||||
bool mg_send(struct mg_connection *, const void *, size_t);
|
||||
size_t mg_printf(struct mg_connection *, const char *fmt, ...);
|
||||
size_t mg_vprintf(struct mg_connection *, const char *fmt, va_list ap);
|
||||
size_t mg_vprintf(struct mg_connection *, const char *fmt, va_list *ap);
|
||||
char *mg_straddr(struct mg_addr *, char *, size_t);
|
||||
bool mg_aton(struct mg_str str, struct mg_addr *addr);
|
||||
char *mg_ntoa(const struct mg_addr *addr, char *buf, size_t len);
|
||||
|
@ -16,10 +16,6 @@
|
||||
#include <nx_port.h>
|
||||
#include <tx_port.h>
|
||||
|
||||
#ifdef __REDLIB__
|
||||
#define va_copy(d, s) __builtin_va_copy(d, s)
|
||||
#endif
|
||||
|
||||
#define PATH_MAX FX_MAXIMUM_PATH
|
||||
#define MG_DIRSEP '\\'
|
||||
|
||||
|
@ -78,13 +78,6 @@ typedef int socklen_t;
|
||||
#define sleep(x) Sleep(x)
|
||||
#define mkdir(a, b) _mkdir(a)
|
||||
|
||||
#ifndef va_copy
|
||||
#ifdef __va_copy
|
||||
#define va_copy __va_copy
|
||||
#else
|
||||
#define va_copy(x, y) (x) = (y)
|
||||
#endif
|
||||
#endif
|
||||
#ifndef S_ISDIR
|
||||
#define S_ISDIR(x) (((x) &_S_IFMT) == _S_IFDIR)
|
||||
#endif
|
||||
|
@ -267,13 +267,10 @@ int mg_http_parse(const char *s, size_t len, struct mg_http_message *hm) {
|
||||
}
|
||||
|
||||
static void mg_http_vprintf_chunk(struct mg_connection *c, const char *fmt,
|
||||
va_list ap) {
|
||||
va_list *ap) {
|
||||
size_t len = c->send.len;
|
||||
va_list tmp;
|
||||
mg_send(c, " \r\n", 10);
|
||||
va_copy(tmp, ap);
|
||||
mg_vxprintf(mg_pfn_iobuf, &c->send, fmt, &tmp);
|
||||
va_end(tmp);
|
||||
mg_vxprintf(mg_pfn_iobuf, &c->send, fmt, ap);
|
||||
if (c->send.len >= len + 10) {
|
||||
mg_snprintf((char *) c->send.buf + len, 9, "%08lx", c->send.len - len - 10);
|
||||
c->send.buf[len + 8] = '\r';
|
||||
@ -285,7 +282,7 @@ static void mg_http_vprintf_chunk(struct mg_connection *c, const char *fmt,
|
||||
void mg_http_printf_chunk(struct mg_connection *c, const char *fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
mg_http_vprintf_chunk(c, fmt, ap);
|
||||
mg_http_vprintf_chunk(c, fmt, &ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
@ -5,12 +5,9 @@
|
||||
#include "timer.h"
|
||||
#include "tls.h"
|
||||
|
||||
size_t mg_vprintf(struct mg_connection *c, const char *fmt, va_list ap) {
|
||||
size_t mg_vprintf(struct mg_connection *c, const char *fmt, va_list *ap) {
|
||||
size_t old = c->send.len;
|
||||
va_list tmp;
|
||||
va_copy(tmp, ap);
|
||||
mg_vxprintf(mg_pfn_iobuf, &c->send, fmt, &tmp);
|
||||
va_end(tmp);
|
||||
mg_vxprintf(mg_pfn_iobuf, &c->send, fmt, ap);
|
||||
return c->send.len - old;
|
||||
}
|
||||
|
||||
@ -18,7 +15,7 @@ size_t mg_printf(struct mg_connection *c, const char *fmt, ...) {
|
||||
size_t len = 0;
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
len = mg_vprintf(c, fmt, ap);
|
||||
len = mg_vprintf(c, fmt, &ap);
|
||||
va_end(ap);
|
||||
return len;
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ struct mg_connection *mg_wrapfd(struct mg_mgr *mgr, int fd,
|
||||
void mg_connect_resolved(struct mg_connection *);
|
||||
bool mg_send(struct mg_connection *, const void *, size_t);
|
||||
size_t mg_printf(struct mg_connection *, const char *fmt, ...);
|
||||
size_t mg_vprintf(struct mg_connection *, const char *fmt, va_list ap);
|
||||
size_t mg_vprintf(struct mg_connection *, const char *fmt, va_list *ap);
|
||||
char *mg_straddr(struct mg_addr *, char *, size_t);
|
||||
bool mg_aton(struct mg_str str, struct mg_addr *addr);
|
||||
char *mg_ntoa(const struct mg_addr *addr, char *buf, size_t len);
|
||||
|
@ -540,7 +540,7 @@ static int fetch(struct mg_mgr *mgr, char *buf, const char *url,
|
||||
}
|
||||
// c->is_hexdumping = 1;
|
||||
va_start(ap, fmt);
|
||||
mg_vprintf(c, fmt, ap);
|
||||
mg_vprintf(c, fmt, &ap);
|
||||
va_end(ap);
|
||||
buf[0] = '\0';
|
||||
for (i = 0; i < 50 && buf[0] == '\0'; i++) mg_mgr_poll(mgr, 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user