FreeRDP/winpr/libwinpr/handle/handle.c

156 lines
2.9 KiB
C
Raw Normal View History

2012-05-29 22:14:26 +04:00
/**
* WinPR: Windows Portable Runtime
* Handle Management
*
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
2012-05-29 22:14:26 +04:00
#include <winpr/handle.h>
#ifndef _WIN32
#include "../synch/synch.h"
#include "../thread/thread.h"
2012-05-29 22:14:26 +04:00
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
2012-05-29 22:14:26 +04:00
BOOL CloseHandle(HANDLE hObject)
{
ULONG Type;
PVOID Object;
if (!winpr_Handle_GetInfo(hObject, &Type, &Object))
return FALSE;
2012-05-29 22:14:26 +04:00
if (Type == HANDLE_TYPE_THREAD)
{
WINPR_THREAD* thread;
thread = (WINPR_THREAD*) thread;
free(thread);
return TRUE;
}
else if (Type == HANDLE_TYPE_MUTEX)
{
pthread_mutex_destroy((pthread_mutex_t*) Object);
winpr_Handle_Remove(Object);
free(Object);
return TRUE;
}
else if (Type == HANDLE_TYPE_EVENT)
{
WINPR_EVENT* event;
event = (WINPR_EVENT*) Object;
if (!event->bAttached)
{
if (event->pipe_fd[0] != -1)
{
close(event->pipe_fd[0]);
event->pipe_fd[0] = -1;
}
if (event->pipe_fd[1] != -1)
{
close(event->pipe_fd[1]);
event->pipe_fd[1] = -1;
}
}
winpr_Handle_Remove(Object);
free(event);
return TRUE;
}
else if (Type == HANDLE_TYPE_SEMAPHORE)
{
WINPR_SEMAPHORE* semaphore;
semaphore = (WINPR_SEMAPHORE*) Object;
#ifdef WINPR_PIPE_SEMAPHORE
if (semaphore->pipe_fd[0] != -1)
{
close(semaphore->pipe_fd[0]);
semaphore->pipe_fd[0] = -1;
if (semaphore->pipe_fd[1] != -1)
{
close(semaphore->pipe_fd[1]);
semaphore->pipe_fd[1] = -1;
}
}
#else
#if defined __APPLE__
semaphore_destroy(mach_task_self(), *((winpr_sem_t*) semaphore->sem));
#else
sem_destroy((winpr_sem_t*) semaphore->sem);
#endif
#endif
winpr_Handle_Remove(Object);
free(Object);
return TRUE;
}
else if (Type == HANDLE_TYPE_ANONYMOUS_PIPE)
{
int pipe_fd;
pipe_fd = (int) ((ULONG_PTR) Object);
if (pipe_fd != -1)
{
close(pipe_fd);
}
winpr_Handle_Remove(Object);
return TRUE;
}
2012-05-29 22:14:26 +04:00
return FALSE;
2012-05-29 22:14:26 +04:00
}
BOOL DuplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle, HANDLE hTargetProcessHandle,
LPHANDLE lpTargetHandle, DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwOptions)
{
return TRUE;
2012-05-29 22:14:26 +04:00
}
BOOL GetHandleInformation(HANDLE hObject, LPDWORD lpdwFlags)
{
return TRUE;
2012-05-29 22:14:26 +04:00
}
BOOL SetHandleInformation(HANDLE hObject, DWORD dwMask, DWORD dwFlags)
{
return TRUE;
2012-05-29 22:14:26 +04:00
}
#endif