mirror of https://github.com/getdnsapi/getdns.git
Deal with windows vsnprintf in config.h
This commit is contained in:
parent
2b9987014d
commit
30e1683d2f
|
@ -1108,7 +1108,6 @@ AH_BOTTOM([
|
||||||
# ifndef FD_SETSIZE
|
# ifndef FD_SETSIZE
|
||||||
# define FD_SETSIZE 1024
|
# define FD_SETSIZE 1024
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# define PRIsz "%Iu"
|
# define PRIsz "%Iu"
|
||||||
#else
|
#else
|
||||||
# define PRIsz "%zu"
|
# define PRIsz "%zu"
|
||||||
|
@ -1148,8 +1147,6 @@ AH_BOTTOM([
|
||||||
#define FD_SET_T
|
#define FD_SET_T
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -1204,6 +1201,12 @@ int inet_pton(int af, const char* src, void* dst);
|
||||||
const char *inet_ntop(int af, const void *src, char *dst, size_t size);
|
const char *inet_ntop(int af, const void *src, char *dst, size_t size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_WINSOCK
|
||||||
|
static inline int _gldns_custom_vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
||||||
|
{ int r = vsnprintf(str, size, format, ap); return r == -1 ? _vscprintf(format, ap) : r; }
|
||||||
|
# define vsnprintf _gldns_custom_vsnprintf
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -133,8 +133,8 @@ gldns_buffer_printf(gldns_buffer *buffer, const char *format, ...)
|
||||||
|
|
||||||
remaining = gldns_buffer_remaining(buffer);
|
remaining = gldns_buffer_remaining(buffer);
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
written = _gldns_vsnprintf((char*)gldns_buffer_current(buffer),
|
written = vsnprintf((char *) gldns_buffer_current(buffer), remaining,
|
||||||
remaining, format, args);
|
format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
if (written == -1) {
|
if (written == -1) {
|
||||||
buffer->_status_err = 1;
|
buffer->_status_err = 1;
|
||||||
|
@ -145,8 +145,7 @@ gldns_buffer_printf(gldns_buffer *buffer, const char *format, ...)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
written = _gldns_vsnprintf(
|
written = vsnprintf((char *) gldns_buffer_current(buffer),
|
||||||
(char *) gldns_buffer_current(buffer),
|
|
||||||
gldns_buffer_remaining(buffer), format, args);
|
gldns_buffer_remaining(buffer), format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
if (written == -1) {
|
if (written == -1) {
|
||||||
|
|
|
@ -27,21 +27,6 @@ extern "C" {
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef USE_WINSOCK
|
|
||||||
#define _gldns_vsnprintf vsnprintf
|
|
||||||
#else
|
|
||||||
/* Unlike Linux and BSD, vsnprintf on Windows returns -1 on overflow.
|
|
||||||
* Here it is redefined to always return the amount printed
|
|
||||||
* if enough space had been available.
|
|
||||||
*/
|
|
||||||
INLINE int
|
|
||||||
_gldns_vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
|
||||||
{
|
|
||||||
int r = vsnprintf(str, size, format, ap);
|
|
||||||
return r == -1 ? _vscprintf(format, ap) : r;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copy data allowing for unaligned accesses in network byte order
|
* Copy data allowing for unaligned accesses in network byte order
|
||||||
* (big endian).
|
* (big endian).
|
||||||
|
@ -175,7 +160,7 @@ gldns_buffer_invariant(gldns_buffer *buffer)
|
||||||
assert(buffer != NULL);
|
assert(buffer != NULL);
|
||||||
assert(buffer->_position <= buffer->_limit || buffer->_vfixed);
|
assert(buffer->_position <= buffer->_limit || buffer->_vfixed);
|
||||||
assert(buffer->_limit <= buffer->_capacity);
|
assert(buffer->_limit <= buffer->_capacity);
|
||||||
assert(buffer->_data != NULL || (buffer->_capacity == 0 && buffer->_vfixed));
|
assert(buffer->_data != NULL || (buffer->_vfixed && buffer->_capacity == 0));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -210,7 +195,7 @@ void gldns_buffer_init_frm_data(gldns_buffer *buffer, void *data, size_t size);
|
||||||
/**
|
/**
|
||||||
* Setup a buffer with the data pointed to. No data copied, no memory allocs.
|
* Setup a buffer with the data pointed to. No data copied, no memory allocs.
|
||||||
* The buffer is fixed. Writes beyond size (the capacity) will update the
|
* The buffer is fixed. Writes beyond size (the capacity) will update the
|
||||||
* position (and not write data. This allows to determine how big the buffer
|
* position (and not write data). This allows to determine how big the buffer
|
||||||
* should have been to contain all the written data.
|
* should have been to contain all the written data.
|
||||||
* \param[in] buffer pointer to the buffer to put the data in
|
* \param[in] buffer pointer to the buffer to put the data in
|
||||||
* \param[in] data the data to encapsulate in the buffer
|
* \param[in] data the data to encapsulate in the buffer
|
||||||
|
|
|
@ -279,7 +279,7 @@ int gldns_wire2str_dname_buf(uint8_t* d, size_t dlen, char* s, size_t slen)
|
||||||
|
|
||||||
int gldns_str_vprint(char** str, size_t* slen, const char* format, va_list args)
|
int gldns_str_vprint(char** str, size_t* slen, const char* format, va_list args)
|
||||||
{
|
{
|
||||||
int w = _gldns_vsnprintf(*str, *slen, format, args);
|
int w = vsnprintf(*str, *slen, format, args);
|
||||||
if(w < 0) {
|
if(w < 0) {
|
||||||
/* error in printout */
|
/* error in printout */
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue