4static VALUE rb_cPathname;
12static ID id_birthtime;
13static ID id_blockdev_p;
14static ID id_chardev_p;
18static ID id_directory_p;
22static ID id_executable_p;
23static ID id_executable_real_p;
25static ID id_expand_path;
33static ID id_grpowned_p;
45static ID id_readable_p;
46static ID id_readable_real_p;
47static ID id_readlines;
49static ID id_realdirpath;
63static ID id_symlink_p;
69static ID id_world_readable_p;
70static ID id_world_writable_p;
71static ID id_writable_p;
72static ID id_writable_real_p;
109 if (memchr(RSTRING_PTR(str),
'\0', RSTRING_LEN(str)))
110 rb_raise(rb_eArgError,
"pathname contains null byte");
113 set_strpath(self, str);
126path_freeze(
VALUE self)
143 return rb_str_equal(get_strpath(self), get_strpath(other));
168 s1 = get_strpath(self);
169 s2 = get_strpath(other);
170 p1 = RSTRING_PTR(s1);
171 p2 = RSTRING_PTR(s2);
172 e1 = p1 + RSTRING_LEN(s1);
173 e2 = p2 + RSTRING_LEN(s2);
174 while (p1 < e1 && p2 < e2) {
176 c1 = (
unsigned char)*p1++;
177 c2 = (
unsigned char)*p2++;
178 if (c1 ==
'/') c1 =
'\0';
179 if (c2 ==
'/') c2 =
'\0';
195#define ST2FIX(h) LONG2FIX((long)(h))
222path_inspect(
VALUE self)
225 VALUE str = get_strpath(self);
226 return rb_sprintf(
"#<%s:%"PRIsVALUE
">", c, str);
239 VALUE str = get_strpath(self);
245 str = rb_funcallv(str, id_sub, argc, argv);
261 VALUE str = get_strpath(self);
268 p = RSTRING_PTR(str);
269 extlen = RSTRING_LEN(str);
270 ext = ruby_enc_find_extname(p, &extlen, rb_enc_get(str));
272 ext = p + RSTRING_LEN(str);
274 else if (extlen <= 1) {
295path_realpath(
int argc,
VALUE *argv,
VALUE self)
311path_realdirpath(
int argc,
VALUE *argv,
VALUE self)
330path_each_line(
int argc,
VALUE *argv,
VALUE self)
335 args[0] = get_strpath(self);
336 n =
rb_scan_args(argc, argv,
"03", &args[1], &args[2], &args[3]);
361 args[0] = get_strpath(self);
362 n =
rb_scan_args(argc, argv,
"03", &args[1], &args[2], &args[3]);
376path_binread(
int argc,
VALUE *argv,
VALUE self)
381 args[0] = get_strpath(self);
383 return rb_funcallv(
rb_cFile, id_binread, 1+n, args);
402 args[0] = get_strpath(self);
403 n =
rb_scan_args(argc, argv,
"03", &args[1], &args[2], &args[3]);
418path_binwrite(
int argc,
VALUE *argv,
VALUE self)
423 args[0] = get_strpath(self);
424 n =
rb_scan_args(argc, argv,
"03", &args[1], &args[2], &args[3]);
440path_readlines(
int argc,
VALUE *argv,
VALUE self)
445 args[0] = get_strpath(self);
446 n =
rb_scan_args(argc, argv,
"03", &args[1], &args[2], &args[3]);
458path_sysopen(
int argc,
VALUE *argv,
VALUE self)
463 args[0] = get_strpath(self);
465 return rb_funcallv(
rb_cIO, id_sysopen, 1+n, args);
477path_atime(
VALUE self)
492path_birthtime(
VALUE self)
506path_ctime(
VALUE self)
520path_mtime(
VALUE self)
591path_fnmatch(
int argc,
VALUE *argv,
VALUE self)
593 VALUE str = get_strpath(self);
594 VALUE pattern, flags;
595 if (
rb_scan_args(argc, argv,
"11", &pattern, &flags) == 1)
610path_ftype(
VALUE self)
647 args[0] = get_strpath(self);
648 n =
rb_scan_args(argc, argv,
"03", &args[1], &args[2], &args[3]);
663path_readlink(
VALUE self)
696path_lstat(
VALUE self)
756path_basename(
int argc,
VALUE *argv,
VALUE self)
758 VALUE str = get_strpath(self);
773path_dirname(
VALUE self)
775 VALUE str = get_strpath(self);
786path_extname(
VALUE self)
788 VALUE str = get_strpath(self);
798path_expand_path(
int argc,
VALUE *argv,
VALUE self)
800 VALUE str = get_strpath(self);
815path_split(
VALUE self)
817 VALUE str = get_strpath(self);
818 VALUE ary, dirname, basename;
832path_blockdev_p(
VALUE self)
841path_chardev_p(
VALUE self)
850path_executable_p(
VALUE self)
859path_executable_real_p(
VALUE self)
868path_exist_p(
VALUE self)
877path_grpowned_p(
VALUE self)
886path_directory_p(
VALUE self)
895path_file_p(
VALUE self)
904path_pipe_p(
VALUE self)
913path_socket_p(
VALUE self)
922path_owned_p(
VALUE self)
931path_readable_p(
VALUE self)
940path_world_readable_p(
VALUE self)
949path_readable_real_p(
VALUE self)
958path_setuid_p(
VALUE self)
967path_setgid_p(
VALUE self)
985path_size_p(
VALUE self)
994path_sticky_p(
VALUE self)
1003path_symlink_p(
VALUE self)
1012path_writable_p(
VALUE self)
1021path_world_writable_p(
VALUE self)
1030path_writable_real_p(
VALUE self)
1039path_zero_p(
VALUE self)
1050path_empty_p(
VALUE self)
1053 VALUE path = get_strpath(self);
1075path_s_glob(
int argc,
VALUE *argv,
VALUE klass)
1080 n =
rb_scan_args(argc, argv,
"12", &args[0], &args[1], &args[2]);
1120 n =
rb_scan_args(argc, argv,
"11", &args[0], &args[1]);
1124 args[2] = rb_hash_new();
1125 rb_hash_aset(args[2],
ID2SYM(id_base), get_strpath(self));
1155path_s_getwd(
VALUE klass)
1189path_entries(
VALUE self)
1191 VALUE klass, str, ary;
1194 str = get_strpath(self);
1213 VALUE str = get_strpath(self);
1227path_rmdir(
VALUE self)
1238path_opendir(
VALUE self)
1242 args[0] = get_strpath(self);
1257path_each_entry(
VALUE self)
1262 args[0] = get_strpath(self);
1267unlink_body(
VALUE str)
1283path_unlink(
VALUE self)
1286 VALUE str = get_strpath(self);
1287 return rb_rescue2(unlink_body, str, unlink_rescue, str, eENOTDIR, (
VALUE)0);
1314#include "pathname_builtin.rbinc"
1316static void init_ids(
void);
1504#ifdef HAVE_RB_EXT_RACTOR_SAFE
1513InitVM_pathname(
void)
1566 rb_define_method(rb_cPathname,
"executable_real?", path_executable_real_p, 0);
1575 rb_define_method(rb_cPathname,
"world_readable?", path_world_readable_p, 0);
1584 rb_define_method(rb_cPathname,
"world_writable?", path_world_writable_p, 0);
1609 id_at_path = rb_intern(
"@path");
1610 id_to_path = rb_intern(
"to_path");
1611 id_ENOTDIR = rb_intern(
"ENOTDIR");
1612 id_atime = rb_intern(
"atime");
1613 id_basename = rb_intern(
"basename");
1614 id_base = rb_intern(
"base");
1615 id_binread = rb_intern(
"binread");
1616 id_binwrite = rb_intern(
"binwrite");
1617 id_birthtime = rb_intern(
"birthtime");
1618 id_blockdev_p = rb_intern(
"blockdev?");
1619 id_chardev_p = rb_intern(
"chardev?");
1620 id_chmod = rb_intern(
"chmod");
1621 id_chown = rb_intern(
"chown");
1622 id_ctime = rb_intern(
"ctime");
1623 id_directory_p = rb_intern(
"directory?");
1624 id_dirname = rb_intern(
"dirname");
1625 id_empty_p = rb_intern(
"empty?");
1626 id_entries = rb_intern(
"entries");
1627 id_executable_p = rb_intern(
"executable?");
1628 id_executable_real_p = rb_intern(
"executable_real?");
1629 id_exist_p = rb_intern(
"exist?");
1630 id_expand_path = rb_intern(
"expand_path");
1631 id_extname = rb_intern(
"extname");
1632 id_file_p = rb_intern(
"file?");
1633 id_fnmatch = rb_intern(
"fnmatch");
1634 id_foreach = rb_intern(
"foreach");
1635 id_ftype = rb_intern(
"ftype");
1636 id_getwd = rb_intern(
"getwd");
1637 id_glob = rb_intern(
"glob");
1638 id_grpowned_p = rb_intern(
"grpowned?");
1639 id_lchmod = rb_intern(
"lchmod");
1640 id_lchown = rb_intern(
"lchown");
1641 id_link = rb_intern(
"link");
1642 id_lstat = rb_intern(
"lstat");
1643 id_lutime = rb_intern(
"lutime");
1644 id_mkdir = rb_intern(
"mkdir");
1645 id_mtime = rb_intern(
"mtime");
1646 id_open = rb_intern(
"open");
1647 id_owned_p = rb_intern(
"owned?");
1648 id_pipe_p = rb_intern(
"pipe?");
1649 id_read = rb_intern(
"read");
1650 id_readable_p = rb_intern(
"readable?");
1651 id_readable_real_p = rb_intern(
"readable_real?");
1652 id_readlines = rb_intern(
"readlines");
1653 id_readlink = rb_intern(
"readlink");
1654 id_realdirpath = rb_intern(
"realdirpath");
1655 id_realpath = rb_intern(
"realpath");
1656 id_rename = rb_intern(
"rename");
1657 id_rmdir = rb_intern(
"rmdir");
1658 id_setgid_p = rb_intern(
"setgid?");
1659 id_setuid_p = rb_intern(
"setuid?");
1660 id_size = rb_intern(
"size");
1661 id_size_p = rb_intern(
"size?");
1662 id_socket_p = rb_intern(
"socket?");
1663 id_split = rb_intern(
"split");
1664 id_stat = rb_intern(
"stat");
1665 id_sticky_p = rb_intern(
"sticky?");
1666 id_sub = rb_intern(
"sub");
1667 id_symlink = rb_intern(
"symlink");
1668 id_symlink_p = rb_intern(
"symlink?");
1669 id_sysopen = rb_intern(
"sysopen");
1670 id_truncate = rb_intern(
"truncate");
1671 id_unlink = rb_intern(
"unlink");
1672 id_utime = rb_intern(
"utime");
1673 id_world_readable_p = rb_intern(
"world_readable?");
1674 id_world_writable_p = rb_intern(
"world_writable?");
1675 id_writable_p = rb_intern(
"writable?");
1676 id_writable_real_p = rb_intern(
"writable_real?");
1677 id_write = rb_intern(
"write");
1678 id_zero_p = rb_intern(
"zero?");
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
#define rb_define_global_function(mid, func, arity)
Defines rb_mKernel #mid.
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
void rb_undef_method(VALUE klass, const char *name)
Defines an undef of a method.
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Retrieves argument from argc and argv to given VALUE references according to the format string.
int rb_block_given_p(void)
Determines if the current method is given a block.
#define T_STRING
Old name of RUBY_T_STRING.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define ID2SYM
Old name of RB_ID2SYM.
#define CLASS_OF
Old name of rb_class_of.
#define rb_ary_new3
Old name of rb_ary_new_from_args.
#define ST2FIX
Old name of RB_ST2FIX.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
VALUE rb_mErrno
Errno module.
VALUE rb_eTypeError
TypeError exception.
VALUE rb_convert_type(VALUE val, int type, const char *name, const char *mid)
Converts an object into another type.
VALUE rb_class_new_instance(int argc, const VALUE *argv, VALUE klass)
Allocates, then initialises an instance of the given class.
VALUE rb_obj_class(VALUE obj)
Queries the class of an object.
VALUE rb_obj_dup(VALUE obj)
Duplicates the given object.
VALUE rb_mFileTest
FileTest module.
VALUE rb_obj_is_kind_of(VALUE obj, VALUE klass)
Queries if the given object is an instance (of possibly descendants) of the given class.
VALUE rb_cFile
File class.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
VALUE rb_funcallv_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
Identical to rb_funcallv(), except you can specify how to handle the last element of the given array.
VALUE rb_call_super(int argc, const VALUE *argv)
This resembles ruby's super.
VALUE rb_ary_entry(VALUE ary, long off)
Queries an element of an array.
void rb_ary_store(VALUE ary, long key, VALUE val)
Destructively stores the passed value to the passed array's passed index.
#define RETURN_ENUMERATOR(obj, argc, argv)
Identical to RETURN_SIZED_ENUMERATOR(), except its size is unknown.
void rb_provide(const char *feature)
Declares that the given feature is already provided by someone else.
void rb_ext_ractor_safe(bool flag)
Asserts that the extension library that calls this function is aware of Ractor.
VALUE rb_str_append(VALUE dst, VALUE src)
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating.
VALUE rb_str_subseq(VALUE str, long beg, long len)
Identical to rb_str_substr(), except the numbers are interpreted as byte offsets instead of character...
st_index_t rb_str_hash(VALUE str)
Calculates a hash value of a string.
VALUE rb_str_equal(VALUE str1, VALUE str2)
Equality of two strings.
VALUE rb_str_freeze(VALUE str)
This is the implementation of String#freeze.
VALUE rb_ivar_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
VALUE rb_ivar_get(VALUE obj, ID name)
Identical to rb_iv_get(), except it accepts the name as an ID instead of a C string.
VALUE rb_const_get_at(VALUE space, ID name)
Identical to rb_const_defined_at(), except it returns the actual defined value.
VALUE rb_check_funcall(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcallv(), except it returns RUBY_Qundef instead of raising rb_eNoMethodError.
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
Shim for block function parameters.
VALUE rb_yield(VALUE val)
Yields the block.
VALUE rb_block_call_kw(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t proc, VALUE data2, int kw_splat)
Identical to rb_funcallv_kw(), except it additionally passes a function as a block.
VALUE rb_block_call(VALUE q, ID w, int e, const VALUE *r, type *t, VALUE y)
Call a method with a block.
VALUE rb_rescue2(type *q, VALUE w, type *e, VALUE r,...)
An equivalent of rescue clause.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY_AREF(a, i)
#define StringValue(v)
Ensures that the parameter object is a String.
const char * rb_obj_classname(VALUE obj)
Queries the name of the class of the passed object.
#define InitVM(ext)
This macro is for internal use.
#define RB_PASS_KEYWORDS
Pass keywords, final argument should be a hash of keywords.
#define RB_PASS_CALLED_KEYWORDS
Pass keywords if current method is called with keywords, useful for argument delegation.
#define RTEST
This is an old name of RB_TEST.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static void Check_Type(VALUE v, enum ruby_value_type t)
Identical to RB_TYPE_P(), except it raises exceptions on predication failure.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.