summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-io/test
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2020-04-28 18:13:43 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2020-10-12 16:20:43 +0900
commit47f65a93c59f146d1e4d9b4d7145bdeead7a6397 (patch)
tree0cc0cd4f794a09d4c5d3983e9b4b24fb5bb241a5 /mrbgems/mruby-io/test
parenta2fbb98fa63b1397f30706797b975b42484ed941 (diff)
downloadmruby-47f65a93c59f146d1e4d9b4d7145bdeead7a6397.tar.gz
mruby-47f65a93c59f146d1e4d9b4d7145bdeead7a6397.zip
Remove the temporary file from the `AF_UNIX` socket test; #4981
Diffstat (limited to 'mrbgems/mruby-io/test')
-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)
{