diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-18 11:11:14 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-18 11:11:14 +0000 |
commit | 9289515562230b6fa9f41559bbb3046f9556c8b3 (patch) | |
tree | 62ea7764478cd1612ad1410e95fdcbf554ee78d8 /file.c | |
parent | 30f9177d5d43b15d5d14f7b18ab96c932fb131f4 (diff) | |
download | ruby-9289515562230b6fa9f41559bbb3046f9556c8b3.tar.gz |
file.c: File.mkfifo
* file.c (rb_file_s_mkfifo): implement File.mkfifo.
[Feature #11536]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -5508,6 +5508,44 @@ rb_stat_sticky(VALUE obj) 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) 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); |