Merge pull request #2887 from FreeRDP/mh-file-api-extension

winpr/file: extend API
This commit is contained in:
Martin Fleisz 2015-09-15 15:57:56 +02:00
commit 912cd96321
2 changed files with 28 additions and 5 deletions

View File

@ -360,6 +360,7 @@ WINPR_API char* GetNamedPipeUnixDomainSocketBaseFilePathA(void);
WINPR_API char* GetNamedPipeUnixDomainSocketFilePathA(LPCSTR lpName);
WINPR_API int GetNamePipeFileDescriptor(HANDLE hNamedPipe);
WINPR_API HANDLE GetFileHandleForFileDescriptor(int fd);
#ifdef __cplusplus
}

View File

@ -18,21 +18,22 @@
* limitations under the License.
*/
#ifndef _WIN32
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <winpr/file.h>
#ifndef _WIN32
#include "../log.h"
#define TAG WINPR_TAG("file")
#include <winpr/file.h>
#include <winpr/wlog.h>
#include "../handle/handle.h"
#include <errno.h>
#include <fcntl.h>
struct winpr_file
{
@ -215,13 +216,34 @@ HANDLE GetStdHandle(DWORD nStdHandle)
BOOL SetStdHandle(DWORD nStdHandle, HANDLE hHandle)
{
return TRUE;
return FALSE;
}
BOOL SetStdHandleEx(DWORD dwStdHandle, HANDLE hNewHandle, HANDLE* phOldHandle)
{
return TRUE;
return FALSE;
}
#endif /* _WIN32 */
/* Extended API */
HANDLE GetFileHandleForFileDescriptor(int fd)
{
#ifdef WIN32
return (HANDLE)_get_osfhandle(fd);
#else /* WIN32 */
WINPR_FILE *pFile;
/* Make sure it's a valid fd */
if (fcntl(fd, F_GETFD) == -1 && errno == EBADF)
return INVALID_HANDLE_VALUE;
pFile = FileHandle_New();
if (!pFile)
return INVALID_HANDLE_VALUE;
pFile->fd = fd;
return (HANDLE)pFile;
#endif /* WIN32 */
}