#include <algorithm>
#include <string>
#include <io.h>
+#include <math.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
int tz_dsttime; /* type of dst correction */
};
-PBD_API int PBD_APICALLTYPE
+LIBPBD_API int PBD_APICALLTYPE
gettimeofday(struct timeval *__restrict tv, __timezone_ptr_t tz) // Does this need to be exported ?
{
FILETIME ft;
#ifndef PTHREAD_H // Defined by PTW32 (Linux and other versions define _PTHREAD_H)
#error "An incompatible version of 'pthread.h' is #included. Use only the Windows (ptw32) version!"
#else
-bool operator> (const pthread_t& lhs, const pthread_t& rhs)
+LIBPBD_API bool operator> (const pthread_t& lhs, const pthread_t& rhs)
{
return (std::greater<void*>()(lhs.p, rhs.p));
}
-bool operator< (const pthread_t& lhs, const pthread_t& rhs)
+LIBPBD_API bool operator< (const pthread_t& lhs, const pthread_t& rhs)
{
return (std::less<void*>()(lhs.p, rhs.p));
}
-bool operator!= (const pthread_t& lhs, const pthread_t& rhs)
+LIBPBD_API bool operator!= (const pthread_t& lhs, const pthread_t& rhs)
{
return (std::not_equal_to<void*>()(lhs.p, rhs.p));
}
-bool operator== (const pthread_t& lhs, const pthread_t& rhs)
+LIBPBD_API bool operator== (const pthread_t& lhs, const pthread_t& rhs)
{
return (!(lhs != rhs));
}
// On Success: The number of bytes read from the file
// On Failure: -1
//
-PBD_API ssize_t PBD_APICALLTYPE
+LIBPBD_API ssize_t PBD_APICALLTYPE
pread(int handle, void *buf, size_t nbytes, off_t offset)
{
int old_errno;
// On Success: The number of bytes written to the file
// On Failure: -1
//
-PBD_API ssize_t PBD_APICALLTYPE
+LIBPBD_API ssize_t PBD_APICALLTYPE
pwrite(int handle, const void *buf, size_t nbytes, off_t offset)
{
int old_errno;
return (ret);
}
+#if defined(_MSC_VER) && (_MSC_VER < 1800)
+//***************************************************************
+//
+// expm1()
+//
+// Emulates C99 expm1() using exp().
+//
+// Returns:
+//
+// On Success: (('e' raised to the power of 'x') - 1)
+// (e.g. expm1(1) == 1.7182818).
+// On Failure: None, except that calling exp(x) should generate
+// an appropriate error for us (such as INF etc).
+//
+LIBPBD_API double PBD_APICALLTYPE
+expm1(double x)
+{
+ return (exp(x) - (double)1.0);
+}
+
+//***************************************************************
+//
+// log1p()
+//
+// Emulates C99 log1p() using log().
+//
+// Returns:
+//
+// On Success: The natural logarithm of (1 + x)
+// (e.g. log1p(1) == 0.69314718).
+// On Failure: None, except that calling log(x) should generate
+// an appropriate error for us (such as ERANGE etc).
+//
+LIBPBD_API double PBD_APICALLTYPE
+log1p(double x)
+{
+ return (log(x + (double)1.0));
+}
+
+//***************************************************************
+//
+// roundf()
+//
+// Emulates roundf() using floorf().
+//
+// Returns:
+//
+// On Success: The largest integer that is less than or
+// equal to 'x'.
+// On Failure: None
+//
+LIBPBD_API float PBD_APICALLTYPE
+roundf(float x)
+{
+ return (floorf(x));
+}
+
+//***************************************************************
+//
+// round()
+//
+// Emulates round() using floor().
+//
+// Returns:
+//
+// On Success: The largest integer that is less than or
+// equal to 'x'.
+// On Failure: None
+//
+LIBPBD_API double PBD_APICALLTYPE
+round(double x)
+{
+ return (floor(x));
+}
+#endif
+
+#if defined(_MSC_VER) && (_MSC_VER < 1900)
+//***************************************************************
+//
+// log2()
+//
+// Emulates C99 log2() using log().
+//
+// Returns:
+//
+// On Success: The binary (base-2) logarithm of 'x'
+// (e.g. log2(1024) == 10).
+// On Failure: None, except that calling log(x) should generate
+// an appropriate error for us (such as ERANGE etc).
+//
+LIBPBD_API double PBD_APICALLTYPE
+log2(double x)
+{
+ return (log(x) / log((double)2.0));
+}
+
+//***************************************************************
+//
+// trunc()
+//
+// Emulates trunc() using floor() and ceil().
+//
+// Returns:
+//
+// On Success: The largest integer whose magnitude is less
+// than or equal to 'x' (regardless of sign).
+// On Failure: None
+//
+LIBPBD_API double PBD_APICALLTYPE
+trunc(double x)
+{
+ if (x < 0)
+ return (ceil(x));
+
+ return (floor(x));
+}
+#endif
+
namespace PBD {
//***************************************************************
// On Success: TRUE (if the user's OS matches the minimum spec)
// On Failure: FALSE otherwise
//
-PBD_API bool PBD_APICALLTYPE
+LIBPBD_API bool PBD_APICALLTYPE
TestForMinimumSpecOS(char *revision /* currently ignored */)
{
bool bRet = true;
// On Success: A pointer to the resolved (absolute) path
// On Failure: NULL
//
-PBD_API char* PBD_APICALLTYPE
+LIBPBD_API char* PBD_APICALLTYPE
realpath (const char *original_path, char resolved_path[_MAX_PATH+1])
{
char *pRet = NULL;
// On Success: Pointer to a (heap based) DIR structure
// On Failure: NULL
//
-PBD_API DIR* PBD_APICALLTYPE
+LIBPBD_API DIR* PBD_APICALLTYPE
opendir (const char *szPath)
{
wchar_t wpath[PATH_MAX+1];
// On Success: A pointer to the supplied DIR's 'dirent' struct
// On Failure: NULL
//
-PBD_API struct dirent* PBD_APICALLTYPE
+LIBPBD_API struct dirent* PBD_APICALLTYPE
readdir (DIR* pDir)
{
int old_errno = 0;
// On Success: 0
// On Failure: -1
//
-PBD_API int PBD_APICALLTYPE
+LIBPBD_API int PBD_APICALLTYPE
closedir (DIR *pDir)
{
int rc = 0;
// On Success: A file descriptor for the opened file.
// On Failure: (-1)
//
-PBD_API int PBD_APICALLTYPE
+LIBPBD_API int PBD_APICALLTYPE
mkstemp (char *template_name)
{
int ret = (-1);
// On Success: Non-zero.
// On Failure: Zero (call 'GetLastError()' to retrieve info)
//
-PBD_API int PBD_APICALLTYPE
+LIBPBD_API int PBD_APICALLTYPE
ntfs_link (const char *existing_filepath, const char *link_filepath)
{
int ret = 1; // 'ERROR_INVALID_FUNCTION'
// On Success: Non-zero.
// On Failure: Zero (call 'GetLastError()' to retrieve info)
//
-PBD_API int PBD_APICALLTYPE
+LIBPBD_API int PBD_APICALLTYPE
ntfs_unlink (const char *link_filepath)
{
int ret = 1; // 'ERROR_INVALID_FUNCTION'
// On Success: A handle to the opened DLL
// On Failure: NULL
//
-PBD_API void* PBD_APICALLTYPE
+LIBPBD_API void* PBD_APICALLTYPE
dlopen (const char *file_name, int mode)
{
// Note that 'mode' is ignored in Win32
// On Success: A non-zero number
// On Failure: 0
//
-PBD_API int PBD_APICALLTYPE
+LIBPBD_API int PBD_APICALLTYPE
dlclose (void *handle)
{
return (::FreeLibrary((HMODULE)handle));
// On Success: A pointer to the found function or symbol
// On Failure: NULL
//
-PBD_API void* PBD_APICALLTYPE
+LIBPBD_API void* PBD_APICALLTYPE
dlsym (void *handle, const char *symbol_name)
{
// First test for RTLD_DEFAULT and RTLD_NEXT
// last error
// On Failure: NULL (if the last error was ERROR_SUCCESS)
//
-PBD_API char* PBD_APICALLTYPE
+LIBPBD_API char* PBD_APICALLTYPE
dlerror ()
{
DWORD dwLastErrorId = GetLastError();