* gc.h, gc.c (scm_must_strdup, scm_must_strndup): New.
authorMarius Vollmer <mvo@zagadka.de>
Sun, 20 May 2001 19:27:22 +0000 (19:27 +0000)
committerMarius Vollmer <mvo@zagadka.de>
Sun, 20 May 2001 19:27:22 +0000 (19:27 +0000)
libguile/gc.c
libguile/gc.h

index 25c9971..657346d 100644 (file)
@@ -1985,6 +1985,20 @@ scm_must_realloc (void *where,
   scm_memory_error (what);
 }
 
+char *
+scm_must_strndup (const char *str, unsigned long length)
+{
+  char * dst = scm_must_malloc (length + 1, "scm_must_strndup");
+  memcpy (dst, str, length);
+  dst[length] = 0;
+  return dst;
+}
+
+char *
+scm_must_strdup (const char *str)
+{
+  return scm_must_strndup (str, strlen (str));
+}
 
 void
 scm_must_free (void *obj)
index 0fe4d51..331c153 100644 (file)
@@ -370,6 +370,8 @@ extern void * scm_must_malloc (scm_sizet len, const char *what);
 extern void * scm_must_realloc (void *where,
                                scm_sizet olen, scm_sizet len,
                                const char *what);
+extern char *scm_must_strdup (const char *str);
+extern char *scm_must_strndup (const char *str, unsigned long n);
 extern void scm_done_malloc (long size);
 extern void scm_done_free (long size);
 extern void scm_must_free (void *obj);