From f9a0ada725b012261ec9460185105f57206c70c3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 18 Oct 2006 16:08:22 +0000 Subject: r19393: Add replacement function for socketpair() (This used to be commit 448a3ecc0184bfa063db1eb3ae6dc16b8b792792) --- source4/lib/replace/replace.c | 21 ++++++++++++++++++ source4/lib/replace/replace.h | 4 ++++ source4/lib/replace/test/testsuite.c | 41 ++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) (limited to 'source4/lib/replace') diff --git a/source4/lib/replace/replace.c b/source4/lib/replace/replace.c index e7f47d7d52..83d7948dfb 100644 --- a/source4/lib/replace/replace.c +++ b/source4/lib/replace/replace.c @@ -590,3 +590,24 @@ int rep_setenv(const char *name, const char *value, int overwrite) } #endif +#ifndef HAVE_SOCKETPAIR +int rep_socketpair(int d, int type, int protocol, int sv[2]) +{ + if (d != AF_UNIX) { + errno = EAFNOSUPPORT; + return -1; + } + + if (protocol != 0) { + errno = EPROTONOSUPPORT; + return -1; + } + + if (type != SOCK_STREAM) { + errno = EOPNOTSUPP; + return -1; + } + + return pipe(sock); +} +#endif diff --git a/source4/lib/replace/replace.h b/source4/lib/replace/replace.h index 7a79f335e2..d75394aa1f 100644 --- a/source4/lib/replace/replace.h +++ b/source4/lib/replace/replace.h @@ -209,6 +209,10 @@ void *rep_dlsym(void *handle, const char *symbol); int rep_dlclose(void *handle); #endif +#ifndef HAVE_SOCKETPAIR +#define socketpair rep_socketpair +int rep_socketpair(int d, int type, int protocol, int sv[2]); +#endif #ifndef PRINTF_ATTRIBUTE #if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) diff --git a/source4/lib/replace/test/testsuite.c b/source4/lib/replace/test/testsuite.c index 3e20e22e45..e921a7fc97 100644 --- a/source4/lib/replace/test/testsuite.c +++ b/source4/lib/replace/test/testsuite.c @@ -376,6 +376,46 @@ static int test_MAX(void) return true; } +static bool test_socketpair(void) +{ + int sock[2]; + char buf[20]; + + printf("test: socketpair\n"); + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock) == -1) { + printf("failure: socketpair [\n" + "socketpair() failed\n" + "]\n"); + return false; + } + + if (write(sock[0], "automatisch", 12) == -1) { + printf("failure: socketpair [\n" + "write() failed: %s\n" + "]\n", strerror(errno)); + return false; + } + + if (read(sock[1], buf, 12) == -1) { + printf("failure: socketpair [\n" + "read() failed: %s\n" + "]\n", strerror(errno)); + return false; + } + + if (strcmp(buf, "automatisch") != 0) { + printf("failure: socketpair [\n" + "expected: automatisch, got: %s\n" + "]\n", buf); + return false; + } + + printf("success: socketpair\n"); + + return true; +} + struct torture_context; int main() @@ -424,6 +464,7 @@ int main() ret &= test_FUNCTION(); ret &= test_MIN(); ret &= test_MAX(); + ret &= test_socketpair(); if (ret) return 0; -- cgit