[macruby-changes] [1756] MacRuby/branches/experimental/file.c

source_changes at macosforge.org source_changes at macosforge.org
Fri Jun 5 16:23:11 PDT 2009


Revision: 1756
          http://trac.macosforge.org/projects/ruby/changeset/1756
Author:   lsansonetti at apple.com
Date:     2009-06-05 16:23:11 -0700 (Fri, 05 Jun 2009)
Log Message:
-----------
implemented File#chown

Modified Paths:
--------------
    MacRuby/branches/experimental/file.c

Modified: MacRuby/branches/experimental/file.c
===================================================================
--- MacRuby/branches/experimental/file.c	2009-06-05 23:18:43 UTC (rev 1755)
+++ MacRuby/branches/experimental/file.c	2009-06-05 23:23:11 UTC (rev 1756)
@@ -1954,24 +1954,17 @@
 static VALUE
 rb_file_chown(VALUE obj, SEL sel, VALUE owner, VALUE group)
 {
-//     rb_io_t *fptr;
-//     int o, g;
-// 
-//     rb_secure(2);
-//     o = NIL_P(owner) ? -1 : NUM2INT(owner);
-//     g = NIL_P(group) ? -1 : NUM2INT(group);
-//     GetOpenFile(obj, fptr);
-// #if defined(DJGPP) || defined(__CYGWIN32__) || defined(_WIN32) || defined(__EMX__)
-//     if (!fptr->path) return Qnil;
-//     if (chown(fptr->path, o, g) == -1)
-//  rb_sys_fail(fptr->path);
-// #else
-//     if (fchown(fptr->fd, o, g) == -1)
-//  rb_sys_fail(fptr->path);
-// #endif
-    
-//    return INT2FIX(0);
-    rb_notimplement();
+    rb_secure(2);
+
+    const int o = NIL_P(owner) ? -1 : NUM2INT(owner);
+    const int g = NIL_P(group) ? -1 : NUM2INT(group);
+    rb_io_t *io_struct = ExtractIOStruct(obj);
+
+    if (fchown(io_struct->fd, o, g) == -1) {
+	rb_sys_fail(RSTRING_PTR(io_struct->path));
+    }
+
+    return INT2FIX(0);
 }
 
 #if defined(HAVE_LCHOWN) && !defined(__CHECKER__)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090605/75051a81/attachment.html>


More information about the macruby-changes mailing list