Project

General

Profile

Feature #9880 ยป dir-fileno.patch

akr (Akira Tanaka), 05/29/2014 11:36 AM

View differences:

configure.in (working copy)
1950 1950
AC_CHECK_FUNCS(clock_gettime)
1951 1951
AC_CHECK_FUNCS(cosh)
1952 1952
AC_CHECK_FUNCS(daemon)
1953
AC_CHECK_FUNCS(dirfd)
1953 1954
AC_CHECK_FUNCS(dl_iterate_phdr)
1954 1955
AC_CHECK_FUNCS(dlopen)
1955 1956
AC_CHECK_FUNCS(dladdr)
dir.c (working copy)
539 539
    return rb_funcall(dir, rb_intern("to_s"), 0, 0);
540 540
}
541 541

  
542
#ifdef HAVE_DIRFD
543
/*
544
 *  call-seq:
545
 *     dir.fileno -> integer
546
 *
547
 *  Returns the file descriptor used in <em>dir</em>.
548
 *
549
 *     d = Dir.new("..")
550
 *     d.fileno   #=> 8
551
 */
552
static VALUE
553
dir_fileno(VALUE dir)
554
{
555
    struct dir_data *dirp;
556
    int fd;
557

  
558
    GetDIR(dir, dirp);
559
    fd = dirfd(dirp->dir);
560
    if (fd == -1)
561
	rb_sys_fail("dirfd");
562
    return INT2NUM(fd);
563
}
564
#else
565
#define dir_fileno rb_f_notimplement
566
#endif
567

  
542 568
/*
543 569
 *  call-seq:
544 570
 *     dir.path -> string or nil
......
2254 2280
    rb_define_singleton_method(rb_cDir, "entries", dir_entries, -1);
2255 2281

  
2256 2282
    rb_define_method(rb_cDir,"initialize", dir_initialize, -1);
2283
    rb_define_method(rb_cDir,"fileno", dir_fileno, 0);
2257 2284
    rb_define_method(rb_cDir,"path", dir_path, 0);
2258 2285
    rb_define_method(rb_cDir,"to_path", dir_path, 0);
2259 2286
    rb_define_method(rb_cDir,"inspect", dir_inspect, 0);