Hi,
In message "Help wanted for statvfs extension"
on 02/04/17, Daniel Berger <djberg96 / hotmail.com> writes:
|/*****************************
| Statvfs.c
|
| $Author: djberg96 $
| $Date: 2002/04/15 12:00:00 $
|
|******************************/
|
|#include "ruby.h"
|#include <sys/statvfs.h>
|
|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.
| 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".
| 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.
matz.