|
Packit |
514978 |
|
|
Packit |
514978 |
|
|
Packit |
514978 |
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
|
Packit |
514978 |
*
|
|
Packit |
514978 |
* Permission to use, copy, modify, and distribute this
|
|
Packit |
514978 |
* software and its documentation for any purpose and without
|
|
Packit |
514978 |
* fee is hereby granted, provided that the above copyright
|
|
Packit |
514978 |
* notice appear in all copies and that both that copyright
|
|
Packit |
514978 |
* notice and this permission notice appear in supporting
|
|
Packit |
514978 |
* documentation, and that the name of M.I.T. not be used in
|
|
Packit |
514978 |
* advertising or publicity pertaining to distribution of the
|
|
Packit |
514978 |
* software without specific, written prior permission.
|
|
Packit |
514978 |
* M.I.T. makes no representations about the suitability of
|
|
Packit |
514978 |
* this software for any purpose. It is provided "as is"
|
|
Packit |
514978 |
* without express or implied warranty.
|
|
Packit |
514978 |
*/
|
|
Packit |
514978 |
|
|
Packit |
514978 |
#include "ares_setup.h"
|
|
Packit |
514978 |
#include "ares_strdup.h"
|
|
Packit |
514978 |
#include "ares.h"
|
|
Packit |
514978 |
#include "ares_private.h"
|
|
Packit |
514978 |
|
|
Packit |
514978 |
char *ares_strdup(const char *s1)
|
|
Packit |
514978 |
{
|
|
Packit |
514978 |
#ifdef HAVE_STRDUP
|
|
Packit |
514978 |
if (ares_malloc == malloc)
|
|
Packit |
514978 |
return strdup(s1);
|
|
Packit |
514978 |
else
|
|
Packit |
514978 |
#endif
|
|
Packit |
514978 |
{
|
|
Packit |
514978 |
size_t sz;
|
|
Packit |
514978 |
char * s2;
|
|
Packit |
514978 |
|
|
Packit |
514978 |
if(s1) {
|
|
Packit |
514978 |
sz = strlen(s1);
|
|
Packit |
514978 |
if(sz < (size_t)-1) {
|
|
Packit |
514978 |
sz++;
|
|
Packit |
514978 |
if(sz < ((size_t)-1) / sizeof(char)) {
|
|
Packit |
514978 |
s2 = ares_malloc(sz * sizeof(char));
|
|
Packit |
514978 |
if(s2) {
|
|
Packit |
514978 |
memcpy(s2, s1, sz * sizeof(char));
|
|
Packit |
514978 |
return s2;
|
|
Packit |
514978 |
}
|
|
Packit |
514978 |
}
|
|
Packit |
514978 |
}
|
|
Packit |
514978 |
}
|
|
Packit |
514978 |
return (char *)NULL;
|
|
Packit |
514978 |
}
|
|
Packit |
514978 |
}
|