From 47f65a93c59f146d1e4d9b4d7145bdeead7a6397 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 28 Apr 2020 18:13:43 +0900 Subject: Remove the temporary file from the `AF_UNIX` socket test; #4981 --- mrbgems/mruby-io/test/mruby_io_test.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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 +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) { -- cgit v1.2.3