Commit 802f1e44 authored by Yang Tse's avatar Yang Tse
Browse files

strdup() clone for systems/configurations which lack it

parent a37cc6cb
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -3,14 +3,14 @@ ares_query.c ares__close_sockets.c ares_free_string.c ares_search.c \
ares__get_hostent.c ares_gethostbyaddr.c ares_send.c ares__read_line.c	\
ares_gethostbyname.c ares_strerror.c ares_cancel.c ares_init.c		\
ares_timeout.c ares_destroy.c ares_mkquery.c ares_version.c		\
ares_expand_name.c ares_parse_a_reply.c windows_port.c			\
ares_expand_name.c ares_parse_a_reply.c windows_port.c ares_strdup.c	\
ares_expand_string.c ares_parse_ptr_reply.c ares_parse_aaaa_reply.c	\
ares_getnameinfo.c inet_net_pton.c bitncmp.c inet_ntop.c		\
ares_parse_ns_reply.c ares_llist.c ares__timeval.c

HHEADERS = ares.h ares_private.h setup.h ares_dns.h ares_version.h          \
           nameser.h inet_net_pton.h inet_ntop.h ares_ipv6.h bitncmp.h      \
           setup_once.h ares_llist.h
           setup_once.h ares_llist.h ares_strdup.h

MANPAGES= ares_destroy.3 ares_expand_name.3 ares_expand_string.3 ares_fds.3 \
 ares_free_hostent.3 ares_free_string.3 ares_gethostbyaddr.3		    \
+5 −0
Original line number Diff line number Diff line
@@ -94,6 +94,11 @@
#include "ares_ipv6.h"
#include "ares_llist.h"

#ifndef HAVE_STRDUP
#  include "ares_strdup.h"
#  define strdup(ptr) ares_strdup(ptr)
#endif

struct query;

struct send_request {

ares/ares_strdup.c

0 → 100644
+43 −0
Original line number Diff line number Diff line

/* $Id$ */

/* Copyright 1998 by the Massachusetts Institute of Technology.
 *
 * Permission to use, copy, modify, and distribute this
 * software and its documentation for any purpose and without
 * fee is hereby granted, provided that the above copyright
 * notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting
 * documentation, and that the name of M.I.T. not be used in
 * advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission.
 * M.I.T. makes no representations about the suitability of
 * this software for any purpose.  It is provided "as is"
 * without express or implied warranty.
 */

#include "setup.h"
#include "ares_strdup.h"

#ifndef HAVE_STRDUP
char *ares_strdup(const char *s1)
{
  size_t sz;
  char * s2;

  if(s1) {
    sz = strlen(s1);
    if(sz < (size_t)-1) {
      sz++;
      if(sz < ((size_t)-1) / sizeof(char)) {
        s2 = malloc(sz * sizeof(char));
        if(s2) {
          memcpy(s2, s1, sz * sizeof(char));
          return s2;
        }
      }
    }
  }
  return (char *)NULL;
}
#endif

ares/ares_strdup.h

0 → 100644
+27 −0
Original line number Diff line number Diff line
#ifndef HEADER_CARES_STRDUP_H
#define HEADER_CARES_STRDUP_H

/* $Id$ */

/* Copyright 1998 by the Massachusetts Institute of Technology.
 *
 * Permission to use, copy, modify, and distribute this
 * software and its documentation for any purpose and without
 * fee is hereby granted, provided that the above copyright
 * notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting
 * documentation, and that the name of M.I.T. not be used in
 * advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission.
 * M.I.T. makes no representations about the suitability of
 * this software for any purpose.  It is provided "as is"
 * without express or implied warranty.
 */

#include "setup.h"

#ifndef HAVE_STRDUP
extern char *ares_strdup(const char *s1);
#endif

#endif /* HEADER_CARES_STRDUP_H */
+3 −0
Original line number Diff line number Diff line
@@ -79,6 +79,9 @@
/* Define if you have the ioctlsocket function.  */
#define HAVE_IOCTLSOCKET 1

/* Define if you have the strdup function. */
#define HAVE_STRDUP 1

/* Define if you have the recv function. */
#define HAVE_RECV 1

Loading