Feature #5974 ยป max_path.patch
dir.c | ||
---|---|---|
}
|
||
/*
|
||
* call-seq:
|
||
* dir.path_max -> 1024
|
||
*
|
||
* Returns the maximum number of bytes in a path name relative to the
|
||
* directory object on which it is called.
|
||
*/
|
||
static VALUE
|
||
dir_path_max(VALUE dir)
|
||
{
|
||
long max_path;
|
||
struct dir_data *dirp;
|
||
TypedData_Get_Struct(dir, struct dir_data, &dir_data_type, dirp);
|
||
errno = 0;
|
||
max_path = fpathconf(dirfd(dirp->dir), _PC_PATH_MAX);
|
||
if (max_path == -1) {
|
||
if (errno == 0) {
|
||
return Qnil; /* no error, but pathconf has no value */
|
||
} else {
|
||
rb_bug_errno("max path", errno);
|
||
}
|
||
}
|
||
return LONG2NUM(max_path);
|
||
}
|
||
/*
|
||
* call-seq:
|
||
* dir.name_max -> 1024
|
||
*
|
||
* Returns the maximum number of bytes in a file name relative to the
|
||
* directory object on which it is called.
|
||
*/
|
||
static VALUE
|
||
dir_name_max(VALUE dir)
|
||
{
|
||
long max_name;
|
||
struct dir_data *dirp;
|
||
TypedData_Get_Struct(dir, struct dir_data, &dir_data_type, dirp);
|
||
errno = 0;
|
||
max_name = fpathconf(dirfd(dirp->dir), _PC_NAME_MAX);
|
||
if (max_name == -1) {
|
||
if (errno == 0) {
|
||
return Qnil; /* no error, but pathconf has no value */
|
||
} else {
|
||
rb_bug_errno("max name", errno);
|
||
}
|
||
}
|
||
return LONG2NUM(max_name);
|
||
}
|
||
/*
|
||
* Objects of class <code>Dir</code> are directory streams representing
|
||
* directories in the underlying file system. They provide a variety of
|
||
* ways to list directories and their contents. See also
|
||
... | ... | |
rb_define_method(rb_cDir,"initialize", dir_initialize, -1);
|
||
rb_define_method(rb_cDir,"path", dir_path, 0);
|
||
rb_define_method(rb_cDir,"path_max", dir_path_max, 0);
|
||
rb_define_method(rb_cDir,"name_max", dir_name_max, 0);
|
||
rb_define_method(rb_cDir,"to_path", dir_path, 0);
|
||
rb_define_method(rb_cDir,"inspect", dir_inspect, 0);
|
||
rb_define_method(rb_cDir,"read", dir_read, 0);
|
test/ruby/test_dir.rb | ||
---|---|---|
FileUtils.remove_entry_secure @root if File.directory?(@root)
|
||
end
|
||
def test_path_max
|
||
assert_operator Dir.new(@root).path_max, :>, 0
|
||
end
|
||
def test_name_max
|
||
assert_operator Dir.new(@root).name_max, :>, 0
|
||
end
|
||
def test_seek
|
||
dir = Dir.open(@root)
|
||
begin
|