From 4f5791ebd03eaec1c7da0865a383175b05102712 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 5 May 2024 19:47:29 +0200 Subject: Adding upstream version 2:4.17.12+dfsg. Signed-off-by: Daniel Baumann --- testprogs/win32/testmailslot/GNUmakefile | 16 ++++++ testprogs/win32/testmailslot/NMakefile | 13 +++++ testprogs/win32/testmailslot/testmailslot.c | 80 +++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 testprogs/win32/testmailslot/GNUmakefile create mode 100644 testprogs/win32/testmailslot/NMakefile create mode 100644 testprogs/win32/testmailslot/testmailslot.c (limited to 'testprogs/win32/testmailslot') diff --git a/testprogs/win32/testmailslot/GNUmakefile b/testprogs/win32/testmailslot/GNUmakefile new file mode 100644 index 0000000..a41fb91 --- /dev/null +++ b/testprogs/win32/testmailslot/GNUmakefile @@ -0,0 +1,16 @@ +INCLUDES=-I. +CFLAGS=$(INCLUDES) +MINGW_CC = i586-mingw32msvc-cc +CC = $(MINGW_CC) + +all: testmailslot.exe + +clean: + rm -f *~ *.obj testmailslot.exe + +.SUFFIXES: .obj .exe .c + +testmailslot.exe: testmailslot.c + +.c.exe: + $(CC) $(CFLAGS) -o $@ $^ $(LIBS) diff --git a/testprogs/win32/testmailslot/NMakefile b/testprogs/win32/testmailslot/NMakefile new file mode 100644 index 0000000..7551d7b --- /dev/null +++ b/testprogs/win32/testmailslot/NMakefile @@ -0,0 +1,13 @@ +# +# use nmake /f NMakefile [] +# +INCLUDES=-I +CFLAGS=$(INCLUDES) -Zi -nologo + +all: testmailslot.exe + +clean: + del *~ *.obj testmailslot.exe + +testmailslot.exe: testmailslot.obj + $(CC) $(CFLAGS) -o testmailslot.exe testmailslot.obj $(LIBS) diff --git a/testprogs/win32/testmailslot/testmailslot.c b/testprogs/win32/testmailslot/testmailslot.c new file mode 100644 index 0000000..b953636 --- /dev/null +++ b/testprogs/win32/testmailslot/testmailslot.c @@ -0,0 +1,80 @@ +/* + * Very simple test application for mailslots + * (C) 2005 Jelmer Vernooij + * Published to the public domain + */ + +#include +#include + +int read_slot(const char *mailslotname) +{ + HANDLE h; + DWORD nr; + char data[30000]; + DWORD nextsize, nummsg = 0; + + if (strncmp(mailslotname, "\\\\.\\mailslot\\", 13) && strncmp(mailslotname, "\\\\*\\mailslot\\", 13)) { + printf("Must specify local mailslot name (starting with \\\\.\\mailslot\\)\n"); + return 1; + } + + h = CreateMailslot(mailslotname, 0, MAILSLOT_WAIT_FOREVER, NULL); + + if (h == INVALID_HANDLE_VALUE) { + printf("Unable to create mailslot %s: %d\n", mailslotname, GetLastError()); + return 1; + } + + if (!ReadFile(h, data, sizeof(data)-1, &nr, NULL)) { + printf("Error reading: %d\n", GetLastError()); + return 1; + } + + data[nr] = '\0'; + + printf("%s\n", data); + + CloseHandle(h); +} + +int write_slot(const char *mailslotname) +{ + HANDLE h; + DWORD nw; + char data[30000]; + h = CreateFile(mailslotname, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + + if (h == INVALID_HANDLE_VALUE) { + printf("Unable to open file: %d\n", GetLastError()); + return 1; + } + + gets(data); + + if (!WriteFile(h, data, strlen(data), &nw, NULL)) { + printf("Error writing file: %d\n", GetLastError()); + return 1; + } + + CloseHandle(h); +} + +int main(int argc, char **argv) +{ + if (argc < 3 || + (strcmp(argv[1], "read") && strcmp(argv[1], "write"))) { + printf("Usage: %s read|write mailslot\n", argv[0]); + return 1; + } + + if (!strcmp(argv[1], "read")) { + return read_slot(argv[2]); + } + + if (!strcmp(argv[1], "write")) { + return write_slot(argv[2]); + } + + return 0; +} -- cgit v1.2.3