]> www.ginac.de Git - cln.git/blob - src/base/string/cl_st_make2.cc
dfcdea02f1944514d3bc1719d4971d0040b3bc12
[cln.git] / src / base / string / cl_st_make2.cc
1 // cl_make_heap_string().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cl_string.h"
8
9
10 // Implementation.
11
12 #include "cl_malloc.h"
13 #include "cl_offsetof.h"
14
15 cl_heap_string* cl_make_heap_string (const char * ptr, unsigned long len)
16 {
17         var cl_heap_string* str = (cl_heap_string*) cl_malloc_hook(offsetofa(cl_heap_string,data)+sizeof(char)*(len+1));
18         str->refcount = 1;
19         str->type = &cl_class_string;
20         str->length = len;
21         {
22                 var const char* ptr1 = ptr;
23                 var char* ptr2 = &str->data[0];
24                 var uintL count;
25                 for (count = len; count > 0; count--)
26                         *ptr2++ = *ptr1++;
27                 *ptr2++ = '\0';
28         }
29         return str;
30 }