A better approach for the Windows strdup issue

This commit is contained in:
Willem Toorop 2017-05-02 17:22:06 +02:00
parent dab93cd197
commit ed08025c38
3 changed files with 9 additions and 25 deletions

View File

@ -1160,9 +1160,14 @@ AH_BOTTOM([
* See: https://support.microsoft.com/en-us/kb/111855 * See: https://support.microsoft.com/en-us/kb/111855
*/ */
# ifndef FD_SETSIZE # ifndef FD_SETSIZE
# define FD_SETSIZE 1024 # define FD_SETSIZE 1024
# endif # endif
# define PRIsz "%Iu" # define PRIsz "%Iu"
/* Windows wants us to use _strdup instead of strdup */
# ifndef strdup
# define strdup _strdup
# endif
#else #else
# define PRIsz "%zu" # define PRIsz "%zu"
#endif #endif

View File

@ -57,15 +57,6 @@
#include "convert.h" #include "convert.h"
#include "debug.h" #include "debug.h"
/* strdup is marked deprecated by the Windows compiler */
#ifndef STRDUP
#ifdef GETDNS_ON_WINDOWS
#define STRDUP(x) _strdup(x)
#else
#define STRDUP(x) strdup(x)
#endif
#endif
getdns_return_t getdns_return_t
getdns_convert_dns_name_to_fqdn( getdns_convert_dns_name_to_fqdn(
const getdns_bindata *dns_name_wire_fmt, char **fqdn_as_string) const getdns_bindata *dns_name_wire_fmt, char **fqdn_as_string)
@ -212,7 +203,7 @@ getdns_display_ip_address(const struct getdns_bindata
buff, buff,
256); 256);
if (ipStr) { if (ipStr) {
return STRDUP(ipStr); return strdup(ipStr);
} }
} else if (bindata_of_ipv4_or_ipv6_address->size == 16) { } else if (bindata_of_ipv4_or_ipv6_address->size == 16) {
const char *ipStr = inet_ntop(AF_INET6, const char *ipStr = inet_ntop(AF_INET6,
@ -220,7 +211,7 @@ getdns_display_ip_address(const struct getdns_bindata
buff, buff,
256); 256);
if (ipStr) { if (ipStr) {
return STRDUP(ipStr); return strdup(ipStr);
} }
} }
return NULL; return NULL;
@ -1685,7 +1676,7 @@ getdns_str2dict(const char *str, getdns_dict **dict)
char value_buf[3072], *value_str = value_buf; char value_buf[3072], *value_str = value_buf;
if (strlen(str) > sizeof(value_str) - 1) if (strlen(str) > sizeof(value_str) - 1)
value_str = STRDUP(str); value_str = strdup(str);
else else
(void)strncpy(value_buf, str, sizeof(value_buf)); (void)strncpy(value_buf, str, sizeof(value_buf));

View File

@ -217,22 +217,14 @@ char* gldns_wire2str_type(uint16_t rrtype)
{ {
char buf[16]; char buf[16];
gldns_wire2str_type_buf(rrtype, buf, sizeof(buf)); gldns_wire2str_type_buf(rrtype, buf, sizeof(buf));
#ifndef USE_WINSOCK
return strdup(buf); return strdup(buf);
#else
return _strdup(buf);
#endif
} }
char* gldns_wire2str_class(uint16_t rrclass) char* gldns_wire2str_class(uint16_t rrclass)
{ {
char buf[16]; char buf[16];
gldns_wire2str_class_buf(rrclass, buf, sizeof(buf)); gldns_wire2str_class_buf(rrclass, buf, sizeof(buf));
#ifndef USE_WINSOCK
return strdup(buf); return strdup(buf);
#else
return _strdup(buf);
#endif
} }
char* gldns_wire2str_dname(uint8_t* dname, size_t dname_len) char* gldns_wire2str_dname(uint8_t* dname, size_t dname_len)
@ -248,11 +240,7 @@ char* gldns_wire2str_rcode(int rcode)
{ {
char buf[16]; char buf[16];
gldns_wire2str_rcode_buf(rcode, buf, sizeof(buf)); gldns_wire2str_rcode_buf(rcode, buf, sizeof(buf));
#ifndef USE_WINSOCK
return strdup(buf); return strdup(buf);
#else
return _strdup(buf);
#endif
} }
int gldns_wire2str_pkt_buf(uint8_t* d, size_t dlen, char* s, size_t slen) int gldns_wire2str_pkt_buf(uint8_t* d, size_t dlen, char* s, size_t slen)