]> gerrit.simantics Code Review - simantics/fmil.git/blob - org.simantics.fmil.core/native/FMILibrary/src/Util/src/JM/jm_named_ptr.c
Switch to full JavaSE-11+ compatibility
[simantics/fmil.git] / org.simantics.fmil.core / native / FMILibrary / src / Util / src / JM / jm_named_ptr.c
1 /*
2     Copyright (C) 2012 Modelon AB
3
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the BSD style license.
6
7      This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10     FMILIB_License.txt file for more details.
11
12     You should have received a copy of the FMILIB_License.txt file
13     along with this program. If not, contact Modelon AB <http://www.modelon.com>.
14 */
15
16 #include <string.h>
17 #include "JM/jm_callbacks.h"
18 #include "JM/jm_named_ptr.h"
19
20 jm_named_ptr jm_named_alloc(const char* name, size_t size, size_t nameoffset, jm_callbacks* c) {
21     jm_named_ptr out;
22     size_t namelen = strlen(name);
23     size_t sizefull = size + namelen;
24     out.ptr = c->malloc(sizefull);
25         out.name = 0;
26     if(out.ptr) {
27         char* outname;
28         outname = out.ptr;
29         outname += nameoffset;
30         if(namelen)
31             memcpy(outname, name, namelen);
32         outname[namelen] = 0;
33         out.name = outname;
34     }
35     return out;
36 }
37
38 jm_named_ptr jm_named_alloc_v(jm_vector(char)* name, size_t size, size_t nameoffset, jm_callbacks* c) {
39     jm_named_ptr out;
40     size_t namelen = jm_vector_get_size(char)(name);
41     size_t sizefull = size + namelen;
42     out.ptr = c->malloc(sizefull);
43         out.name = 0;
44     if(out.ptr) {
45         char * outname = out.ptr;
46         outname += nameoffset;
47         if(namelen)
48             memcpy(outname, jm_vector_get_itemp(char)(name,0), namelen);
49         outname[namelen] = 0;
50         out.name = outname;
51     }
52     return out;
53 }
54
55 #define JM_TEMPLATE_INSTANCE_TYPE jm_named_ptr
56 #include "JM/jm_vector_template.h"