]>
git.ipfire.org Git - thirdparty/squid.git/blob - compat/xstring.cc
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
10 #include "compat/xalloc.h"
11 #include "compat/xstring.h"
16 xstrdup(const char *s
)
20 (*failure_notify
) ("xstrdup: tried to dup a NULL pointer!\n");
23 perror("xstrdup: tried to dup a NULL pointer!");
28 /* copy string, including terminating character */
29 size_t sz
= strlen(s
) + 1;
30 char *p
= static_cast<char *>(xmalloc(sz
));
37 xstrncpy(char *dst
, const char *src
, size_t n
)
45 while (--n
!= 0 && *src
!= '\0') {
56 xstrndup(const char *s
, size_t n
)
61 (*failure_notify
) ("xstrndup: tried to dup a NULL pointer!\n");
63 perror("xstrndup: tried to dup a NULL pointer!");
68 size_t sz
= strlen(s
) + 1;
69 // size_t is unsigned, as mandated by c99 and c++ standards.
73 char *p
= xstrncpy(static_cast<char *>(xmalloc(sz
)), s
, sz
);