tizen 2.4 release
[external/c-ares.git] / ares_strdup.c
1
2
3 /* Copyright 1998 by the Massachusetts Institute of Technology.
4  *
5  * Permission to use, copy, modify, and distribute this
6  * software and its documentation for any purpose and without
7  * fee is hereby granted, provided that the above copyright
8  * notice appear in all copies and that both that copyright
9  * notice and this permission notice appear in supporting
10  * documentation, and that the name of M.I.T. not be used in
11  * advertising or publicity pertaining to distribution of the
12  * software without specific, written prior permission.
13  * M.I.T. makes no representations about the suitability of
14  * this software for any purpose.  It is provided "as is"
15  * without express or implied warranty.
16  */
17
18 #include "ares_setup.h"
19 #include "ares_strdup.h"
20
21 #ifndef HAVE_STRDUP
22 char *ares_strdup(const char *s1)
23 {
24   size_t sz;
25   char * s2;
26
27   if(s1) {
28     sz = strlen(s1);
29     if(sz < (size_t)-1) {
30       sz++;
31       if(sz < ((size_t)-1) / sizeof(char)) {
32         s2 = malloc(sz * sizeof(char));
33         if(s2) {
34           memcpy(s2, s1, sz * sizeof(char));
35           return s2;
36         }
37       }
38     }
39   }
40   return (char *)NULL;
41 }
42 #endif