grpc
third_party
cares
cares
src
lib
ares_strdup.c
Go to the documentation of this file.
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
#include "
ares.h
"
21
#include "
ares_private.h
"
22
23
char
*
ares_strdup
(
const
char
*s1)
24
{
25
#ifdef HAVE_STRDUP
26
if
(
ares_malloc
== malloc)
27
return
strdup
(s1);
28
else
29
#endif
30
{
31
size_t
sz;
32
char
* s2;
33
34
if
(s1) {
35
sz = strlen(s1);
36
if
(sz < (
size_t
)-1) {
37
sz++;
38
if
(sz < ((
size_t
)-1) /
sizeof
(
char
)) {
39
s2 =
ares_malloc
(sz *
sizeof
(
char
));
40
if
(s2) {
41
memcpy
(s2, s1, sz *
sizeof
(
char
));
42
return
s2;
43
}
44
}
45
}
46
}
47
return
(
char
*)NULL;
48
}
49
}
ares.h
ares_strdup
char * ares_strdup(const char *s1)
Definition:
ares_strdup.c:23
ares_strdup.h
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
ares_malloc
void *(* ares_malloc)(size_t size)=default_malloc
Definition:
ares_library_init.c:58
ares_setup.h
ares_private.h
strdup
#define strdup(ptr)
Definition:
acountry.c:55
grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:43