2 Copyright (C) 2012 Modelon AB
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the BSD style license.
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.
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>.
16 #ifndef JM_PORTABILITY_H_
\r
17 #define JM_PORTABILITY_H_
\r
18 #include <fmilib_config.h>
\r
19 #include "jm_callbacks.h"
\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
26 #define DLL_HANDLE void*
\r
27 #include <dlfcn.h> /* Standard POSIX/UNIX API */
\r
30 #include "jm_types.h"
\r
31 /** \file jm_portability.h
\r
32 Handling platform specific defines and functions.
\r
35 \addtogroup jm_utils
\r
37 \addtogroup jm_portability
\r
40 /** \addtogroup jm_portability Handling platform specific defines and functions
\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
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
48 /** \brief A function pointer as returned when DLL symbol is loaded.*/
50 #define jm_dll_function_ptr FARPROC
\r
52 typedef void* jm_dll_function_ptr;
\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
58 /** \brief Return error associated with Dll handling */
\r
59 char* jm_portability_get_last_dll_error (void);
\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
64 /** \brief Set current working directory*/
\r
65 jm_status_enu_t jm_portability_set_current_working_directory(const char* cwd);
\r
67 /** \brief Get system-wide temporary directory */
\r
68 const char* jm_get_system_temp_dir();
\r
71 \brief Create a uniquely named temporary directory.
72 \param cb - callbacks for memory allocation and logging. Default callbacks
73 are used if this parameter is NULL.
74 \param tmplt Directory name template ending with XXXXXX. The template is
76 \return A pointer to the modified template. The function returns NULL if
77 the template does not end with XXXXXX, or if the directory could
80 char *jm_mkdtemp(jm_callbacks *cb, char *tmplt);
84 \brief Get absolute path to an existing directory
\r
85 \param cb - callbacks for memory allocation and logging. Default callbacks are used if this parameter is NULL.
\r
86 \param dir - path to a directory (relative or absolute).
\r
87 \param outPath - buffer for storing the directory
\r
88 \param len - of the buffer (if size is larger than FILENAME_MAX + 1 then the path will always fit in)
\r
89 \return Pointer to outPath on success, 0 - on error in which case a message is send to the logger.
\r
91 char* jm_get_dir_abspath(jm_callbacks* cb, const char* dir, char* outPath, size_t len);
\r
94 \brief Create a unique temporary directory
\r
95 \param cb - callbacks for memory allocation and logging. Default callbacks are used if this parameter is NULL.
\r
96 \param systemTempDir - directory where the temp dir should be located both absolute and relative path are accepted.
\r
97 System-wide directory is used if this parameter is NULL.
\r
98 \param tempPrefix - File name template prefix used when creating temporaty directories. "jm" is used if this is NULL.
\r
99 \return A pointer to the temporary directory name (absolute path, no terminating '/'). Caller is responsible for freeing the memory.
\r
100 The function returns NULL if there were errors in which case a message is send to the logger.
\r
102 char* jm_mk_temp_dir(jm_callbacks* cb, const char* systemTempDir, const char* tempPrefix);
\r
105 \brief Create a file:// URL from absolute path
\r
106 \param cb - callbacks for memory allocation and logging. Default callbacks are used if this parameter is NULL.
\r
107 \param absPath - absolute path to be converted into the URL
\r
108 \return A pointer to the URL. Caller is responsible for freeing the memory.
\r
109 The function returns NULL if there were errors in which case a message is send to the logger.
\r
111 char* jm_create_URL_from_abs_path(jm_callbacks* cb, const char* absPath);
\r
114 \brief Make a directory.
\r
116 jm_status_enu_t jm_mkdir(jm_callbacks* cb, const char* dir);
\r
119 \brief Remove directory and all it contents.
\r
121 jm_status_enu_t jm_rmdir(jm_callbacks* cb, const char* dir);
\r
124 \brief C89 compatible implementation of C99 vsnprintf.
\r
127 int jm_vsnprintf(char * str, size_t size, const char * fmt, va_list al);
130 \brief C89 compatible implementation of C99 snprintf.
\r
133 int jm_snprintf(char * str, size_t size, const char * fmt, ...);
136 #define JM_VA_COPY va_copy
137 #elif defined(HAVE___VA_COPY)
\r
138 #define JM_VA_COPY __va_copy
140 #define JM_VA_COPY(dest,src) dest=src
144 #endif /* End of header file JM_PORTABILITY_H_ */
\r