/src/ntp-dev/libntp/strdup.c
Line | Count | Source |
1 | | #include <config.h> |
2 | | |
3 | | #include <ctype.h> |
4 | | #include <string.h> |
5 | | #include "ntp_assert.h" |
6 | | #include "ntp_malloc.h" |
7 | | #include "l_stdlib.h" |
8 | | |
9 | | #ifndef HAVE_STRDUP |
10 | | # undef STRDUP_EMPTY_UNIT |
11 | | char *strdup(const char *s); |
12 | | char * |
13 | | strdup( |
14 | | const char *s |
15 | | ) |
16 | | { |
17 | | size_t octets; |
18 | | char * cp; |
19 | | |
20 | | REQUIRE(s); |
21 | | octets = strlen(s) + 1; |
22 | | if ((cp = malloc(octets)) == NULL) |
23 | | return NULL; |
24 | | memcpy(cp, s, octets); |
25 | | |
26 | | return cp; |
27 | | } |
28 | | #endif |
29 | | |
30 | | #ifndef HAVE__STRUPR |
31 | | char * |
32 | | _strupr(char *s) |
33 | 0 | { |
34 | 0 | char *pch; |
35 | |
|
36 | 0 | for (pch = s; '\0' != *pch; pch++) { |
37 | | *pch = toupper((u_char)*pch); |
38 | 0 | } |
39 | 0 | return s; |
40 | 0 | } |
41 | | #endif |
42 | | |
43 | | #ifndef HAVE_STRNLEN |
44 | | # undef STRDUP_EMPTY_UNIT |
45 | | size_t strnlen(const char *s, size_t n) |
46 | | { |
47 | | const char *e = memchr(s, 0, n); |
48 | | return e ? (size_t)(e - s) : n; |
49 | | } |
50 | | #endif |
51 | | |
52 | | NONEMPTY_TRANSLATION_UNIT |