Feature #4512 » 0001-ext-fcntl-fcntl.c-add-F_DUPFD_CLOEXEC-constant.patch
ext/fcntl/fcntl.c | ||
---|---|---|
************************************************/
|
||
#define _POSIX_C_SOURCE 200809L
|
||
#include "ruby.h"
|
||
#include <fcntl.h>
|
||
... | ... | |
#ifdef F_DUPFD
|
||
rb_define_const(mFcntl, "F_DUPFD", INT2NUM(F_DUPFD));
|
||
#endif
|
||
#ifdef F_DUPFD_CLOEXEC
|
||
rb_define_const(mFcntl, "F_DUPFD_CLOEXEC", INT2NUM(F_DUPFD_CLOEXEC));
|
||
#endif
|
||
#ifdef F_GETFD
|
||
rb_define_const(mFcntl, "F_GETFD", INT2NUM(F_GETFD));
|
||
#endif
|
test/fcntl/test_fcntl.rb | ||
---|---|---|
require 'test/unit'
|
||
begin
|
||
require 'fcntl'
|
||
rescue LoadError
|
||
end
|
||
class TestFcntl < Test::Unit::TestCase
|
||
include Fcntl
|
||
def setup
|
||
@r, @w = IO.pipe
|
||
end
|
||
def teardown
|
||
@r.close unless @r.closed?
|
||
@w.close unless @w.closed?
|
||
end
|
||
def test_fcntl_cloexec
|
||
flags = @r.fcntl(F_GETFD)
|
||
assert_equal(0, flags & FD_CLOEXEC, "old flags=#{flags}")
|
||
fd = @r.fcntl(F_DUPFD_CLOEXEC)
|
||
assert_kind_of Integer, fd, "not integer: #{fd.inspect}"
|
||
io = IO.for_fd(fd)
|
||
flags = io.fcntl(F_GETFD)
|
||
assert_equal(FD_CLOEXEC, flags & FD_CLOEXEC, "new flags=#{flags}")
|
||
assert_nil io.close
|
||
end if defined?(F_DUPFD_CLOEXEC)
|
||
end if defined?(Fcntl)
|
- « Previous
- 1
- 2
- Next »