]> gerrit.simantics Code Review - simantics/fmil.git/blob - org.simantics.fmil.core/native/FMUSimulator/include/FMIL/Util/JM/jm_portability.h
Renamed org.simantics.fmil to org.simantics.fmil.core to prevent having bundles and...
[simantics/fmil.git] / org.simantics.fmil.core / native / FMUSimulator / include / FMIL / Util / JM / jm_portability.h
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 #ifndef JM_PORTABILITY_H_\r
17 #define JM_PORTABILITY_H_\r
18 #include <fmilib_config.h>\r
19 #include "jm_callbacks.h"\r
20 \r
21 /* Include platform dependent headers */\r
22 #if defined(_MSC_VER) || defined(WIN32) || defined(__MINGW32__)\r
23 #include <windows.h> /* Microsoft Windows API */\r
24 #define DLL_HANDLE HANDLE\r
25 #else\r
26 #define DLL_HANDLE void*\r
27 #include <dlfcn.h>  /* Standard POSIX/UNIX API */\r
28 #endif\r
29 \r
30 #include "jm_types.h"\r
31 /** \file jm_portability.h\r
32         Handling platform specific defines and functions.\r
33 */\r
34 /**\r
35         \addtogroup jm_utils\r
36         @{\r
37                 \addtogroup jm_portability\r
38         @}\r
39 */\r
40 /** \addtogroup jm_portability Handling platform specific defines and functions\r
41 @{*/\r
42 /** \brief Load a dll/so library into the process and return a handle. */\r
43 DLL_HANDLE              jm_portability_load_dll_handle          (const char* dll_file_path);\r
44 \r
45 /** \brief Unload a Dll and release the handle*/\r
46 jm_status_enu_t jm_portability_free_dll_handle          (DLL_HANDLE dll_handle);\r
47 \r
48 /** \brief A function pointer as returned when DLL symbol is loaded.*/
49 #ifdef WIN32
50 #define jm_dll_function_ptr FARPROC
51 #else
52 typedef void* jm_dll_function_ptr; 
53 #endif
54 \r
55 /** \brief Find a function in the Dll and return a function pointer */\r
56 jm_status_enu_t jm_portability_load_dll_function        (DLL_HANDLE dll_handle, char* dll_function_name, jm_dll_function_ptr* dll_function_ptrptr);\r
57 \r
58 /** \brief Return error associated with Dll handling */\r
59 char* jm_portability_get_last_dll_error (void);\r
60 \r
61 /** \brief Get current working directory name */\r
62 jm_status_enu_t jm_portability_get_current_working_directory(char* buffer, size_t len);\r
63 \r
64 /** \brief Set current working directory*/\r
65 jm_status_enu_t jm_portability_set_current_working_directory(const char* cwd);\r
66 \r
67 /** \brief Get system-wide temporary directory */\r
68 const char* jm_get_system_temp_dir();\r
69 \r
70 /** \r
71         \brief Create a unique file name \r
72         \param tmplt File name template ending with XXXXXX.\r
73         \return A pointer to the modified template. The function returns NULL if \r
74         template is badly formed or no more unique names can be created from the given template.\r
75 */\r
76 char* jm_mktemp(char* tmplt);\r
77 \r
78 \r
79 /** \r
80         \brief Get absolute path to an existing directory\r
81         \param cb - callbacks for memory allocation and logging. Default callbacks are used if this parameter is NULL.\r
82         \param dir - path to a directory (relative or absolute).\r
83         \param outPath - buffer for storing the directory\r
84         \param len - of the buffer (if size is larger than FILENAME_MAX + 1 then the path will always fit in)\r
85         \return Pointer to outPath on success, 0 - on error in which case a message is send to the logger.      \r
86 */\r
87 char* jm_get_dir_abspath(jm_callbacks* cb, const char* dir, char* outPath, size_t len);\r
88 \r
89 /** \r
90         \brief Create a unique temporary directory\r
91         \param cb - callbacks for memory allocation and logging. Default callbacks are used if this parameter is NULL.\r
92         \param systemTempDir - directory where the temp dir should be located both absolute and relative path are accepted.\r
93                                 System-wide directory is used if this parameter is NULL.\r
94         \param tempPrefix - File name template prefix used when creating temporaty directories. "jm" is used if this is NULL.\r
95         \return A pointer to the temporary directory name (absolute path, no terminating '/'). Caller is responsible for freeing the memory.\r
96                 The function returns NULL if there were errors in which case a message is send to the logger.   \r
97 */\r
98 char* jm_mk_temp_dir(jm_callbacks* cb, const char* systemTempDir, const char* tempPrefix);\r
99 \r
100 /** \r
101         \brief Create a file:// URL from absolute path\r
102         \param cb - callbacks for memory allocation and logging. Default callbacks are used if this parameter is NULL.\r
103         \param absPath - absolute path to be converted into the URL\r
104         \return A pointer to the URL. Caller is responsible for freeing the memory.\r
105                 The function returns NULL if there were errors in which case a message is send to the logger.   \r
106 */\r
107 char* jm_create_URL_from_abs_path(jm_callbacks* cb, const char* absPath);\r
108 \r
109 /**\r
110         \brief Make a directory.\r
111 */\r
112 jm_status_enu_t jm_mkdir(jm_callbacks* cb, const char* dir);\r
113 \r
114 /**\r
115 \brief Remove directory and all it contents.\r
116 */\r
117 jm_status_enu_t jm_rmdir(jm_callbacks* cb, const char* dir);\r
118 \r
119 /**\r
120 \brief C89 compatible implementation of C99 vsnprintf. \r
121 */\r
122 FMILIB_EXPORT
123 int jm_vsnprintf(char * str, size_t size, const char * fmt, va_list al);
124
125 /**\r
126 \brief C89 compatible implementation of C99 snprintf. \r
127 */\r
128 FMILIB_EXPORT\r
129 int jm_snprintf(char * str, size_t size, const char * fmt, ...);
130 \r
131 #ifdef HAVE_VA_COPY
132 #define JM_VA_COPY va_copy
133 #elif defined(HAVE___VA_COPY)\r
134 #define JM_VA_COPY __va_copy
135 #elif defined(WIN32)
136 #define JM_VA_COPY(dest,src) dest=src
137 #endif
138 \r
139 /*@}*/\r
140 #endif /* End of header file JM_PORTABILITY_H_ */\r