summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-io/test/mruby_io_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'mrbgems/mruby-io/test/mruby_io_test.c')
-rw-r--r--mrbgems/mruby-io/test/mruby_io_test.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/mrbgems/mruby-io/test/mruby_io_test.c b/mrbgems/mruby-io/test/mruby_io_test.c
index 8bc87a0d4..7ad59d495 100644
--- a/mrbgems/mruby-io/test/mruby_io_test.c
+++ b/mrbgems/mruby-io/test/mruby_io_test.c
@@ -67,6 +67,38 @@ mkdtemp(char *temp)
#include "mruby/variable.h"
#include <mruby/ext/io.h>
+int wd_save;
+int socket_available_p;
+
+#if !defined(_WIN32) && !defined(_WIN64)
+static int mrb_io_socket_available()
+{
+ int fd, retval = 1;
+ struct sockaddr_un sun0;
+ char socketname[] = "tmp.mruby-io-socket-ok.XXXXXXXX";
+ if (!(fd = mkstemp(socketname))) {
+ retval = 0;
+ goto sock_test_out;
+ }
+ unlink(socketname);
+ close(fd);
+ fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (fd == -1) {
+ retval = 0;
+ goto sock_test_out;
+ }
+ sun0.sun_family = AF_UNIX;
+ snprintf(sun0.sun_path, sizeof(sun0.sun_path), "%s", socketname);
+ if (bind(fd, (struct sockaddr *)&sun0, sizeof(sun0)) == -1) {
+ retval = 0;
+ }
+sock_test_out:
+ unlink(socketname);
+ close(fd);
+ return retval;
+}
+#endif
+
static mrb_value
mrb_io_test_io_setup(mrb_state *mrb, mrb_value self)
{