Method: File.chardev?

Defined in:
file.c

.chardev?(file_name) ⇒ Boolean

Returns true if the named file is a character device.

file_name can be an IO object.

Returns:

  • (Boolean)


1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
# File 'file.c', line 1726

static VALUE
rb_file_chardev_p(VALUE obj, VALUE fname)
{
#ifndef S_ISCHR
#   define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
#endif

    struct stat st;

    if (rb_stat(fname, &st) < 0) return Qfalse;
    if (S_ISCHR(st.st_mode)) return Qtrue;

    return Qfalse;
}