]> gerrit.simantics Code Review - simantics/fmil.git/blob - org.simantics.fmil.core/native/FMILibrary/src/Util/src/FMI/fmi_util.c
Add FMILibrary-2.0.3 to org.simantics.fmil.core\native.
[simantics/fmil.git] / org.simantics.fmil.core / native / FMILibrary / src / Util / src / FMI / fmi_util.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 */\r
15 \r
16 #include <assert.h>\r
17 #include <string.h>\r
18 #include <stdio.h>\r
19 #include <FMI/fmi_util.h>\r
20 \r
21 char* fmi_construct_dll_dir_name(jm_callbacks* callbacks, const char* fmu_unzipped_path) {\r
22         char* dir_path;\r
23         size_t len;\r
24 \r
25         assert( fmu_unzipped_path && callbacks);\r
26 \r
27         len = \r
28                 strlen(fmu_unzipped_path) + strlen(FMI_FILE_SEP)\r
29                 + strlen(FMI_BINARIES) + strlen(FMI_FILE_SEP) \r
30                 + strlen(FMI_PLATFORM) + strlen(FMI_FILE_SEP) + 1;\r
31 \r
32         dir_path = (char*)callbacks->malloc(len);\r
33         if (dir_path == NULL) {\r
34                 jm_log_fatal(callbacks, "FMIUT", "Failed to allocate memory.");\r
35                 return NULL;\r
36         }\r
37 \r
38         sprintf(dir_path, "%s%s%s%s%s%s", fmu_unzipped_path, FMI_FILE_SEP, FMI_BINARIES, FMI_FILE_SEP, FMI_PLATFORM, FMI_FILE_SEP);/*safe */\r
39 \r
40         return dir_path;\r
41 }\r
42 \r
43 char* fmi_construct_dll_file_name(jm_callbacks* callbacks, const char* dll_dir_name, const char* model_identifier) {
44         char* fname;
45         size_t len;
46         assert(callbacks && model_identifier);
47         len = 
48                 strlen(dll_dir_name) +
49                 strlen(model_identifier) 
50                 + strlen(FMI_DLL_EXT) + 1;
51         fname = (char*)callbacks->malloc(len);\r
52         if (fname == NULL) {\r
53                 jm_log_fatal(callbacks, "FMIUT", "Failed to allocate memory.");\r
54                 return NULL;\r
55         }\r
56         sprintf(fname, "%s%s%s", dll_dir_name, model_identifier, FMI_DLL_EXT);/*safe */\r
57 \r
58         return fname;\r
59 }