Merge pull request #4069 from yurashek/master

Build on Solaris
This commit is contained in:
David Fort 2017-08-02 09:53:38 +02:00 committed by GitHub
commit c84065f40c
2 changed files with 87 additions and 0 deletions

View File

@ -990,6 +990,10 @@ BOOL freerdp_tcp_set_keep_alive_mode(int sockfd)
WLog_WARN(TAG, "setsockopt() IPPROTO_TCP, TCP_KEEPIDLE");
}
#endif
#ifndef SOL_TCP
/* "tcp" from /etc/protocols as getprotobyname(3C) */
#define SOL_TCP 6
#endif
#ifdef TCP_KEEPCNT
optval = 3;

View File

@ -276,7 +276,12 @@ static BOOL FileLockFileEx(HANDLE hFile, DWORD dwFlags, DWORD dwReserved,
DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh,
LPOVERLAPPED lpOverlapped)
{
#ifdef __sun
struct flock lock;
int lckcmd;
#else
int lock;
#endif
WINPR_FILE* pFile = (WINPR_FILE*)hFile;
if (lpOverlapped)
@ -295,6 +300,27 @@ static BOOL FileLockFileEx(HANDLE hFile, DWORD dwFlags, DWORD dwReserved,
return FALSE;
}
#ifdef __sun
lock.l_start = 0;
lock.l_len = 0;
lock.l_whence = SEEK_SET;
if (dwFlags & LOCKFILE_EXCLUSIVE_LOCK)
lock.l_type = F_WRLCK;
else
lock.l_type = F_WRLCK;
if (dwFlags & LOCKFILE_FAIL_IMMEDIATELY)
lckcmd = F_SETLK;
else
lckcmd = F_SETLKW;
if(fcntl(fileno(pFile->fp), lckcmd, &lock) == -1) {
WLog_ERR(TAG, "F_SETLK failed with %s [0x%08X]",
strerror(errno), errno);
return FALSE;
}
#else
if (dwFlags & LOCKFILE_EXCLUSIVE_LOCK)
lock = LOCK_EX;
else
@ -309,6 +335,7 @@ static BOOL FileLockFileEx(HANDLE hFile, DWORD dwFlags, DWORD dwReserved,
strerror(errno), errno);
return FALSE;
}
#endif
pFile->bLocked = TRUE;
@ -319,6 +346,9 @@ static BOOL FileUnlockFile(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffs
DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh)
{
WINPR_FILE* pFile = (WINPR_FILE*)hFile;
#ifdef __sun
struct flock lock;
#endif
if (!hFile)
return FALSE;
@ -329,12 +359,26 @@ static BOOL FileUnlockFile(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffs
return FALSE;
}
#ifdef __sun
lock.l_start = 0;
lock.l_len = 0;
lock.l_whence = SEEK_SET;
lock.l_type = F_UNLCK;
if (fcntl(fileno(pFile->fp), F_GETLK, &lock) == -1)
{
WLog_ERR(TAG, "F_UNLCK on %s failed with %s [0x%08X]",
pFile->lpFileName, strerror(errno), errno);
return FALSE;
}
#else
if (flock(fileno(pFile->fp), LOCK_UN) < 0)
{
WLog_ERR(TAG, "flock(LOCK_UN) %s failed with %s [0x%08X]",
pFile->lpFileName, strerror(errno), errno);
return FALSE;
}
#endif
return TRUE;
}
@ -343,6 +387,9 @@ static BOOL FileUnlockFileEx(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfByte
DWORD nNumberOfBytesToUnlockHigh, LPOVERLAPPED lpOverlapped)
{
WINPR_FILE* pFile = (WINPR_FILE*)hFile;
#ifdef __sun
struct flock lock;
#endif
if (lpOverlapped)
{
@ -360,12 +407,25 @@ static BOOL FileUnlockFileEx(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfByte
return FALSE;
}
#ifdef __sun
lock.l_start = 0;
lock.l_len = 0;
lock.l_whence = SEEK_SET;
lock.l_type = F_UNLCK;
if (fcntl(fileno(pFile->fp), F_GETLK, &lock) == -1)
{
WLog_ERR(TAG, "F_UNLCK on %s failed with %s [0x%08X]",
pFile->lpFileName, strerror(errno), errno);
return FALSE;
}
#else
if (flock(fileno(pFile->fp), LOCK_UN) < 0)
{
WLog_ERR(TAG, "flock(LOCK_UN) %s failed with %s [0x%08X]",
pFile->lpFileName, strerror(errno), errno);
return FALSE;
}
#endif
return TRUE;
}
@ -600,7 +660,11 @@ static HANDLE FileCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dw
WINPR_FILE* pFile;
BOOL create;
const char* mode = FileGetMode(dwDesiredAccess, dwCreationDisposition, &create);
#ifdef __sun
struct flock lock;
#else
int lock = 0;
#endif
FILE* fp = NULL;
struct stat st;
@ -677,16 +741,35 @@ static HANDLE FileCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dw
setvbuf(fp, NULL, _IONBF, 0);
#ifdef __sun
lock.l_start = 0;
lock.l_len = 0;
lock.l_whence = SEEK_SET;
if (dwShareMode & FILE_SHARE_READ)
lock.l_type = F_RDLCK;
if (dwShareMode & FILE_SHARE_WRITE)
lock.l_type = F_RDLCK;
#else
if (dwShareMode & FILE_SHARE_READ)
lock = LOCK_SH;
if (dwShareMode & FILE_SHARE_WRITE)
lock = LOCK_EX;
#endif
if (dwShareMode & (FILE_SHARE_READ | FILE_SHARE_WRITE))
{
#ifdef __sun
if (fcntl(fileno(pFile->fp), F_SETLKW, &lock) == -1)
#else
if (flock(fileno(pFile->fp), lock) < 0)
#endif
{
#ifdef __sun
WLog_ERR(TAG, "F_SETLKW failed with %s [0x%08X]",
#else
WLog_ERR(TAG, "flock failed with %s [0x%08X]",
#endif
strerror(errno), errno);
SetLastError(map_posix_err(errno));
FileCloseHandle(pFile);