1 /* 2 ** Copyright 2004, Travis Geiselbrecht. All rights reserved. 3 ** Distributed under the terms of the NewOS License. 4 */ 5 /* 6 * Copyright (c) 2008 Travis Geiselbrecht 7 * 8 * Use of this source code is governed by a MIT-style 9 * license that can be found in the LICENSE file or at 10 * https://opensource.org/licenses/MIT 11 */ 12 #include <stdlib.h> 13 #include <string.h> 14 15 char * strdup(const char * str)16strdup(const char *str) { 17 size_t len; 18 char *copy; 19 20 len = strlen(str) + 1; 21 copy = malloc(len); 22 if (copy == NULL) 23 return NULL; 24 memcpy(copy, str, len); 25 return copy; 26 } 27 28