Sha256: 0199d59663e893e7e92fd18dc685bcc137e2fecf8262951dbeabd6b386c14792

Contents?: true

Size: 586 Bytes

Versions: 1

Compression:

Stored size: 586 Bytes

Contents

static VALUE getDiskStats (VALUE obj, VALUE path) {
	FILE *file = fopen("/proc/diskstats", "r");
	if(!file) return rb_ary_new();

	char lines[120];
	unsigned long long read, write;
	char *p = StringValuePtr(path);

	while (fgets(lines, sizeof(lines) - 1, file)) {
		if (sscanf(lines, "%*s %*s %119s %*s %*s %llu %*s %*s %*s %llu", lines, &read, &write) == 3) {
			if(strcmp(lines, p) == 0) {
				fclose(file);

				return rb_ary_new_from_args(
					2,
					ULL2NUM(read),
					ULL2NUM(write)
				);
			}
		} else {
			return rb_ary_new();
		}
	}

	fclose(file);
	return rb_ary_new();
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
linux_stat-2.7.0 ext/fs_stat/disk_stat.h