0001-ext-fcntl-fcntl.c-add-F_DUPFD_CLOEXEC-constant.patch

updated patch with test case - Eric Wong, 07/01/2011 04:33 PM

Download (2.04 KB)

View differences:

ext/fcntl/fcntl.c
31 31

  
32 32
************************************************/
33 33

  
34
#define _POSIX_C_SOURCE 200809L
34 35
#include "ruby.h"
35 36
#include <fcntl.h>
36 37

  
......
116 117
#ifdef F_DUPFD
117 118
    rb_define_const(mFcntl, "F_DUPFD", INT2NUM(F_DUPFD));
118 119
#endif
120
#ifdef F_DUPFD_CLOEXEC
121
    rb_define_const(mFcntl, "F_DUPFD_CLOEXEC", INT2NUM(F_DUPFD_CLOEXEC));
122
#endif
119 123
#ifdef F_GETFD
120 124
    rb_define_const(mFcntl, "F_GETFD", INT2NUM(F_GETFD));
121 125
#endif
test/fcntl/test_fcntl.rb
1
require 'test/unit'
2
begin
3
  require 'fcntl'
4
rescue LoadError
5
end
6

  
7
class TestFcntl < Test::Unit::TestCase
8
  include Fcntl
9

  
10
  def setup
11
    @r, @w = IO.pipe
12
  end
13

  
14
  def teardown
15
    @r.close unless @r.closed?
16
    @w.close unless @w.closed?
17
  end
18

  
19
  def test_fcntl_cloexec
20
    flags = @r.fcntl(F_GETFD)
21
    assert_equal(0, flags & FD_CLOEXEC, "old flags=#{flags}")
22

  
23
    fd = @r.fcntl(F_DUPFD_CLOEXEC)
24
    assert_kind_of Integer, fd, "not integer: #{fd.inspect}"
25

  
26
    io = IO.for_fd(fd)
27
    flags = io.fcntl(F_GETFD)
28
    assert_equal(FD_CLOEXEC, flags & FD_CLOEXEC, "new flags=#{flags}")
29
    assert_nil io.close
30
  end if defined?(F_DUPFD_CLOEXEC)
31
end if defined?(Fcntl)
0
-