linux_stat 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2aa2fadafde1932205250a8c9ac30d823a9eadab17bb13ae9f5a49a2217f773
4
- data.tar.gz: '080da5da8cb063f1be4811cffb1d81fea4db65816435fc2351dc030588dedd2a'
3
+ metadata.gz: f81f89f0e4f50ff1565a5b6dba272c9ac6fab336a4e3c72888355f199fd216e1
4
+ data.tar.gz: e3d4daabdcacdfa1d54bf899dc5c98b5fc3354ecaee3ead4bfa546462d64cfb2
5
5
  SHA512:
6
- metadata.gz: fb8800524cb7d515c9a2505ad5a02f6a0f9696746960e99d8ee209d7714e756d43770156526e8996be39524722c24065316dfee74240b650376bff7825c6e69d
7
- data.tar.gz: cf5795f0e99c58948a0ce3b185d24de576c3f2172326164f280370ef842145423d39dfc25358cd0f79d3a5a7c571a4f566e4c8bf42a406ea09d643633d498b6e
6
+ metadata.gz: 2d8ed40932920cc10ef10a083b2be1d5bad58dfba658f0b14643826e258f4fdc6f5e89aaac1a711e3fbf674feae7d2e9be777608d02c1ab30df4621d56768ee1
7
+ data.tar.gz: 2fc069a7134118010affd0354aa7bde2615f8183cf7a8b7defd42342084b3f6a7bf0a5e5774e78aa262302b259dc16c542c06f46d1642e8e3376be308343a93e
@@ -1,25 +1,27 @@
1
- static VALUE getDiskStats (volatile VALUE obj, volatile VALUE path) {
2
- FILE *file = fopen("/proc/diskstats", "r") ;
3
- if(!file) return rb_ary_new() ;
1
+ static VALUE getDiskStats (VALUE obj, VALUE path) {
2
+ FILE *file = fopen("/proc/diskstats", "r");
3
+ if(!file) return rb_ary_new();
4
4
 
5
- char lines[120] ;
6
- unsigned long long read, write ;
7
- char *p = StringValuePtr(path) ;
5
+ char lines[120];
6
+ unsigned long long read, write;
7
+ char *p = StringValuePtr(path);
8
8
 
9
- while(fgets(lines, 119, file)) {
10
- sscanf(lines, "%*s %*s %s %*s %*s %llu %*s %*s %*s %llu", lines, &read, &write) ;
9
+ while (fgets(lines, sizeof(lines) - 1, file)) {
10
+ if (sscanf(lines, "%*s %*s %119s %*s %*s %llu %*s %*s %*s %llu", lines, &read, &write) == 3) {
11
+ if(strcmp(lines, p) == 0) {
12
+ fclose(file);
11
13
 
12
- if(strcmp(lines, p) == 0) {
13
- fclose(file) ;
14
-
15
- return rb_ary_new_from_args(
16
- 2,
17
- ULL2NUM(read),
18
- ULL2NUM(write)
19
- ) ;
14
+ return rb_ary_new_from_args(
15
+ 2,
16
+ ULL2NUM(read),
17
+ ULL2NUM(write)
18
+ );
19
+ }
20
+ } else {
21
+ return rb_ary_new();
20
22
  }
21
23
  }
22
24
 
23
- fclose(file) ;
24
- return rb_ary_new() ;
25
+ fclose(file);
26
+ return rb_ary_new();
25
27
  }
@@ -9,4 +9,6 @@ unless have_header('sys/statvfs.h') && have_header('sys/ioctl.h') &&
9
9
  abort('Missing header')
10
10
  end
11
11
 
12
+ $CFLAGS << ' -O3 -march=native -mtune=native'
13
+
12
14
  create_makefile 'linux_stat/fs_stat'
@@ -8,41 +8,31 @@
8
8
  #include "sector_size.h"
9
9
  #include "disk_stat.h"
10
10
 
11
- #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
12
- #pragma GCC optimize ("O3")
13
- #pragma GCC diagnostic warning "-Wall"
14
- #elif defined(__clang__)
15
- #pragma clang optimize on
16
- #pragma clang diagnostic warning "-Wall"
17
- #elif defined(__INTEL_COMPILER)
18
- #pragma intel optimization_level 3
19
- #endif
11
+ static VALUE statfs(VALUE obj, VALUE dir) {
12
+ struct statvfs buf;
13
+ char *d = StringValuePtr(dir);
14
+ VALUE hash = rb_hash_new();
20
15
 
21
- static VALUE statfs(volatile VALUE obj, volatile VALUE dir) {
22
- struct statvfs buf ;
23
- char *d = StringValuePtr(dir) ;
24
- VALUE hash = rb_hash_new() ;
16
+ if(statvfs(d, &buf) < 0) return hash;
25
17
 
26
- if(statvfs(d, &buf) < 0) return hash ;
18
+ rb_hash_aset(hash, ID2SYM(rb_intern("block_size")), INT2FIX((unsigned int)buf.f_bsize));
19
+ rb_hash_aset(hash, ID2SYM(rb_intern("fragment_size")), ULL2NUM((unsigned long long)buf.f_frsize));
20
+ rb_hash_aset(hash, ID2SYM(rb_intern("blocks")), ULL2NUM((unsigned long long)buf.f_blocks));
21
+ rb_hash_aset(hash, ID2SYM(rb_intern("block_free")), ULL2NUM((unsigned long long)buf.f_bfree));
22
+ rb_hash_aset(hash, ID2SYM(rb_intern("block_avail_unpriv")), ULL2NUM((unsigned long long)buf.f_bavail));
23
+ rb_hash_aset(hash, ID2SYM(rb_intern("inodes")), ULL2NUM((unsigned long long)buf.f_files));
24
+ rb_hash_aset(hash, ID2SYM(rb_intern("free_inodes")), ULL2NUM((unsigned long long)buf.f_ffree));
25
+ rb_hash_aset(hash, ID2SYM(rb_intern("filesystem_id")), ULL2NUM((unsigned long long)buf.f_fsid));
26
+ rb_hash_aset(hash, ID2SYM(rb_intern("mount_flags")), ULL2NUM((unsigned long long)buf.f_flag));
27
+ rb_hash_aset(hash, ID2SYM(rb_intern("max_filename_length")), ULL2NUM((unsigned long long)buf.f_namemax));
27
28
 
28
- rb_hash_aset(hash, ID2SYM(rb_intern("block_size")), INT2FIX((unsigned int)buf.f_bsize)) ;
29
- rb_hash_aset(hash, ID2SYM(rb_intern("fragment_size")), ULL2NUM((unsigned long long)buf.f_frsize)) ;
30
- rb_hash_aset(hash, ID2SYM(rb_intern("blocks")), ULL2NUM((unsigned long long)buf.f_blocks)) ;
31
- rb_hash_aset(hash, ID2SYM(rb_intern("block_free")), ULL2NUM((unsigned long long)buf.f_bfree)) ;
32
- rb_hash_aset(hash, ID2SYM(rb_intern("block_avail_unpriv")), ULL2NUM((unsigned long long)buf.f_bavail)) ;
33
- rb_hash_aset(hash, ID2SYM(rb_intern("inodes")), ULL2NUM((unsigned long long)buf.f_files)) ;
34
- rb_hash_aset(hash, ID2SYM(rb_intern("free_inodes")), ULL2NUM((unsigned long long)buf.f_ffree)) ;
35
- rb_hash_aset(hash, ID2SYM(rb_intern("filesystem_id")), ULL2NUM((unsigned long long)buf.f_fsid)) ;
36
- rb_hash_aset(hash, ID2SYM(rb_intern("mount_flags")), ULL2NUM((unsigned long long)buf.f_flag)) ;
37
- rb_hash_aset(hash, ID2SYM(rb_intern("max_filename_length")), ULL2NUM((unsigned long long)buf.f_namemax)) ;
38
-
39
- return hash ;
29
+ return hash;
40
30
  }
41
31
 
42
32
  void Init_fs_stat() {
43
- VALUE _linux_stat = rb_define_module("LinuxStat") ;
44
- VALUE fs = rb_define_module_under(_linux_stat, "FS") ;
45
- rb_define_module_function(fs, "stat", statfs, 1) ;
46
- rb_define_module_function(fs, "sectors", getSectorSize, 1) ;
47
- rb_define_module_function(fs, "total_io", getDiskStats, 1) ;
33
+ VALUE _linux_stat = rb_define_module("LinuxStat");
34
+ VALUE fs = rb_define_module_under(_linux_stat, "FS");
35
+ rb_define_module_function(fs, "stat", statfs, 1);
36
+ rb_define_module_function(fs, "sectors", getSectorSize, 1);
37
+ rb_define_module_function(fs, "total_io", getDiskStats, 1);
48
38
  }
@@ -1,13 +1,13 @@
1
- static VALUE getSectorSize(volatile VALUE obj, volatile VALUE path) {
2
- char *dev = StringValuePtr(path) ;
1
+ static VALUE getSectorSize(VALUE obj, VALUE path) {
2
+ char *dev = StringValuePtr(path);
3
3
 
4
- unsigned int fd = open(dev, O_RDONLY | O_NONBLOCK) ;
5
- if(fd < 0) return Qnil ;
4
+ unsigned int fd = open(dev, O_RDONLY | O_NONBLOCK);
5
+ if(fd < 0) return Qnil;
6
6
 
7
- unsigned int sSize = 0 ;
8
- short status = ioctl(fd, BLKSSZGET, &sSize) ;
9
- close(fd) ;
10
- if(status < 0) return Qnil ;
7
+ unsigned int sSize = 0;
8
+ short status = ioctl(fd, BLKSSZGET, &sSize);
9
+ close(fd);
10
+ if(status < 0) return Qnil;
11
11
 
12
- return UINT2NUM(sSize) ;
12
+ return UINT2NUM(sSize);
13
13
  }
@@ -1,2 +1,5 @@
1
1
  require 'mkmf'
2
+
3
+ $CFLAGS << ' -O3 -march=native -mtune=native'
4
+
2
5
  create_makefile 'linux_stat/misc/integer'
@@ -12,52 +12,44 @@
12
12
  - It doesn't raise any error. Handing nil is enough to indicate that it failed.
13
13
  */
14
14
 
15
- #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
16
- #pragma GCC optimize ("O3")
17
- #pragma GCC diagnostic warning "-Wall"
18
- #elif defined(__clang__)
19
- #pragma clang optimize on
20
- #pragma clang diagnostic warning "-Wall"
21
- #elif defined(__INTEL_COMPILER)
22
- #pragma intel optimization_level 3
23
- #endif
24
-
25
15
  #include <limits.h>
26
16
  #include "ruby.h"
27
17
 
28
- VALUE isNumber(volatile VALUE obj, volatile VALUE val) {
29
- // But we don't expect anything other than String though as Argument.
30
- // Note that raising ArgumentError or any kind of Error shouldn't be done here
31
- // Otherwise Integer(n) is the best method in Ruby.
18
+ VALUE isNumber(VALUE obj, VALUE val) {
19
+ // Expecting a String as input, return Qnil for any other type
32
20
  if (!RB_TYPE_P(val, T_STRING))
33
- return Qnil ;
21
+ return Qnil;
34
22
 
35
- char *str = StringValuePtr(val) ;
36
- char ch = str[0] ;
23
+ char *str = StringValuePtr(val);
24
+ size_t len = RSTRING_LEN(val);
37
25
 
38
26
  // If the string is empty, return false
39
- if (!ch) return Qfalse ;
27
+ if (len == 0) return Qfalse;
40
28
 
41
- unsigned char i = ch == '-' ? 1 : 0 ;
42
- if (!str[i]) return Qfalse ;
29
+ size_t i = 0;
30
+ char ch = str[0];
43
31
 
44
- unsigned char max = UCHAR_MAX ;
32
+ // If the string starts with '-', skip it but ensure there are digits after it
33
+ if (ch == '-') {
34
+ i = 1;
35
+ if (i == len) return Qfalse;
36
+ }
45
37
 
46
- # pragma GCC unroll 4
47
- while((ch = str[i++])) {
48
- if (ch < 48 || ch > 57)
49
- return Qfalse ;
38
+ // Iterate through each character to check if it's a digit
39
+ for (; i < len; i++) {
40
+ ch = str[i];
50
41
 
51
- if (i == max)
52
- return Qnil ;
42
+ if (ch < '0' || ch > '9') {
43
+ return Qfalse;
44
+ }
53
45
  }
54
46
 
55
- return Qtrue ;
47
+ return Qtrue;
56
48
  }
57
49
 
58
50
  void Init_integer() {
59
- VALUE linuxStat = rb_define_module("LinuxStat") ;
60
- VALUE misc = rb_define_module_under(linuxStat, "Misc") ;
51
+ VALUE linuxStat = rb_define_module("LinuxStat");
52
+ VALUE misc = rb_define_module_under(linuxStat, "Misc");
61
53
 
62
- rb_define_module_function(misc, "integer?", isNumber, 1) ;
54
+ rb_define_module_function(misc, "integer?", isNumber, 1);
63
55
  }
data/ext/nftw/extconf.rb CHANGED
@@ -5,4 +5,7 @@ unless have_const('linux') || RbConfig::CONFIG['arch'].to_s[/linux/]
5
5
  end
6
6
 
7
7
  abort('Missing header') unless have_header('ftw.h')
8
+
9
+ $CFLAGS << ' -O3 -march=native -mtune=native'
10
+
8
11
  create_makefile 'linux_stat/nftw'
data/ext/nftw/nftw.c CHANGED
@@ -1,13 +1,3 @@
1
- #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
2
- #pragma GCC optimize ("O3")
3
- #pragma GCC diagnostic warning "-Wall"
4
- #elif defined(__clang__)
5
- #pragma clang optimize on
6
- #pragma clang diagnostic warning "-Wall"
7
- #elif defined(__INTEL_COMPILER)
8
- #pragma intel optimization_level 3
9
- #endif
10
-
11
1
  #define _GNU_SOURCE 1
12
2
 
13
3
  #include <ftw.h>
@@ -16,17 +6,17 @@
16
6
 
17
7
  #include "ruby.h"
18
8
 
19
- VALUE LIST ;
20
- intmax_t TOTAL_FILES ;
9
+ VALUE LIST;
10
+ intmax_t TOTAL_FILES;
21
11
 
22
12
  static int storeInfo(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) {
23
- VALUE hash = rb_hash_new() ;
13
+ VALUE hash = rb_hash_new();
24
14
 
25
15
  // Raw type flag
26
16
  VALUE typeFlag = (tflag == FTW_D) ? ID2SYM(rb_intern("FTW_D")) : (tflag == FTW_DNR) ? ID2SYM(rb_intern("FTW_DNR")) :
27
17
  (tflag == FTW_DP) ? ID2SYM(rb_intern("FTW_DP")) : (tflag == FTW_F) ? ID2SYM(rb_intern("FTW_F")) :
28
18
  (tflag == FTW_NS) ? ID2SYM(rb_intern("FTW_NS")) : (tflag == FTW_SL) ? ID2SYM(rb_intern("FTW_SL")) :
29
- (tflag == FTW_SLN) ? ID2SYM(rb_intern("FTW_SLN")) : Qnil ;
19
+ (tflag == FTW_SLN) ? ID2SYM(rb_intern("FTW_SLN")) : Qnil;
30
20
 
31
21
  rb_hash_aset(
32
22
  hash,
@@ -62,20 +52,20 @@ static int storeInfo(const char *fpath, const struct stat *sb, int tflag, struct
62
52
  rb_str_new_cstr(fpath + ftwbuf->base)
63
53
  );
64
54
 
65
- rb_ary_push(LIST, hash) ;
66
- return 0 ;
55
+ rb_ary_push(LIST, hash);
56
+ return 0;
67
57
  }
68
58
 
69
59
  static int storeFilesInfo(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) {
70
60
  if (!(tflag == FTW_F || tflag == FTW_SL || tflag == FTW_SLN))
71
- return 0 ;
61
+ return 0;
72
62
 
73
- VALUE hash = rb_hash_new() ;
63
+ VALUE hash = rb_hash_new();
74
64
 
75
65
  // Raw type flag
76
66
  VALUE typeFlag = (tflag == FTW_F) ? ID2SYM(rb_intern("FTW_F")) :
77
67
  (tflag == FTW_SL) ? ID2SYM(rb_intern("FTW_SL")) :
78
- (tflag == FTW_SLN) ? ID2SYM(rb_intern("FTW_SLN")) : Qnil ;
68
+ (tflag == FTW_SLN) ? ID2SYM(rb_intern("FTW_SLN")) : Qnil;
79
69
 
80
70
  rb_hash_aset(
81
71
  hash,
@@ -105,9 +95,9 @@ static int storeFilesInfo(const char *fpath, const struct stat *sb, int tflag, s
105
95
  );
106
96
 
107
97
  // Dirname
108
- char dirname[ftwbuf->base] ;
109
- *dirname = '\0' ;
110
- strncat(dirname, fpath, ftwbuf->base - 1) ;
98
+ char dirname[ftwbuf->base];
99
+ *dirname = '\0';
100
+ strncat(dirname, fpath, ftwbuf->base - 1);
111
101
 
112
102
  rb_hash_aset(
113
103
  hash,
@@ -122,195 +112,195 @@ static int storeFilesInfo(const char *fpath, const struct stat *sb, int tflag, s
122
112
  rb_str_new_cstr(fpath + ftwbuf->base)
123
113
  );
124
114
 
125
- rb_ary_push(LIST, hash) ;
126
- return 0 ;
115
+ rb_ary_push(LIST, hash);
116
+ return 0;
127
117
  }
128
118
 
129
119
  static int countChildren(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) {
130
- TOTAL_FILES++ ;
131
- return 0 ;
120
+ TOTAL_FILES++;
121
+ return 0;
132
122
  }
133
123
 
134
124
  static int countFiles(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) {
135
- if(tflag == FTW_F || tflag == FTW_SL || tflag == FTW_SLN) TOTAL_FILES++ ;
136
- return 0 ;
125
+ if(tflag == FTW_F || tflag == FTW_SL || tflag == FTW_SLN) TOTAL_FILES++;
126
+ return 0;
137
127
  }
138
128
 
139
129
  static int countDirectories(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) {
140
- if(tflag == FTW_D || tflag == FTW_DNR) TOTAL_FILES++ ;
141
- return 0 ;
130
+ if(tflag == FTW_D || tflag == FTW_DNR) TOTAL_FILES++;
131
+ return 0;
142
132
  }
143
133
 
144
- VALUE getChildrenCount(volatile VALUE obj, volatile VALUE rb_dir, volatile VALUE rb_flags) {
145
- TOTAL_FILES = 0 ;
146
- rb_ary_clear(LIST) ;
134
+ VALUE getChildrenCount(VALUE obj, VALUE rb_dir, VALUE rb_flags) {
135
+ TOTAL_FILES = 0;
136
+ rb_ary_clear(LIST);
147
137
 
148
138
  int flags = FIX2INT(rb_flags);
149
- char *dir = StringValuePtr(rb_dir) ;
150
- VALUE returnValue = rb_hash_new() ;
139
+ char *dir = StringValuePtr(rb_dir);
140
+ VALUE returnValue = rb_hash_new();
151
141
 
152
142
  if (nftw(dir, countChildren, 20, flags) == -1) {
153
- rb_hash_aset(returnValue, ID2SYM(rb_intern("value")), ULL2NUM(TOTAL_FILES)) ;
154
- rb_hash_aset(returnValue, ID2SYM(rb_intern("error")), Qtrue) ;
143
+ rb_hash_aset(returnValue, ID2SYM(rb_intern("value")), ULL2NUM(TOTAL_FILES));
144
+ rb_hash_aset(returnValue, ID2SYM(rb_intern("error")), Qtrue);
155
145
  } else {
156
- rb_hash_aset(returnValue, ID2SYM(rb_intern("value")), ULL2NUM(TOTAL_FILES)) ;
157
- rb_hash_aset(returnValue, ID2SYM(rb_intern("error")), Qfalse) ;
146
+ rb_hash_aset(returnValue, ID2SYM(rb_intern("value")), ULL2NUM(TOTAL_FILES));
147
+ rb_hash_aset(returnValue, ID2SYM(rb_intern("error")), Qfalse);
158
148
  }
159
149
 
160
- return returnValue ;
150
+ return returnValue;
161
151
  }
162
152
 
163
- VALUE getFilesCount(volatile VALUE obj, volatile VALUE rb_dir) {
164
- TOTAL_FILES = 0 ;
153
+ VALUE getFilesCount(VALUE obj, VALUE rb_dir) {
154
+ TOTAL_FILES = 0;
165
155
 
166
- int flags = FTW_PHYS ;
156
+ int flags = FTW_PHYS;
167
157
  #ifdef FTW_CONTINUE
168
- flags |= FTW_CONTINUE ;
158
+ flags |= FTW_CONTINUE;
169
159
  #endif
170
160
 
171
161
  if (nftw(StringValuePtr(rb_dir), countFiles, 20, flags) == -1)
172
- return Qnil ;
162
+ return Qnil;
173
163
 
174
- return ULL2NUM(TOTAL_FILES) ;
164
+ return ULL2NUM(TOTAL_FILES);
175
165
  }
176
166
 
177
- VALUE getDirectoriesCount(volatile VALUE obj, volatile VALUE rb_dir) {
178
- TOTAL_FILES = 0 ;
167
+ VALUE getDirectoriesCount(VALUE obj, VALUE rb_dir) {
168
+ TOTAL_FILES = 0;
179
169
 
180
- int flags = FTW_PHYS ;
170
+ int flags = FTW_PHYS;
181
171
  #ifdef FTW_CONTINUE
182
- flags |= FTW_CONTINUE ;
172
+ flags |= FTW_CONTINUE;
183
173
  #endif
184
174
 
185
175
  if (nftw(StringValuePtr(rb_dir), countDirectories, 20, flags) == -1)
186
- return Qnil ;
176
+ return Qnil;
187
177
 
188
- return ULL2NUM(--TOTAL_FILES) ;
178
+ return ULL2NUM(--TOTAL_FILES);
189
179
  }
190
180
 
191
- VALUE getStat(volatile VALUE obj, volatile VALUE rb_dir, volatile VALUE rb_flags) {
192
- rb_ary_clear(LIST) ;
181
+ VALUE getStat(VALUE obj, VALUE rb_dir, VALUE rb_flags) {
182
+ rb_ary_clear(LIST);
193
183
 
194
184
  int flags = FIX2INT(rb_flags);
195
- char *dir = StringValuePtr(rb_dir) ;
196
- VALUE returnValue = rb_hash_new() ;
185
+ char *dir = StringValuePtr(rb_dir);
186
+ VALUE returnValue = rb_hash_new();
197
187
 
198
188
  if (nftw(dir, storeInfo, 20, flags) == -1) {
199
- rb_hash_aset(returnValue, ID2SYM(rb_intern("value")), LIST) ;
200
- rb_hash_aset(returnValue, ID2SYM(rb_intern("error")), Qtrue) ;
189
+ rb_hash_aset(returnValue, ID2SYM(rb_intern("value")), LIST);
190
+ rb_hash_aset(returnValue, ID2SYM(rb_intern("error")), Qtrue);
201
191
  } else {
202
- rb_hash_aset(returnValue, ID2SYM(rb_intern("value")), LIST) ;
203
- rb_hash_aset(returnValue, ID2SYM(rb_intern("error")), Qfalse) ;
192
+ rb_hash_aset(returnValue, ID2SYM(rb_intern("value")), LIST);
193
+ rb_hash_aset(returnValue, ID2SYM(rb_intern("error")), Qfalse);
204
194
  }
205
195
 
206
- return returnValue ;
196
+ return returnValue;
207
197
  }
208
198
 
209
- VALUE getFilesStat(volatile VALUE obj, volatile VALUE rb_dir) {
210
- rb_ary_clear(LIST) ;
199
+ VALUE getFilesStat(VALUE obj, VALUE rb_dir) {
200
+ rb_ary_clear(LIST);
211
201
 
212
- int flags = FTW_PHYS ;
202
+ int flags = FTW_PHYS;
213
203
  #ifdef FTW_CONTINUE
214
- flags |= FTW_CONTINUE ;
204
+ flags |= FTW_CONTINUE;
215
205
  #endif
216
206
 
217
- char *dir = StringValuePtr(rb_dir) ;
218
- VALUE returnValue = rb_hash_new() ;
207
+ char *dir = StringValuePtr(rb_dir);
208
+ VALUE returnValue = rb_hash_new();
219
209
 
220
210
  if (nftw(dir, storeFilesInfo, 20, flags) == -1) {
221
- rb_hash_aset(returnValue, ID2SYM(rb_intern("value")), LIST) ;
222
- rb_hash_aset(returnValue, ID2SYM(rb_intern("error")), Qtrue) ;
211
+ rb_hash_aset(returnValue, ID2SYM(rb_intern("value")), LIST);
212
+ rb_hash_aset(returnValue, ID2SYM(rb_intern("error")), Qtrue);
223
213
  } else {
224
- rb_hash_aset(returnValue, ID2SYM(rb_intern("value")), LIST) ;
225
- rb_hash_aset(returnValue, ID2SYM(rb_intern("error")), Qfalse) ;
214
+ rb_hash_aset(returnValue, ID2SYM(rb_intern("value")), LIST);
215
+ rb_hash_aset(returnValue, ID2SYM(rb_intern("error")), Qfalse);
226
216
  }
227
217
 
228
- return returnValue ;
218
+ return returnValue;
229
219
  }
230
220
 
231
221
  // Return all flags as hash
232
222
  VALUE flags_hash(VALUE nftw) {
233
- VALUE all_flags = rb_hash_new() ;
234
- rb_ary_clear(LIST) ;
223
+ VALUE all_flags = rb_hash_new();
224
+ rb_ary_clear(LIST);
235
225
 
236
226
  // All Flags
237
- VALUE flags = rb_hash_new() ;
227
+ VALUE flags = rb_hash_new();
238
228
  #ifdef FTW_ACTIONRETVAL
239
- rb_hash_aset(flags, ID2SYM(rb_intern("FTW_ACTIONRETVAL")), INT2FIX(FTW_ACTIONRETVAL)) ;
229
+ rb_hash_aset(flags, ID2SYM(rb_intern("FTW_ACTIONRETVAL")), INT2FIX(FTW_ACTIONRETVAL));
240
230
  #endif
241
231
 
242
- rb_hash_aset(flags, ID2SYM(rb_intern("FTW_CHDIR")), INT2FIX(FTW_CHDIR)) ;
243
- rb_hash_aset(flags, ID2SYM(rb_intern("FTW_DEPTH")), INT2FIX(FTW_DEPTH)) ;
244
- rb_hash_aset(flags, ID2SYM(rb_intern("FTW_MOUNT")), INT2FIX(FTW_MOUNT)) ;
245
- rb_hash_aset(flags, ID2SYM(rb_intern("FTW_PHYS")), INT2FIX(FTW_PHYS)) ;
246
- rb_hash_aset(all_flags, ID2SYM(rb_intern("flags")), flags) ;
232
+ rb_hash_aset(flags, ID2SYM(rb_intern("FTW_CHDIR")), INT2FIX(FTW_CHDIR));
233
+ rb_hash_aset(flags, ID2SYM(rb_intern("FTW_DEPTH")), INT2FIX(FTW_DEPTH));
234
+ rb_hash_aset(flags, ID2SYM(rb_intern("FTW_MOUNT")), INT2FIX(FTW_MOUNT));
235
+ rb_hash_aset(flags, ID2SYM(rb_intern("FTW_PHYS")), INT2FIX(FTW_PHYS));
236
+ rb_hash_aset(all_flags, ID2SYM(rb_intern("flags")), flags);
247
237
 
248
238
  // Actionretval Flags
249
239
  #ifdef FTW_ACTIONRETVAL
250
- VALUE actionretval_flags = rb_hash_new() ;
251
- rb_hash_aset(actionretval_flags, ID2SYM(rb_intern("FTW_CONTINUE")), INT2FIX(FTW_CONTINUE)) ;
252
- rb_hash_aset(actionretval_flags, ID2SYM(rb_intern("FTW_SKIP_SIBLINGS")), INT2FIX(FTW_SKIP_SIBLINGS)) ;
253
- rb_hash_aset(actionretval_flags, ID2SYM(rb_intern("FTW_SKIP_SUBTREE")), INT2FIX(FTW_SKIP_SUBTREE)) ;
254
- rb_hash_aset(actionretval_flags, ID2SYM(rb_intern("FTW_STOP")), INT2FIX(FTW_STOP)) ;
255
- rb_hash_aset(all_flags, ID2SYM(rb_intern("actionretval_flags")), actionretval_flags) ;
240
+ VALUE actionretval_flags = rb_hash_new();
241
+ rb_hash_aset(actionretval_flags, ID2SYM(rb_intern("FTW_CONTINUE")), INT2FIX(FTW_CONTINUE));
242
+ rb_hash_aset(actionretval_flags, ID2SYM(rb_intern("FTW_SKIP_SIBLINGS")), INT2FIX(FTW_SKIP_SIBLINGS));
243
+ rb_hash_aset(actionretval_flags, ID2SYM(rb_intern("FTW_SKIP_SUBTREE")), INT2FIX(FTW_SKIP_SUBTREE));
244
+ rb_hash_aset(actionretval_flags, ID2SYM(rb_intern("FTW_STOP")), INT2FIX(FTW_STOP));
245
+ rb_hash_aset(all_flags, ID2SYM(rb_intern("actionretval_flags")), actionretval_flags);
256
246
  #endif
257
247
 
258
248
  // Type Flags
259
- VALUE type_flags = rb_hash_new() ;
260
- rb_hash_aset(type_flags, ID2SYM(rb_intern("FTW_D")), INT2FIX(FTW_D)) ;
261
- rb_hash_aset(type_flags, ID2SYM(rb_intern("FTW_DNR")), INT2FIX(FTW_DNR)) ;
262
- rb_hash_aset(type_flags, ID2SYM(rb_intern("FTW_DP")), INT2FIX(FTW_DP)) ;
263
- rb_hash_aset(type_flags, ID2SYM(rb_intern("FTW_F")), INT2FIX(FTW_F)) ;
264
- rb_hash_aset(type_flags, ID2SYM(rb_intern("FTW_NS")), INT2FIX(FTW_NS)) ;
265
- rb_hash_aset(type_flags, ID2SYM(rb_intern("FTW_SL")), INT2FIX(FTW_SL)) ;
266
- rb_hash_aset(type_flags, ID2SYM(rb_intern("FTW_SLN")), INT2FIX(FTW_SLN)) ;
267
- rb_hash_aset(all_flags, ID2SYM(rb_intern("type_flags")), type_flags) ;
268
-
269
- return all_flags ;
249
+ VALUE type_flags = rb_hash_new();
250
+ rb_hash_aset(type_flags, ID2SYM(rb_intern("FTW_D")), INT2FIX(FTW_D));
251
+ rb_hash_aset(type_flags, ID2SYM(rb_intern("FTW_DNR")), INT2FIX(FTW_DNR));
252
+ rb_hash_aset(type_flags, ID2SYM(rb_intern("FTW_DP")), INT2FIX(FTW_DP));
253
+ rb_hash_aset(type_flags, ID2SYM(rb_intern("FTW_F")), INT2FIX(FTW_F));
254
+ rb_hash_aset(type_flags, ID2SYM(rb_intern("FTW_NS")), INT2FIX(FTW_NS));
255
+ rb_hash_aset(type_flags, ID2SYM(rb_intern("FTW_SL")), INT2FIX(FTW_SL));
256
+ rb_hash_aset(type_flags, ID2SYM(rb_intern("FTW_SLN")), INT2FIX(FTW_SLN));
257
+ rb_hash_aset(all_flags, ID2SYM(rb_intern("type_flags")), type_flags);
258
+
259
+ return all_flags;
270
260
  }
271
261
 
272
262
  void Init_nftw() {
273
263
  // Initialize globals
274
- LIST = rb_ary_new() ;
275
- rb_global_variable(&LIST) ;
264
+ LIST = rb_ary_new();
265
+ rb_global_variable(&LIST);
276
266
 
277
267
  // Initialize main LinuxStat and NFTW modules
278
- VALUE _linux_stat = rb_define_module("LinuxStat") ;
268
+ VALUE _linux_stat = rb_define_module("LinuxStat");
279
269
  VALUE nftw = rb_define_module_under(_linux_stat, "NFTW");
280
270
 
281
271
  // Methods
282
- rb_define_module_function(nftw, "stat", getStat, 2) ;
283
- rb_define_module_function(nftw, "stat_files", getFilesStat, 1) ;
284
- rb_define_module_function(nftw, "count_children", getChildrenCount, 2) ;
285
- rb_define_module_function(nftw, "count_files", getFilesCount, 1) ;
286
- rb_define_module_function(nftw, "count_directories", getDirectoriesCount, 1) ;
272
+ rb_define_module_function(nftw, "stat", getStat, 2);
273
+ rb_define_module_function(nftw, "stat_files", getFilesStat, 1);
274
+ rb_define_module_function(nftw, "count_children", getChildrenCount, 2);
275
+ rb_define_module_function(nftw, "count_files", getFilesCount, 1);
276
+ rb_define_module_function(nftw, "count_directories", getDirectoriesCount, 1);
287
277
 
288
278
  // Constants
289
- rb_define_const(nftw, "FLAGS", flags_hash(nftw)) ;
279
+ rb_define_const(nftw, "FLAGS", flags_hash(nftw));
290
280
 
291
281
  // Flags
292
282
  #ifdef FTW_ACTIONRETVAL
293
- rb_define_const(nftw, "FTW_ACTIONRETVAL", INT2FIX(FTW_ACTIONRETVAL)) ;
283
+ rb_define_const(nftw, "FTW_ACTIONRETVAL", INT2FIX(FTW_ACTIONRETVAL));
294
284
  #endif
295
- rb_define_const(nftw, "FTW_CHDIR", INT2FIX(FTW_CHDIR)) ;
296
- rb_define_const(nftw, "FTW_DEPTH", INT2FIX(FTW_DEPTH)) ;
297
- rb_define_const(nftw, "FTW_MOUNT", INT2FIX(FTW_MOUNT)) ;
298
- rb_define_const(nftw, "FTW_PHYS", INT2FIX(FTW_PHYS)) ;
285
+ rb_define_const(nftw, "FTW_CHDIR", INT2FIX(FTW_CHDIR));
286
+ rb_define_const(nftw, "FTW_DEPTH", INT2FIX(FTW_DEPTH));
287
+ rb_define_const(nftw, "FTW_MOUNT", INT2FIX(FTW_MOUNT));
288
+ rb_define_const(nftw, "FTW_PHYS", INT2FIX(FTW_PHYS));
299
289
 
300
290
  // ActionRetval flags
301
291
  #ifdef FTW_ACTIONRETVAL
302
- rb_define_const(nftw, "FTW_CONTINUE", INT2FIX(FTW_CONTINUE)) ;
303
- rb_define_const(nftw, "FTW_SKIP_SIBLINGS", INT2FIX(FTW_SKIP_SIBLINGS)) ;
304
- rb_define_const(nftw, "FTW_SKIP_SUBTREE", INT2FIX(FTW_SKIP_SUBTREE)) ;
305
- rb_define_const(nftw, "FTW_STOP", INT2FIX(FTW_STOP)) ;
292
+ rb_define_const(nftw, "FTW_CONTINUE", INT2FIX(FTW_CONTINUE));
293
+ rb_define_const(nftw, "FTW_SKIP_SIBLINGS", INT2FIX(FTW_SKIP_SIBLINGS));
294
+ rb_define_const(nftw, "FTW_SKIP_SUBTREE", INT2FIX(FTW_SKIP_SUBTREE));
295
+ rb_define_const(nftw, "FTW_STOP", INT2FIX(FTW_STOP));
306
296
  #endif
307
297
 
308
298
  // typeflags
309
- rb_define_const(nftw, "FTW_D", INT2FIX(FTW_D)) ;
310
- rb_define_const(nftw, "FTW_DNR", INT2FIX(FTW_DNR)) ;
311
- rb_define_const(nftw, "FTW_DP", INT2FIX(FTW_DP)) ;
312
- rb_define_const(nftw, "FTW_F", INT2FIX(FTW_F)) ;
313
- rb_define_const(nftw, "FTW_NS", INT2FIX(FTW_NS)) ;
314
- rb_define_const(nftw, "FTW_SL", INT2FIX(FTW_SL)) ;
315
- rb_define_const(nftw, "FTW_SLN", INT2FIX(FTW_SLN)) ;
299
+ rb_define_const(nftw, "FTW_D", INT2FIX(FTW_D));
300
+ rb_define_const(nftw, "FTW_DNR", INT2FIX(FTW_DNR));
301
+ rb_define_const(nftw, "FTW_DP", INT2FIX(FTW_DP));
302
+ rb_define_const(nftw, "FTW_F", INT2FIX(FTW_F));
303
+ rb_define_const(nftw, "FTW_NS", INT2FIX(FTW_NS));
304
+ rb_define_const(nftw, "FTW_SL", INT2FIX(FTW_SL));
305
+ rb_define_const(nftw, "FTW_SLN", INT2FIX(FTW_SLN));
316
306
  }
data/ext/nproc/extconf.rb CHANGED
@@ -8,4 +8,6 @@ unless have_header('sched.h') && have_header('ruby.h')
8
8
  abort('Missing header')
9
9
  end
10
10
 
11
+ $CFLAGS << ' -O3 -march=native -mtune=native'
12
+
11
13
  create_makefile 'linux_stat/nproc'