From: djberg96@... (Daniel Berger) Date: 2002-04-17T22:25:37+09:00 Subject: Re: Help wanted for statvfs extension matz@ruby-lang.org (Yukihiro Matsumoto) wrote in message news:<1019001849.539148.32628.nullmailer@picachu.netlab.jp>... > Hi, > > In message "Help wanted for statvfs extension" > on 02/04/17, Daniel Berger writes: > > |/***************************** > | Statvfs.c > | > | $Author: djberg96 $ > | $Date: 2002/04/15 12:00:00 $ > | > |******************************/ > | > |#include "ruby.h" > |#include > | > |VALUE info; > > I think this variable should not be global. Just local variable to > the function statvfs_new(). > > |VALUE statvfs_new(VALUE class) > |{ > | statvfs_t *p; > | p = ALLOC(statvfs_t); > | info = Data_Wrap_Struct(class,0,free,p); > > No problem here, but you can use Data_Make_Struct() also for this > purpose. Oh, thanks. I think I made a portability mistake here, though. statvfs_t is the name of the statvfs struct in statvfs.h on Solaris. It doesn't necessarily have that name in other flavors of Unix (e.g. it didn't have a name under Mandrake). So, I'll just replace "statvfs_t *p" with "struct statvfs *p". > > | return info; > |} > | > |VALUE statvfs_favail(VALUE self, VALUE dir) > |{ > | statvfs_t *p; > | int favail; > | > | Data_Get_Struct(self,statvfs_t,p); > | statvfs(STR2CSTR(dir),p); > | favail = p->f_favail; > | return rb_int_new(favail); > |} > | > |static VALUE mStatvfs; > |VALUE cStatvfs; > > It's OK to make this variable "static". > > |void Init_statvfs() > |{ > | mStatvfs = rb_define_module("statvfs"); > > You don't need to define this "module". Oh? Will the module name simply be the same as the .c file by default? > > | cStatvfs = rb_define_class("Statvfs",rb_cObject); > | > | rb_define_singleton_method(cStatvfs,"new",statvfs_new,0); > | rb_define_method(cStatvfs,"favail",statvfs_favail,1); > |} > > Hope this helps. Yes, thanks. Now, if I can decipher Nobu Nokada's first message, I'll be good. :) Regards, Dan