Added kernel_args_strdup() function as a strdup() replacement.

Added a ToDo comment.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7500 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-05-10 16:47:06 +00:00
parent f6de96a7e6
commit 007c81ec98
+27
View File
@@ -9,6 +9,12 @@
#include <boot/stage2.h>
#include <boot/platform.h>
#include <string.h>
// ToDo: the kernel_args heap chunks need to be remembered in the kernel_args
// structure, so that unneeded memory can be freed in the kernel again.
static const size_t kChunkSize = 16384;
@@ -60,6 +66,27 @@ kernel_args_malloc(size_t size)
}
/** Convenience function that copies strdup() functions for the
* kernel args heap.
*/
extern "C" char *
kernel_args_strdup(const char *string)
{
if (string == NULL || string[0] == '\0')
return NULL;
size_t length = strlen(string) + 1;
char *target = (char *)kernel_args_malloc(length);
if (target == NULL)
return NULL;
memcpy(target, string, length);
return target;
}
/** This function frees a block allocated via kernel_args_malloc().
* It's very simple; it can only free the last allocation. It's
* enough for its current usage in the boot loader, though.