summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-02-16 07:53:21 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-02-16 07:53:21 +0000
commite1c29a3f13a8d5ca0f9a4e491a752c73aca1d721 (patch)
tree6aa26039a5949f42bd879914ef2f124c5144a392 /file.c
parent9ac8f70f3da942e8a1bc6cadc87cbeaaec2bf44f (diff)
* io.c (set_outfile): f should be the FILE* from the assigning value.
* ext/socket/socket.c (tcp_s_open): should not give default value to local_host. * time.c (time_s_times): move to Process::times. * file.c (rb_file_s_lchmod): new method File::lchmod. * file.c (rb_file_s_lchown): new method File::lchown. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r--file.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/file.c b/file.c
index 749eb06..c4e6781 100644
--- a/file.c
+++ b/file.c
@@ -951,6 +951,42 @@ rb_file_chmod(obj, vmode)
return INT2FIX(0);
}
+#if defined(HAVE_LCHMOD)
+static void
+lchmod_internal(path, mode)
+ const char *path;
+ int mode;
+{
+ if (lchmod(path, mode) == -1)
+ rb_sys_fail(path);
+}
+
+static VALUE
+rb_file_s_lchmod(argc, argv)
+ int argc;
+ VALUE *argv;
+{
+ VALUE vmode;
+ VALUE rest;
+ int mode, n;
+
+ rb_secure(2);
+ rb_scan_args(argc, argv, "1*", &vmode, &rest);
+ mode = NUM2INT(vmode);
+
+ n = apply2files(lchmod_internal, rest, mode);
+ return INT2FIX(n);
+}
+#else
+static VALUE
+rb_file_s_lchmod(argc, argv)
+ int argc;
+ VALUE *argv;
+{
+ rb_notimplement();
+}
+#endif
+
struct chown_args {
int owner, group;
};
@@ -1012,6 +1048,53 @@ rb_file_chown(obj, owner, group)
return INT2FIX(0);
}
+#if defined(HAVE_LCHOWN)
+static void
+lchown_internal(path, args)
+ const char *path;
+ struct chown_args *args;
+{
+ if (lchown(path, args->owner, args->group) < 0)
+ rb_sys_fail(path);
+}
+
+static VALUE
+rb_file_s_lchown(argc, argv)
+ int argc;
+ VALUE *argv;
+{
+ VALUE o, g, rest;
+ struct chown_args arg;
+ int n;
+
+ rb_secure(2);
+ rb_scan_args(argc, argv, "2*", &o, &g, &rest);
+ if (NIL_P(o)) {
+ arg.owner = -1;
+ }
+ else {
+ arg.owner = NUM2INT(o);
+ }
+ if (NIL_P(g)) {
+ arg.group = -1;
+ }
+ else {
+ arg.group = NUM2INT(g);
+ }
+
+ n = apply2files(lchown_internal, rest, &arg);
+ return INT2FIX(n);
+}
+#else
+static VALUE
+rb_file_s_lchown(argc, argv)
+ int argc;
+ VALUE *argv;
+{
+ rb_notimplement();
+}
+#endif
+
struct timeval rb_time_timeval();
#if defined(HAVE_UTIMES) && !defined(__CHECKER__)
@@ -2206,6 +2289,8 @@ Init_File()
rb_define_singleton_method(rb_cFile, "utime", rb_file_s_utime, -1);
rb_define_singleton_method(rb_cFile, "chmod", rb_file_s_chmod, -1);
rb_define_singleton_method(rb_cFile, "chown", rb_file_s_chown, -1);
+ rb_define_singleton_method(rb_cFile, "lchmod", rb_file_s_lchmod, -1);
+ rb_define_singleton_method(rb_cFile, "lchown", rb_file_s_lchown, -1);
rb_define_singleton_method(rb_cFile, "link", rb_file_s_link, 2);
rb_define_singleton_method(rb_cFile, "symlink", rb_file_s_symlink, 2);