8000 file.c: File.mkfifo · documenting-ruby/ruby@9289515 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 9289515

Browse files
committed
file.c: File.mkfifo
* file.c (rb_file_s_mkfifo): implement File.mkfifo. [Feature ruby#11536] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 30f9177 commit 9289515

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Fri Sep 18 20:11:11 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* file.c (rb_file_s_mkfifo): implement File.mkfifo.
4+
[Feature #11536]
5+
16
Fri Sep 18 16:56:19 2015 Shugo Maeda <shugo@ruby-lang.org>
27

38
* NEWS: add Net::FTP#mlst and Net::FTP#mlsd.

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ with all sufficient information, see the ChangeLog file.
3030
[Feature #11049]
3131
* Enumerable#chunk_while [Feature #10769]
3232

33+
* File
34+
35+
* File.mkfifo [Feature #11536]
36+
3337
* Hash
3438

3539
* Hash#fetch_values [Feature #10017]

configure.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,6 +2182,8 @@ AC_CHECK_FUNCS(memalign)
21822182
AC_CHECK_FUNCS(writev)
21832183
AC_CHECK_FUNCS(memrchr)
21842184
AC_CHECK_FUNCS(memmem)
2185+
AC_CHECK_FUNCS(mkfifo)
2186+
AC_CHECK_FUNCS(mknod)
21852187
AC_CHECK_FUNCS(mktime)
21862188
AC_CHECK_FUNCS(pipe2)
21872189
AC_CHECK_FUNCS(poll)

file.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5508,6 +5508,44 @@ rb_stat_sticky(VALUE obj)
55085508
return Qfalse;
55095509
}
55105510

5511+
#if !defined HAVE_MKFIFO && defined HAVE_MKNOD && defined S_IFIFO
5512+
#define mkfifo(path, mode) mknod(path, (mode)&~S_IFMT|S_IFIFO, 0)
5513+
#define HAVE_MKFIFO
5514+
#endif
5515+
5516+
/*
5517+
* call-seq:
5518+
* File.mkfifo(file_name, mode) => 0
5519+
*
5520+
* Creates a FIFO special file with name _file_name_. _mode_
5521+
* specifies the FIFO's permissions. It is modified by the process's
5522+
* umask in the usual way: the permissions of the created file are
5523+
* (mode & ~umask).
5524+
*/
5525+
5526+
#ifdef HAVE_MKFIFO
5527+
static VALUE
5528+
rb_file_s_mkfifo(int argc, VALUE *argv)
5529+
{
5530+
VALUE path;
5531+
int mode = 0666;
5532+
5533+
rb_check_arity(argc, 1, 2);
5534+
if (argc > 1) {
5535+
mode = NUM2INT(argv[1]);
5536+
}
5537+
path = argv[0];
5538+
FilePathValue(path);
5539+
path = rb_str_encode_ospath(path);
5540+
if (mkfifo(RSTRING_PTR(path), mode)) {
5541+
rb_sys_fail_path(path);
5542+
}
5543+
return INT2FIX(0);
5544+
}
5545+
#else
5546+
#define rb_file_s_mkfifo rb_f_notimplement
5547+
#endif
5548+
55115549
VALUE rb_mFConst;
55125550

55135551
void
@@ -5917,6 +5955,7 @@ Init_File(void)
59175955
rb_define_singleton_method(rb_cFile, "rename", rb_file_s_rename, 2);
59185956
rb_define_singleton_method(rb_cFile, "umask", rb_file_s_umask, -1);
59195957
rb_define_singleton_method(rb_cFile, "truncate", rb_file_s_truncate, 2);
5958+
rb_define_singleton_method(rb_cFile, "mkfifo", rb_file_s_mkfifo, -1);
59205959
rb_define_singleton_method(rb_cFile, "expand_path", rb_file_s_expand_path, -1);
59215960
rb_define_singleton_method(rb_cFile, "absolute_path", rb_file_s_absolute_path, -1);
59225961
rb_define_singleton_method(rb_cFile, "realpath", rb_file_s_realpath, -1);

test/lib/envutil.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
require_relative "find_executable"
55

66
def File.mkfifo(fn)
7-
raise NotImplementedError, "does not support fifo" if /mswin|mingw|bccwin/ =~ RUBY_PLATFORM
87
ret = system("mkfifo", fn)
98
raise NotImplementedError, "mkfifo fails" if !ret
10-
end
9+
end unless File.respond_to?(:mkfifo) or /mswin|mingw|bccwin/ =~ RUBY_PLATFORM
1110

1211
module EnvUtil
1312
def rubybin

0 commit comments

Comments
 (0)
0