Added windows implementation of pseudo tty access functions over pipes [Carl]

This commit is contained in:
Miodrag Milanovic 2012-02-19 08:50:03 +00:00
parent f15ecf090f
commit 4ba8461f7c
5 changed files with 93 additions and 2 deletions

1
.gitattributes vendored
View File

@ -5281,6 +5281,7 @@ src/osd/windows/winmain.h svneol=native#text/plain
src/osd/windows/winmenu.c svneol=native#text/plain
src/osd/windows/winmisc.c svneol=native#text/plain
src/osd/windows/winprefix.h svneol=native#text/plain
src/osd/windows/winptty.c svneol=native#text/plain
src/osd/windows/winsocket.c svneol=native#text/plain
src/osd/windows/winsync.c svneol=native#text/plain
src/osd/windows/wintime.c svneol=native#text/plain

View File

@ -281,7 +281,8 @@ OSDCOREOBJS = \
$(WINOBJ)/winutil.o \
$(WINOBJ)/winclip.o \
$(WINOBJ)/winsocket.o \
$(WINOBJ)/winwork.o
$(WINOBJ)/winwork.o \
$(WINOBJ)/winptty.o

View File

@ -72,6 +72,7 @@ INLINE int is_path_to_physical_drive(const char *path)
return (_strnicmp(path, "\\\\.\\physicaldrive", 17) == 0);
}
extern const char *winfile_ptty_identifier;
//============================================================
@ -110,6 +111,13 @@ file_error osd_open(const char *path, UINT32 openflags, osd_file **file, UINT64
goto error;
}
if (strncmp(path, winfile_ptty_identifier, strlen(winfile_ptty_identifier)) == 0)
{
(*file)->type = WINFILE_PTTY;
filerr = win_open_ptty(path, openflags, file, filesize);
goto error;
}
(*file)->type = WINFILE_FILE;
// convert the path into something Windows compatible
@ -214,6 +222,9 @@ file_error osd_read(osd_file *file, void *buffer, UINT64 offset, UINT32 length,
case WINFILE_SOCKET:
return win_read_socket(file, buffer, offset, length, actual);
break;
case WINFILE_PTTY:
return win_read_ptty(file, buffer, offset, length, actual);
break;
}
return FILERR_NONE;
@ -250,6 +261,9 @@ file_error osd_write(osd_file *file, const void *buffer, UINT64 offset, UINT32 l
case WINFILE_SOCKET:
return win_write_socket(file, buffer, offset, length, actual);
break;
case WINFILE_PTTY:
return win_write_ptty(file, buffer, offset, length, actual);
break;
}
return FILERR_NONE;
@ -272,6 +286,8 @@ file_error osd_close(osd_file *file)
case WINFILE_SOCKET:
return win_close_socket(file);
break;
case WINFILE_PTTY:
return win_close_ptty(file);
}
return FILERR_NONE;
}

View File

@ -15,7 +15,8 @@
enum
{
WINFILE_FILE = 0,
WINFILE_SOCKET
WINFILE_SOCKET,
WINFILE_PTTY
};
//============================================================
@ -43,6 +44,11 @@ file_error win_read_socket(osd_file *file, void *buffer, UINT64 offset, UINT32 c
file_error win_write_socket(osd_file *file, const void *buffer, UINT64 offset, UINT32 count, UINT32 *actual);
file_error win_close_socket(osd_file *file);
file_error win_open_ptty(const char *path, UINT32 openflags, osd_file **file, UINT64 *filesize);
file_error win_read_ptty(osd_file *file, void *buffer, UINT64 offset, UINT32 count, UINT32 *actual);
file_error win_write_ptty(osd_file *file, const void *buffer, UINT64 offset, UINT32 count, UINT32 *actual);
file_error win_close_ptty(osd_file *file);
file_error win_error_to_mame_file_error(DWORD error);
#endif //__WINFILE__

67
src/osd/windows/winptty.c Normal file
View File

@ -0,0 +1,67 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "winfile.h"
#include "strconv.h"
#include "winutil.h"
const char *winfile_ptty_identifier = "\\\\.\\pipe\\";
file_error win_open_ptty(const char *path, UINT32 openflags, osd_file **file, UINT64 *filesize)
{
TCHAR *t_name;
HANDLE pipe;
if((t_name = tstring_from_utf8(path)) == NULL)
return FILERR_OUT_OF_MEMORY;
pipe = CreateNamedPipe(t_name, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_NOWAIT, 1, 32, 32, 0, NULL);
if(pipe == INVALID_HANDLE_VALUE)
return FILERR_ACCESS_DENIED;
(*file)->handle = pipe;
*filesize = 0;
osd_free(t_name);
return FILERR_NONE;
}
file_error win_read_ptty(osd_file *file, void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
{
BOOL res;
DWORD bytes_read;
res = ReadFile(file->handle, buffer, count, &bytes_read, NULL);
if(res == FALSE)
return win_error_to_file_error(GetLastError());
if(actual != NULL)
*actual = bytes_read;
return FILERR_NONE;
}
file_error win_write_ptty(osd_file *file, const void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
{
BOOL res;
DWORD bytes_wrote;
res = WriteFile(file->handle, buffer, count, &bytes_wrote, NULL);
if(res == FALSE)
return win_error_to_file_error(GetLastError());
if(actual != NULL)
*actual = bytes_wrote;
return FILERR_NONE;
}
file_error win_close_ptty(osd_file *file)
{
FlushFileBuffers(file->handle);
DisconnectNamedPipe(file->handle);
CloseHandle(file->handle);
osd_free(file);
return FILERR_NONE;
}