]> gerrit.simantics Code Review - simantics/fmil.git/blobdiff - org.simantics.fmil.core/native/FMILibrary/src/Util/include/JM/jm_portability.h
Add FMILibrary-2.0.3 to org.simantics.fmil.core\native.
[simantics/fmil.git] / org.simantics.fmil.core / native / FMILibrary / src / Util / include / JM / jm_portability.h
diff --git a/org.simantics.fmil.core/native/FMILibrary/src/Util/include/JM/jm_portability.h b/org.simantics.fmil.core/native/FMILibrary/src/Util/include/JM/jm_portability.h
new file mode 100644 (file)
index 0000000..82e472a
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+    Copyright (C) 2012 Modelon AB
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the BSD style license.
+
+     This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    FMILIB_License.txt file for more details.
+
+    You should have received a copy of the FMILIB_License.txt file
+    along with this program. If not, contact Modelon AB <http://www.modelon.com>.
+*/\r
+\r
+#ifndef JM_PORTABILITY_H_\r
+#define JM_PORTABILITY_H_\r
+#include <fmilib_config.h>\r
+#include "jm_callbacks.h"\r
+\r
+/* Include platform dependent headers */\r
+#if defined(_MSC_VER) || defined(WIN32) || defined(__MINGW32__)\r
+#include <windows.h> /* Microsoft Windows API */\r
+#define DLL_HANDLE HANDLE\r
+#else\r
+#define DLL_HANDLE void*\r
+#include <dlfcn.h>  /* Standard POSIX/UNIX API */\r
+#endif\r
+\r
+#include "jm_types.h"\r
+/** \file jm_portability.h\r
+       Handling platform specific defines and functions.\r
+*/\r
+/**\r
+       \addtogroup jm_utils\r
+       @{\r
+               \addtogroup jm_portability\r
+       @}\r
+*/\r
+/** \addtogroup jm_portability Handling platform specific defines and functions\r
+@{*/\r
+/** \brief Load a dll/so library into the process and return a handle. */\r
+DLL_HANDLE             jm_portability_load_dll_handle          (const char* dll_file_path);\r
+\r
+/** \brief Unload a Dll and release the handle*/\r
+jm_status_enu_t jm_portability_free_dll_handle         (DLL_HANDLE dll_handle);\r
+\r
+/** \brief A function pointer as returned when DLL symbol is loaded.*/
+#ifdef WIN32\r
+#define jm_dll_function_ptr FARPROC\r
+#else\r
+typedef void* jm_dll_function_ptr; \r
+#endif\r
+\r
+/** \brief Find a function in the Dll and return a function pointer */\r
+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
+\r
+/** \brief Return error associated with Dll handling */\r
+char* jm_portability_get_last_dll_error        (void);\r
+\r
+/** \brief Get current working directory name */\r
+jm_status_enu_t jm_portability_get_current_working_directory(char* buffer, size_t len);\r
+\r
+/** \brief Set current working directory*/\r
+jm_status_enu_t jm_portability_set_current_working_directory(const char* cwd);\r
+\r
+/** \brief Get system-wide temporary directory */\r
+const char* jm_get_system_temp_dir();\r
+
+/**
+    \brief Create a uniquely named temporary directory.
+    \param cb - callbacks for memory allocation and logging. Default callbacks
+            are used if this parameter is NULL.
+    \param tmplt Directory name template ending with XXXXXX. The template is
+            modified by the call.
+    \return A pointer to the modified template. The function returns NULL if
+            the template does not end with XXXXXX, or if the directory could
+            not be created.
+*/
+char *jm_mkdtemp(jm_callbacks *cb, char *tmplt);
+
+\r
+/** \r
+       \brief Get absolute path to an existing directory\r
+       \param cb - callbacks for memory allocation and logging. Default callbacks are used if this parameter is NULL.\r
+       \param dir - path to a directory (relative or absolute).\r
+       \param outPath - buffer for storing the directory\r
+       \param len - of the buffer (if size is larger than FILENAME_MAX + 1 then the path will always fit in)\r
+       \return Pointer to outPath on success, 0 - on error in which case a message is send to the logger.      \r
+*/\r
+char* jm_get_dir_abspath(jm_callbacks* cb, const char* dir, char* outPath, size_t len);\r
+\r
+/** \r
+       \brief Create a unique temporary directory\r
+       \param cb - callbacks for memory allocation and logging. Default callbacks are used if this parameter is NULL.\r
+       \param systemTempDir - directory where the temp dir should be located both absolute and relative path are accepted.\r
+                               System-wide directory is used if this parameter is NULL.\r
+       \param tempPrefix - File name template prefix used when creating temporaty directories. "jm" is used if this is NULL.\r
+       \return A pointer to the temporary directory name (absolute path, no terminating '/'). Caller is responsible for freeing the memory.\r
+               The function returns NULL if there were errors in which case a message is send to the logger.   \r
+*/\r
+char* jm_mk_temp_dir(jm_callbacks* cb, const char* systemTempDir, const char* tempPrefix);\r
+\r
+/** \r
+       \brief Create a file:// URL from absolute path\r
+       \param cb - callbacks for memory allocation and logging. Default callbacks are used if this parameter is NULL.\r
+       \param absPath - absolute path to be converted into the URL\r
+       \return A pointer to the URL. Caller is responsible for freeing the memory.\r
+               The function returns NULL if there were errors in which case a message is send to the logger.   \r
+*/\r
+char* jm_create_URL_from_abs_path(jm_callbacks* cb, const char* absPath);\r
+\r
+/**\r
+       \brief Make a directory.\r
+*/\r
+jm_status_enu_t jm_mkdir(jm_callbacks* cb, const char* dir);\r
+\r
+/**\r
+\brief Remove directory and all it contents.\r
+*/\r
+jm_status_enu_t jm_rmdir(jm_callbacks* cb, const char* dir);\r
+\r
+/**\r
+\brief C89 compatible implementation of C99 vsnprintf. \r
+*/\r
+FMILIB_EXPORT
+int jm_vsnprintf(char * str, size_t size, const char * fmt, va_list al);
+
+/**\r
+\brief C89 compatible implementation of C99 snprintf. \r
+*/\r
+FMILIB_EXPORT\r
+int jm_snprintf(char * str, size_t size, const char * fmt, ...);
+\r
+#ifdef HAVE_VA_COPY
+#define JM_VA_COPY va_copy
+#elif defined(HAVE___VA_COPY)\r
+#define JM_VA_COPY __va_copy
+#elif defined(WIN32)
+#define JM_VA_COPY(dest,src) dest=src
+#endif
+\r
+/*@}*/\r
+#endif /* End of header file JM_PORTABILITY_H_ */\r