24 extern "C" WINBASEAPI BOOL WINAPI
25 CreateHardLinkA( LPCSTR lpFileName,
26 LPCSTR lpExistingFileName,
27 LPSECURITY_ATTRIBUTES lpSecurityAttributes );
38 #include <ardourext/misc.h>
39 #include <ardourext/pthread.h>
44 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
53 gettimeofday(
struct timeval *__restrict tv, __timezone_ptr_t tz)
56 unsigned __int64 tmpres = 0;
57 static int tzflag = 0;
61 GetSystemTimeAsFileTime(&ft);
63 tmpres |= ft.dwHighDateTime;
65 tmpres |= ft.dwLowDateTime;
69 tmpres -= DELTA_EPOCH_IN_MICROSECS;
70 tv->tv_sec = (long)(tmpres / 1000000UL);
71 tv->tv_usec = (long)(tmpres % 1000000UL);
76 struct timezone *ptz =
static_cast<struct timezone*
> (tz);
84 ptz->tz_minuteswest = _timezone / 60;
85 ptz->tz_dsttime = _daylight;
94 #ifndef PTHREAD_H // Defined by PTW32 (Linux and other versions define _PTHREAD_H)
95 #error "An incompatible version of 'pthread.h' is #included. Use only the Windows (ptw32) version!"
97 LIBPBD_API bool operator> (
const pthread_t& lhs,
const pthread_t& rhs)
99 return (std::greater<void*>()(lhs.p, rhs.p));
104 return (std::less<void*>()(lhs.p, rhs.p));
109 return (std::not_equal_to<void*>()(lhs.p, rhs.p));
114 return (!(lhs != rhs));
130 char invert_backslash(
char character)
132 if (
'\\' == character)
149 char invert_forwardslash(
char character)
151 if (
'/' == character)
170 pread(
int handle,
void *buf,
size_t nbytes, off_t offset)
175 off_t old_offset = _tell(handle);
181 _lseek(handle, offset, SEEK_SET);
182 ret = _read(handle, buf, nbytes);
185 _lseek(handle, old_offset, SEEK_SET);
205 pwrite(
int handle,
const void *buf,
size_t nbytes, off_t offset)
210 off_t old_offset = _lseek(handle, offset, SEEK_SET);
216 ret = _write(handle, buf, nbytes);
219 _lseek(handle, old_offset, SEEK_SET);
281 return (log(x) / log((
double)2.0));
299 TestForMinimumSpecOS(
char *
revision )
302 #ifdef PLATFORM_WINDOWS
304 HINSTANCE hKernelDll = (HINSTANCE)dlopen(
"kernel32.dll", RTLD_NOW);
309 if (NULL != dlsym(hKernelDll,
"CreateHardLinkA"))
333 realpath (
const char *original_path,
char resolved_path[
_MAX_PATH+1])
350 char temp[(MAX_PATH+1)*6];
354 pRet = _fullpath(temp, Glib::locale_from_utf8(original_path).c_str(),
_MAX_PATH);
356 strcpy(resolved_path, Glib::locale_to_utf8(temp).c_str());
376 opendir (
const char *szPath)
387 if ((!errno) && (
'\0' == szPath[0]))
393 if (0 == MultiByteToWideChar (CP_UTF8, 0, (LPCSTR)szPath, -1, (LPWSTR)wpath,
sizeof(wpath)))
396 if ((!errno) && ((rc = GetFileAttributesW(wpath)) == -1))
399 if ((!errno) && (!(rc & FILE_ATTRIBUTE_DIRECTORY)))
407 pDir = (DIR *)malloc(
sizeof(DIR) + strlen(szPath) + strlen(
"\\") + strlen (
"*"));
419 strcpy(pDir->dd_name, szPath);
422 if (pDir->dd_name[0] !=
'\0' &&
423 pDir->dd_name[strlen(pDir->dd_name) - 1] !=
'/' &&
424 pDir->dd_name[strlen(pDir->dd_name) - 1] !=
'\\')
426 strcat (pDir->dd_name,
"\\");
430 strcat(pDir->dd_name,
"*");
434 pDir->dd_handle = (-1);
441 pDir->dd_dir.d_ino = 0;
442 pDir->dd_dir.d_reclen = 0;
443 pDir->dd_dir.d_namlen = 0;
444 strcpy(pDir->dd_dir.d_name, pDir->dd_dta.name);
477 if ((strcmp(pDir->dd_dir.d_name, pDir->dd_dta.name)) && (!errno))
482 if (pDir->dd_stat < 0)
486 return (
struct dirent *)0;
488 else if (pDir->dd_stat == 0)
492 pDir->dd_handle = _findfirst (Glib::locale_from_utf8(pDir->dd_name).c_str(), &(pDir->dd_dta));
494 if (pDir->dd_handle == -1)
506 if (_findnext (pDir->dd_handle, &(pDir->dd_dta)))
510 _findclose (pDir->dd_handle);
511 pDir->dd_handle = -1;
519 if (pDir->dd_stat > 0)
524 strcpy(pDir->dd_dir.d_name, pDir->dd_dta.name);
525 pDir->dd_dir.d_namlen = strlen (pDir->dd_dir.d_name);
526 return (&pDir->dd_dir);
530 return (
struct dirent *) 0;
556 if ((-1) != pDir->dd_handle)
557 rc = _findclose (pDir->dd_handle);
580 mkstemp (
char *template_name)
586 if (NULL != (szFileName = _mktemp(template_name)))
588 if (0 != ::GetTempPathA(
sizeof(szTempPath), szTempPath))
590 strcat(szTempPath, szFileName);
591 ret = _open(szTempPath, (_O_CREAT|_O_BINARY|_O_TEMPORARY|_O_RDWR|_O_TRUNC), _S_IWRITE);
611 ntfs_link (
const char *existing_filepath,
const char *link_filepath)
614 bool bValidPath =
false;
617 if (existing_filepath && link_filepath)
619 std::string strRoot = existing_filepath;
621 if ((1 < strRoot.length()) && (
'\\' == existing_filepath[0]) && (
'\\' == existing_filepath[1]))
626 std::transform(strRoot.begin(), strRoot.end(), strRoot.begin(), invert_backslash);
629 std::string::iterator iter = strRoot.begin();
630 while ((slashcnt < 4) && (iter != strRoot.end()))
645 iter = strRoot.begin();
647 for (slashcnt=0; slashcnt<4;)
654 if (++iter == strRoot.end())
658 strRoot.resize(charcnt);
665 if (1 < strRoot.length() && (
':' == existing_filepath[1]))
668 std::transform(strRoot.begin(), strRoot.end(), strRoot.begin(), invert_backslash);
670 if (2 == strRoot.length())
673 if (
'/' == strRoot[2])
686 std::transform(strRoot.begin(), strRoot.end(), strRoot.begin(), invert_forwardslash);
690 if (::GetVolumeInformationA(strRoot.c_str(), NULL, 0, NULL, NULL, NULL, szFileSystemType,
_MAX_PATH+1))
692 std::string strRootFileSystemType = szFileSystemType;
693 std::transform(strRootFileSystemType.begin(), strRootFileSystemType.end(), strRootFileSystemType.begin(), ::toupper);
694 #if (_WIN32_WINNT >= 0x0500)
695 if (0 == strRootFileSystemType.compare(
"NTFS"))
697 if (TestForMinimumSpecOS())
698 if (0 == CreateHardLinkA(link_filepath, existing_filepath, NULL))
701 ret = GetLastError();
704 SetLastError(ret = 0);
741 ntfs_unlink (
const char *link_filepath)
744 bool bValidPath =
false;
749 std::string strRoot = link_filepath;
751 if ((1 < strRoot.length()) && (
'\\' == link_filepath[0]) && (
'\\' == link_filepath[1]))
756 std::transform(strRoot.begin(), strRoot.end(), strRoot.begin(), invert_backslash);
759 std::string::iterator iter = strRoot.begin();
760 while ((slashcnt < 4) && (iter != strRoot.end()))
775 iter = strRoot.begin();
777 for (slashcnt=0; slashcnt<4;)
784 if (++iter == strRoot.end())
788 strRoot.resize(charcnt);
795 if (1 < strRoot.length() && (
':' == link_filepath[1]))
798 std::transform(strRoot.begin(), strRoot.end(), strRoot.begin(), invert_backslash);
800 if (2 == strRoot.length())
803 if (
'/' == strRoot[2])
816 std::transform(strRoot.begin(), strRoot.end(), strRoot.begin(), invert_forwardslash);
820 if (::GetVolumeInformationA(strRoot.c_str(), NULL, 0, NULL, NULL, NULL, szFileSystemType,
_MAX_PATH+1))
822 std::string strRootFileSystemType = szFileSystemType;
823 std::transform(strRootFileSystemType.begin(), strRootFileSystemType.end(), strRootFileSystemType.begin(), ::toupper);
824 #if (_WIN32_WINNT >= 0x0500)
825 if (0 == strRootFileSystemType.compare(
"NTFS"))
826 if (TestForMinimumSpecOS())
827 if (0 == DeleteFileA(link_filepath))
828 ret = GetLastError();
864 dlopen (
const char *file_name,
int mode)
867 return(::LoadLibraryA(Glib::locale_from_utf8(file_name).c_str()));
883 dlclose (
void *handle)
885 return (::FreeLibrary((HMODULE)handle));
901 dlsym (
void *handle,
const char *symbol_name)
904 if ((handle == 0) || (handle == ((
void *) -1L)))
909 return (::GetProcAddress((HMODULE)handle, symbol_name));
912 #define LOCAL_ERROR_BUF_SIZE 1024
913 static char szLastWinError[LOCAL_ERROR_BUF_SIZE];
929 DWORD dwLastErrorId = GetLastError();
930 if (ERROR_SUCCESS == dwLastErrorId)
934 if (0 == FormatMessage(
935 FORMAT_MESSAGE_FROM_SYSTEM,
940 LOCAL_ERROR_BUF_SIZE,
943 sprintf(szLastWinError,
"Could not decipher the previous error message");
948 SetLastError(ERROR_SUCCESS);
951 return(szLastWinError);
954 #endif // COMPILER_MSVC
bool operator<(shared_ptr< T > const &a, shared_ptr< U > const &b)
bool operator!=(shared_ptr< T > const &a, shared_ptr< U > const &b)
LIBARDOUR_API const char * revision
bool operator==(const RouteProcessorSelection &a, const RouteProcessorSelection &b)