mirror of https://github.com/getdnsapi/getdns.git
Deal with windows vsnprintf in config.h
This commit is contained in:
parent
2b9987014d
commit
30e1683d2f
21
configure.ac
21
configure.ac
|
@ -1101,17 +1101,16 @@ AH_BOTTOM([
|
|||
#endif
|
||||
|
||||
#ifdef GETDNS_ON_WINDOWS
|
||||
/* On windows it is allowed to increase the FD_SETSIZE
|
||||
/* On windows it is allowed to increase the FD_SETSIZE
|
||||
* (and nescessary to make our custom eventloop work)
|
||||
* See: https://support.microsoft.com/en-us/kb/111855
|
||||
*/
|
||||
#ifndef FD_SETSIZE
|
||||
#define FD_SETSIZE 1024
|
||||
#endif
|
||||
|
||||
#define PRIsz "%Iu"
|
||||
# ifndef FD_SETSIZE
|
||||
# define FD_SETSIZE 1024
|
||||
# endif
|
||||
# define PRIsz "%Iu"
|
||||
#else
|
||||
#define PRIsz "%zu"
|
||||
# define PRIsz "%zu"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
@ -1148,8 +1147,6 @@ AH_BOTTOM([
|
|||
#define FD_SET_T
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#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);
|
||||
#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
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -133,8 +133,8 @@ gldns_buffer_printf(gldns_buffer *buffer, const char *format, ...)
|
|||
|
||||
remaining = gldns_buffer_remaining(buffer);
|
||||
va_start(args, format);
|
||||
written = _gldns_vsnprintf((char*)gldns_buffer_current(buffer),
|
||||
remaining, format, args);
|
||||
written = vsnprintf((char *) gldns_buffer_current(buffer), remaining,
|
||||
format, args);
|
||||
va_end(args);
|
||||
if (written == -1) {
|
||||
buffer->_status_err = 1;
|
||||
|
@ -145,8 +145,7 @@ gldns_buffer_printf(gldns_buffer *buffer, const char *format, ...)
|
|||
return -1;
|
||||
}
|
||||
va_start(args, format);
|
||||
written = _gldns_vsnprintf(
|
||||
(char *) gldns_buffer_current(buffer),
|
||||
written = vsnprintf((char *) gldns_buffer_current(buffer),
|
||||
gldns_buffer_remaining(buffer), format, args);
|
||||
va_end(args);
|
||||
if (written == -1) {
|
||||
|
|
|
@ -27,21 +27,6 @@ extern "C" {
|
|||
# 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
|
||||
* (big endian).
|
||||
|
@ -175,7 +160,7 @@ gldns_buffer_invariant(gldns_buffer *buffer)
|
|||
assert(buffer != NULL);
|
||||
assert(buffer->_position <= buffer->_limit || buffer->_vfixed);
|
||||
assert(buffer->_limit <= buffer->_capacity);
|
||||
assert(buffer->_data != NULL || (buffer->_capacity == 0 && buffer->_vfixed));
|
||||
assert(buffer->_data != NULL || (buffer->_vfixed && buffer->_capacity == 0));
|
||||
}
|
||||
#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.
|
||||
* 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.
|
||||
* \param[in] buffer pointer to the buffer to put the data in
|
||||
* \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 w = _gldns_vsnprintf(*str, *slen, format, args);
|
||||
int w = vsnprintf(*str, *slen, format, args);
|
||||
if(w < 0) {
|
||||
/* error in printout */
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue