diff options
Diffstat (limited to 'spec/ffi/fixtures/FunctionTest.c')
-rw-r--r-- | spec/ffi/fixtures/FunctionTest.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/ffi/fixtures/FunctionTest.c b/spec/ffi/fixtures/FunctionTest.c index a37373a..1dd9185 100644 --- a/spec/ffi/fixtures/FunctionTest.c +++ b/spec/ffi/fixtures/FunctionTest.c @@ -11,6 +11,7 @@ #ifndef _WIN32 #include <unistd.h> #include <pthread.h> +#include <stdarg.h> #include <stdlib.h> #endif @@ -61,6 +62,44 @@ void testBlockingClose(struct testBlockingData *self) { free(self); } +static int sum_varargs(va_list args) { + char sum = 0; + int arg; + while ((arg = va_arg(args, int)) != 0) { + sum += arg; + } + va_end(args); + return sum; +} + +/* Write c to pipe1 and return the value read from pipe2, or 0 if there’s + * an error such as a timeout, or if c does not equal the sum of the + * zero-terminated list of char arguments. */ +char testBlockingWRva(struct testBlockingData *self, char c, ...) { + va_list args; + va_start(args, c); + if (sum_varargs(args) != c) { + return 0; + } + + if( pipeHelperWriteChar(self->pipe1[1], c) != 1) + return 0; + return pipeHelperReadChar(self->pipe2[0], 10); +} + +char testBlockingRWva(struct testBlockingData *self, char c, ...) { + va_list args; + va_start(args, c); + if (sum_varargs(args) != c) { + return 0; + } + + char d = pipeHelperReadChar(self->pipe1[0], 10); + if( pipeHelperWriteChar(self->pipe2[1], c) != 1) + return 0; + return d; +} + struct async_data { void (*fn)(int); int value; |