vfs: check userland buffers before reading them.
[haiku.git] / src / system / libroot / posix / string / strdup.cpp
bloba4306f089961252097e521341a41e5f1abd36773
1 /*
2 * Copyright 2003-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <string.h>
8 #include <stdlib.h>
11 char*
12 strdup(const char *string)
14 char* copied;
15 size_t length;
17 // unlike the standard strdup() function, the BeOS implementation
18 // handles NULL strings gracefully
19 if (string == NULL)
20 return NULL;
22 length = strlen(string) + 1;
24 if ((copied = (char *)malloc(length)) == NULL)
25 return NULL;
27 memcpy(copied, string, length);
28 return copied;