+ if (len == -1)
+ ALOGW("Cannot write to %s (%s)\n", path, strerror(errno));
+ else if (len != buf_len)
+ ALOGW("Cannot write %d bytes to %s (%d)\n", buf_len, path, len);
+ else
+ ALOGV("Wrote %d bytes to %s\n", buf_len, path);
+
+ return len;
+}
+
+
+static void str2int(const char* buf, void *v)
+{
+ *(int*)v = atoi(buf);
+}
+
+
+static void str2float(const char* buf, void *v)
+{
+ *(float*)v = strtof(buf, NULL);
+}
+
+
+static void str2uint64(const char* buf, void *v)
+{
+ *(uint64_t*)v = atoll(buf);
+}
+
+
+int sysfs_read_num(const char path[PATH_MAX], void *v,
+ void (*str2num)(const char* buf, void *v))
+{
+ char buf[20];
+ int len = sysfs_read_str(path, buf, sizeof(buf));
+