strdup.c (ntp-4.2.8p14) | : | strdup.c (ntp-4.2.8p15) | ||
---|---|---|---|---|
#include <config.h> | #include <config.h> | |||
#include <ntp_assert.h> | #include <ntp_assert.h> | |||
#include "ntp_malloc.h" | ||||
#include <string.h> | #include <string.h> | |||
#include "ntp_malloc.h" | ||||
#include "l_stdlib.h" | ||||
#ifndef HAVE_STRDUP | #define STRDUP_EMPTY_UNIT | |||
#ifndef HAVE_STRDUP | ||||
# undef STRDUP_EMPTY_UNIT | ||||
char *strdup(const char *s); | char *strdup(const char *s); | |||
char * | char * | |||
strdup( | strdup( | |||
const char *s | const char *s | |||
) | ) | |||
{ | { | |||
size_t octets; | size_t octets; | |||
char * cp; | char * cp; | |||
REQUIRE(s); | REQUIRE(s); | |||
octets = strlen(s) + 1; | octets = strlen(s) + 1; | |||
if ((cp = malloc(octets)) == NULL) | if ((cp = malloc(octets)) == NULL) | |||
return NULL; | return NULL; | |||
memcpy(cp, s, octets); | memcpy(cp, s, octets); | |||
return cp; | return cp; | |||
} | } | |||
#else | #endif | |||
#ifndef HAVE_MEMCHR | ||||
# undef STRDUP_EMPTY_UNIT | ||||
void *memchr(const void *s, int c, size_t n) | ||||
{ | ||||
const unsigned char *p = s; | ||||
while (n && *p != c) { | ||||
--n; | ||||
++p; | ||||
} | ||||
return n ? (char*)p : NULL; | ||||
} | ||||
#endif | ||||
#ifndef HAVE_STRNLEN | ||||
# undef STRDUP_EMPTY_UNIT | ||||
size_t strnlen(const char *s, size_t n) | ||||
{ | ||||
const char *e = memchr(s, 0, n); | ||||
return e ? (size_t)(e - s) : n; | ||||
} | ||||
#endif | ||||
#ifdef STRDUP_EMPTY_UNIT | ||||
int strdup_c_nonempty_compilation_unit; | int strdup_c_nonempty_compilation_unit; | |||
#endif | #endif | |||
End of changes. 6 change blocks. | ||||
4 lines changed or deleted | 30 lines changed or added |