Module: Bug::File::Stat

Defined in:
ext/-test-/file/stat.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_fd(fileno) ⇒ Object



4
5
6
7
8
9
10
# File 'ext/-test-/file/stat.c', line 4

static VALUE
stat_for_fd(VALUE self, VALUE fileno)
{
    struct stat st;
    if (fstat(NUM2INT(fileno), &st)) rb_sys_fail(0);
    return rb_stat_new(&st);
}

.for_path(path) ⇒ Object



12
13
14
15
16
17
18
19
# File 'ext/-test-/file/stat.c', line 12

static VALUE
stat_for_path(VALUE self, VALUE path)
{
    struct stat st;
    FilePathValue(path);
    if (stat(RSTRING_PTR(path), &st)) rb_sys_fail(0);
    return rb_stat_new(&st);
}

Instance Method Details

#[](key) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'ext/-test-/st/numhash/numhash.c', line 38

static VALUE
numhash_aref(VALUE self, VALUE key)
{
    st_data_t data;
    st_table *tbl = (st_table *)Check_TypedStruct(self, &numhash_type);
    if (!SPECIAL_CONST_P(key)) rb_raise(rb_eArgError, "not a special const");
    if (st_lookup(tbl, (st_data_t)key, &data))
        return (VALUE)data;
    return Qnil;
}

#[]=(key, data) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'ext/-test-/st/numhash/numhash.c', line 49

static VALUE
numhash_aset(VALUE self, VALUE key, VALUE data)
{
    st_table *tbl = (st_table *)Check_TypedStruct(self, &numhash_type);
    if (!SPECIAL_CONST_P(key)) rb_raise(rb_eArgError, "not a special const");
    if (!SPECIAL_CONST_P(data)) rb_raise(rb_eArgError, "not a special const");
    st_insert(tbl, (st_data_t)key, (st_data_t)data);
    return self;
}

#delete_safe(key) ⇒ Object



114
115
116
117
118
119
120
121
122
123
# File 'ext/-test-/st/numhash/numhash.c', line 114

static VALUE
numhash_delete_safe(VALUE self, VALUE key)
{
    st_table *table = (st_table *)Check_TypedStruct(self, &numhash_type);
    st_data_t val, k = (st_data_t)key;
    if (st_delete_safe(table, &k, &val, (st_data_t)self)) {
        return val;
    }
    return Qnil;
}

#eachObject



68
69
70
71
72
73
74
# File 'ext/-test-/st/numhash/numhash.c', line 68

static VALUE
numhash_each(VALUE self)
{
    st_table *table = (st_table *)Check_TypedStruct(self, &numhash_type);
    st_data_t data = (st_data_t)self;
    return st_foreach_check(table, numhash_i, data, data) ? Qtrue : Qfalse;
}

#initializeObject



29
30
31
32
33
34
35
36
# File 'ext/-test-/st/numhash/numhash.c', line 29

static VALUE
numhash_init(VALUE self)
{
    st_table *tbl = (st_table *)Check_TypedStruct(self, &numhash_type);
    if (tbl) st_free_table(tbl);
    DATA_PTR(self) = st_init_numtable();
    return self;
}

#sizeObject



107
108
109
110
111
112
# File 'ext/-test-/st/numhash/numhash.c', line 107

static VALUE
numhash_size(VALUE self)
{
    st_table *table = (st_table *)Check_TypedStruct(self, &numhash_type);
    return ST2NUM(table->num_entries);
}

#st_update(key) ⇒ Object



19
20
21
22
23
24
25
26
# File 'ext/-test-/st/update/update.c', line 19

static VALUE
test_st_update(VALUE self, VALUE key)
{
    if (st_update(RHASH_TBL(self), (st_data_t)key, update_func, 0))
        return Qtrue;
    else
        return Qfalse;
}

#update(key) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'ext/-test-/st/numhash/numhash.c', line 91

static VALUE
numhash_update(VALUE self, VALUE key)
{
    st_table *table = (st_table *)Check_TypedStruct(self, &numhash_type);
    if (st_update(table, (st_data_t)key, update_func, 0))
        return Qtrue;
    else
        return Qfalse;
}