summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-01-29 07:16:09 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-01-29 07:16:09 +0000
commit86298123d748030ec9dcbb64ba3bf86816de9de7 (patch)
tree5071f9d4670df7f8a7ed10355c9bef1a544aa32c /file.c
parente9d17f8a226bcfcf234def5d0ba77fb77a48a534 (diff)
* file.c (rb_stat_rdev_major): added. [new]
* file.c (rb_stat_rdev_minor): added. [new] * file.c (rb_stat_inspect): print mode in octal. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2027 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r--file.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/file.c b/file.c
index e3bc81c..8d6d5e0 100644
--- a/file.c
+++ b/file.c
@@ -211,6 +211,30 @@ rb_stat_rdev(self)
}
static VALUE
+rb_stat_rdev_major(self)
+ VALUE self;
+{
+#if defined(HAVE_ST_RDEV) && defined(major)
+ long rdev = get_stat(self)->st_rdev;
+ return ULONG2NUM(major(rdev));
+#else
+ return INT2FIX(0);
+#endif
+}
+
+static VALUE
+rb_stat_rdev_minor(self)
+ VALUE self;
+{
+#if defined(HAVE_ST_RDEV) && defined(minor)
+ long rdev = get_stat(self)->st_rdev;
+ return ULONG2NUM(minor(rdev));
+#else
+ return INT2FIX(0);
+#endif
+}
+
+static VALUE
rb_stat_size(self)
VALUE self;
{
@@ -290,15 +314,23 @@ rb_stat_inspect(self)
rb_str_buf_cat2(str, " ");
for (i = 0; i < sizeof(member)/sizeof(member[0]); i++) {
- VALUE str2;
+ VALUE v;
if (i > 0) {
rb_str_buf_cat2(str, ", ");
}
rb_str_buf_cat2(str, member[i].name);
rb_str_buf_cat2(str, "=");
- str2 = rb_inspect((*member[i].func)(self));
- rb_str_append(str, str2);
+ v = (*member[i].func)(self);
+ if (i == 2) { /* mode */
+ char buf[32];
+
+ sprintf(buf, "0%o", NUM2INT(v));
+ rb_str_buf_cat2(str, buf);
+ }
+ else {
+ rb_str_append(str, rb_inspect(v));
+ }
}
rb_str_buf_cat2(str, ">");
OBJ_INFECT(str, self);
@@ -2553,6 +2585,8 @@ Init_File()
rb_define_method(rb_cStat, "uid", rb_stat_uid, 0);
rb_define_method(rb_cStat, "gid", rb_stat_gid, 0);
rb_define_method(rb_cStat, "rdev", rb_stat_rdev, 0);
+ rb_define_method(rb_cStat, "rdev_major", rb_stat_rdev_major, 0);
+ rb_define_method(rb_cStat, "rdev_minor", rb_stat_rdev_minor, 0);
rb_define_method(rb_cStat, "size", rb_stat_size, 0);
rb_define_method(rb_cStat, "blksize", rb_stat_blksize, 0);
rb_define_method(rb_cStat, "blocks", rb_stat_blocks, 0);