12 #include <sys/types.h>
28 numread =
read(fd, buf, buflen - 1);
37 return (
unsigned int) numread;
40 static unsigned int sysfs_write_file(
const char *
path,
41 const char *
value,
size_t len)
50 numwrite =
write(fd, value, len);
56 return (
unsigned int) numwrite;
72 unsigned long long value;
79 if (
stat(path, &statbuf) != 0)
87 if (
stat(path, &statbuf) != 0)
99 linebuf[numread] =
'\0';
102 value =
strtoull(linebuf, &endp, 0);
103 if (value > 1 || value < 0)
125 cpu, idlestate, fname);
131 numread =
read(fd, buf, buflen - 1);
140 return (
unsigned int) numread;
160 static unsigned long long sysfs_idlestate_get_one_value(
unsigned int cpu,
161 unsigned int idlestate,
164 unsigned long long value;
173 idlestate_value_files[which],
174 linebuf,
sizeof(linebuf));
178 value =
strtoull(linebuf, &endp, 0);
180 if (endp == linebuf || errno ==
ERANGE)
200 static char *sysfs_idlestate_get_one_string(
unsigned int cpu,
201 unsigned int idlestate,
212 idlestate_string_files[which],
213 linebuf,
sizeof(linebuf));
217 result = strdup(linebuf);
221 if (result[
strlen(result) - 1] ==
'\n')
222 result[
strlen(result) - 1] =
'\0';
228 unsigned int idlestate)
234 unsigned int idlestate)
240 unsigned int idlestate)
242 return sysfs_idlestate_get_one_value(cpu, idlestate,
IDLESTATE_TIME);
247 return sysfs_idlestate_get_one_string(cpu, idlestate,
IDLESTATE_NAME);
252 return sysfs_idlestate_get_one_string(cpu, idlestate,
IDLESTATE_DESC);
277 "cpu%u/cpuidle/state%d", cpu, idlestates);
290 static unsigned int sysfs_cpuidle_read_file(
const char *
fname,
char *
buf,
318 static char *sysfs_cpuidle_get_one_string(
enum cpuidle_string which)
327 len = sysfs_cpuidle_read_file(cpuidle_string_files[which],
328 linebuf,
sizeof(linebuf));
332 result = strdup(linebuf);
336 if (result[
strlen(result) - 1] ==
'\n')
337 result[
strlen(result) - 1] =
'\0';