1#include <config.h> 2 3#include <ntp_assert.h>
| 1#include <config.h> 2 3#include <ntp_assert.h>
|
4#include "ntp_malloc.h"
| |
5#include <string.h>
| 4#include <string.h>
|
| 5#include "ntp_malloc.h" 6#include "l_stdlib.h"
|
6
| 7
|
7#ifndef HAVE_STRDUP
| 8#define STRDUP_EMPTY_UNIT
|
8
| 9
|
| 10#ifndef HAVE_STRDUP 11# undef STRDUP_EMPTY_UNIT
|
9char *strdup(const char *s);
| 12char *strdup(const char *s);
|
10
| |
11char * 12strdup( 13 const char *s 14 ) 15{ 16 size_t octets; 17 char * cp; 18 19 REQUIRE(s); 20 octets = strlen(s) + 1; 21 if ((cp = malloc(octets)) == NULL) 22 return NULL; 23 memcpy(cp, s, octets); 24 25 return cp; 26}
| 13char * 14strdup( 15 const char *s 16 ) 17{ 18 size_t octets; 19 char * cp; 20 21 REQUIRE(s); 22 octets = strlen(s) + 1; 23 if ((cp = malloc(octets)) == NULL) 24 return NULL; 25 memcpy(cp, s, octets); 26 27 return cp; 28}
|
27#else
| 29#endif 30 31#ifndef HAVE_MEMCHR 32# undef STRDUP_EMPTY_UNIT 33void *memchr(const void *s, int c, size_t n) 34{ 35 const unsigned char *p = s; 36 while (n && *p != c) { 37 --n; 38 ++p; 39 } 40 return n ? (char*)p : NULL; 41} 42#endif 43 44#ifndef HAVE_STRNLEN 45# undef STRDUP_EMPTY_UNIT 46size_t strnlen(const char *s, size_t n) 47{ 48 const char *e = memchr(s, 0, n); 49 return e ? (size_t)(e - s) : n; 50} 51#endif 52 53#ifdef STRDUP_EMPTY_UNIT
|
28int strdup_c_nonempty_compilation_unit; 29#endif
| 54int strdup_c_nonempty_compilation_unit; 55#endif
|