[前][次][番号順一覧][スレッド一覧]

ruby-changes:39816

From: nobu <ko1@a...>
Date: Fri, 18 Sep 2015 20:11:42 +0900 (JST)
Subject: [ruby-changes:39816] nobu:r51897 (trunk): file.c: File.mkfifo

nobu	2015-09-18 20:11:14 +0900 (Fri, 18 Sep 2015)

  New Revision: 51897

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51897

  Log:
    file.c: File.mkfifo
    
    * file.c (rb_file_s_mkfifo): implement File.mkfifo.
      [Feature #11536]

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/configure.in
    trunk/file.c
    trunk/test/lib/envutil.rb
Index: configure.in
===================================================================
--- configure.in	(revision 51896)
+++ configure.in	(revision 51897)
@@ -2182,6 +2182,8 @@ AC_CHECK_FUNCS(memalign) https://github.com/ruby/ruby/blob/trunk/configure.in#L2182
 AC_CHECK_FUNCS(writev)
 AC_CHECK_FUNCS(memrchr)
 AC_CHECK_FUNCS(memmem)
+AC_CHECK_FUNCS(mkfifo)
+AC_CHECK_FUNCS(mknod)
 AC_CHECK_FUNCS(mktime)
 AC_CHECK_FUNCS(pipe2)
 AC_CHECK_FUNCS(poll)
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51896)
+++ ChangeLog	(revision 51897)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Sep 18 20:11:11 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* file.c (rb_file_s_mkfifo): implement File.mkfifo.
+	  [Feature #11536]
+
 Fri Sep 18 16:56:19 2015  Shugo Maeda  <shugo@r...>
 
 	* NEWS: add Net::FTP#mlst and Net::FTP#mlsd.
Index: NEWS
===================================================================
--- NEWS	(revision 51896)
+++ NEWS	(revision 51897)
@@ -30,6 +30,10 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L30
     [Feature #11049]
   * Enumerable#chunk_while [Feature #10769]
 
+* File
+
+  * File.mkfifo [Feature #11536]
+
 * Hash
 
   * Hash#fetch_values [Feature #10017]
Index: test/lib/envutil.rb
===================================================================
--- test/lib/envutil.rb	(revision 51896)
+++ test/lib/envutil.rb	(revision 51897)
@@ -4,10 +4,9 @@ require "timeout" https://github.com/ruby/ruby/blob/trunk/test/lib/envutil.rb#L4
 require_relative "find_executable"
 
 def File.mkfifo(fn)
-  raise NotImplementedError, "does not support fifo" if /mswin|mingw|bccwin/ =~ RUBY_PLATFORM
   ret = system("mkfifo", fn)
   raise NotImplementedError, "mkfifo fails" if !ret
-end
+end unless File.respond_to?(:mkfifo) or /mswin|mingw|bccwin/ =~ RUBY_PLATFORM
 
 module EnvUtil
   def rubybin
Index: file.c
===================================================================
--- file.c	(revision 51896)
+++ file.c	(revision 51897)
@@ -5508,6 +5508,44 @@ rb_stat_sticky(VALUE obj) https://github.com/ruby/ruby/blob/trunk/file.c#L5508
     return Qfalse;
 }
 
+#if !defined HAVE_MKFIFO && defined HAVE_MKNOD && defined S_IFIFO
+#define mkfifo(path, mode) mknod(path, (mode)&~S_IFMT|S_IFIFO, 0)
+#define HAVE_MKFIFO
+#endif
+
+/*
+ *  call-seq:
+ *     File.mkfifo(file_name, mode)  => 0
+ *
+ *  Creates a FIFO special file with name _file_name_.  _mode_
+ *  specifies the FIFO's permissions. It is modified by the process's
+ *  umask in the usual way: the permissions of the created file are
+ *  (mode & ~umask).
+ */
+
+#ifdef HAVE_MKFIFO
+static VALUE
+rb_file_s_mkfifo(int argc, VALUE *argv)
+{
+    VALUE path;
+    int mode = 0666;
+
+    rb_check_arity(argc, 1, 2);
+    if (argc > 1) {
+	mode = NUM2INT(argv[1]);
+    }
+    path = argv[0];
+    FilePathValue(path);
+    path = rb_str_encode_ospath(path);
+    if (mkfifo(RSTRING_PTR(path), mode)) {
+	rb_sys_fail_path(path);
+    }
+    return INT2FIX(0);
+}
+#else
+#define rb_file_s_mkfifo rb_f_notimplement
+#endif
+
 VALUE rb_mFConst;
 
 void
@@ -5917,6 +5955,7 @@ Init_File(void) https://github.com/ruby/ruby/blob/trunk/file.c#L5955
     rb_define_singleton_method(rb_cFile, "rename", rb_file_s_rename, 2);
     rb_define_singleton_method(rb_cFile, "umask", rb_file_s_umask, -1);
     rb_define_singleton_method(rb_cFile, "truncate", rb_file_s_truncate, 2);
+    rb_define_singleton_method(rb_cFile, "mkfifo", rb_file_s_mkfifo, -1);
     rb_define_singleton_method(rb_cFile, "expand_path", rb_file_s_expand_path, -1);
     rb_define_singleton_method(rb_cFile, "absolute_path", rb_file_s_absolute_path, -1);
     rb_define_singleton_method(rb_cFile, "realpath", rb_file_s_realpath, -1);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]