readlink(p1)
public
Returns the name of the file referenced by the given link. Not available on all platforms.
File.symlink("testfile", "link2test")
File.readlink("link2test")
Show source
static VALUE
rb_file_s_readlink(VALUE klass, VALUE path)
{
char *buf;
int size = 100;
int rv;
VALUE v;
rb_secure(2);
FilePathValue(path);
buf = xmalloc(size);
while ((rv = readlink(RSTRING_PTR(path), buf, size)) == size
|| (rv < 0 && errno == ERANGE) /* quirky behavior of GPFS */
#endif
) {
size *= 2;
buf = xrealloc(buf, size);
}
if (rv < 0) {
xfree(buf);
rb_sys_fail_path(path);
}
v = rb_tainted_str_new(buf, rv);
xfree(buf);
return v;
#else
rb_notimplement();
return Qnil; /* not reached */
#endif
}