summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2012-02-19 08:50:03 +0000
committer Miodrag Milanovic <mmicko@gmail.com>2012-02-19 08:50:03 +0000
commit4ba8461f7cfe12d35ad94d79554a04d2e40cf751 (patch)
treeae351c62680ea0a3f71cda1d986f00f8e2d6f6f8
parentf15ecf090fadf9d06afe0566a06499c0688d8252 (diff)
Added windows implementation of pseudo tty access functions over pipes [Carl]
-rw-r--r--.gitattributes1
-rw-r--r--src/osd/windows/windows.mak3
-rw-r--r--src/osd/windows/winfile.c16
-rw-r--r--src/osd/windows/winfile.h8
-rw-r--r--src/osd/windows/winptty.c67
5 files changed, 93 insertions, 2 deletions
diff --git a/.gitattributes b/.gitattributes
index 9bb4e97d4ae..60171c4acc3 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -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
diff --git a/src/osd/windows/windows.mak b/src/osd/windows/windows.mak
index 08f049f2f07..78ff6a8d94a 100644
--- a/src/osd/windows/windows.mak
+++ b/src/osd/windows/windows.mak
@@ -281,7 +281,8 @@ OSDCOREOBJS = \
$(WINOBJ)/winutil.o \
$(WINOBJ)/winclip.o \
$(WINOBJ)/winsocket.o \
- $(WINOBJ)/winwork.o
+ $(WINOBJ)/winwork.o \
+ $(WINOBJ)/winptty.o
diff --git a/src/osd/windows/winfile.c b/src/osd/windows/winfile.c
index faeac115edd..17a15bb0055 100644
--- a/src/osd/windows/winfile.c
+++ b/src/osd/windows/winfile.c
@@ -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;
}
diff --git a/src/osd/windows/winfile.h b/src/osd/windows/winfile.h
index 82cbc886ed1..b71d9434490 100644
--- a/src/osd/windows/winfile.h
+++ b/src/osd/windows/winfile.h
@@ -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__
diff --git a/src/osd/windows/winptty.c b/src/osd/windows/winptty.c
new file mode 100644
index 00000000000..28de05e9a31
--- /dev/null
+++ b/src/osd/windows/winptty.c
@@ -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;
+}