summaryrefslogtreecommitdiffstats
path: root/common/mem.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/mem.c')
-rw-r--r--common/mem.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/common/mem.c b/common/mem.c
index ad0cccf6..56b37157 100644
--- a/common/mem.c
+++ b/common/mem.c
@@ -32,11 +32,29 @@ char *spice_strdup(const char *str)
{
char *copy;
+ if (str == NULL) {
+ return NULL;
+ }
+
copy = (char *)spice_malloc(strlen(str) + 1);
strcpy(copy, str);
return copy;
}
+char *spice_strndup(const char *str, size_t n_bytes)
+{
+ char *copy;
+
+ if (str == NULL) {
+ return NULL;
+ }
+
+ copy = (char *)spice_malloc(n_bytes + 1);
+ strncpy(copy, str, n_bytes);
+ copy[n_bytes] = 0;
+ return copy;
+}
+
void *spice_memdup(const void *mem, size_t n_bytes)
{
void *copy;