Thomas Heijligen | 9204355 | 2019-01-29 12:48:01 +0100 | [diff] [blame] | 1 | #include <string.h> |
| 2 | #include <stddef.h> |
| 3 | #include <stdlib.h> |
| 4 | |
| 5 | char *strdup(const char *s) |
| 6 | { |
| 7 | size_t sz = strlen(s) + 1; |
| 8 | char *d = malloc(sz); |
Thejaswani Putta | 6f5225c | 2019-04-11 18:36:08 -0700 | [diff] [blame^] | 9 | if (d) |
| 10 | memcpy(d, s, sz); |
Thomas Heijligen | 9204355 | 2019-01-29 12:48:01 +0100 | [diff] [blame] | 11 | return d; |
| 12 | } |
| 13 | |
| 14 | char *strconcat(const char *s1, const char *s2) |
| 15 | { |
| 16 | size_t sz_1 = strlen(s1); |
| 17 | size_t sz_2 = strlen(s2); |
| 18 | char *d = malloc(sz_1 + sz_2 + 1); |
Thejaswani Putta | 6f5225c | 2019-04-11 18:36:08 -0700 | [diff] [blame^] | 19 | if (d) { |
| 20 | memcpy(d, s1, sz_1); |
| 21 | memcpy(d + sz_1, s2, sz_2 + 1); |
| 22 | } |
Thomas Heijligen | 9204355 | 2019-01-29 12:48:01 +0100 | [diff] [blame] | 23 | return d; |
| 24 | } |