I am using C
file IO to read value from a sysfs
interface in linux
. Path and sample value of the register is as follows:
cat /sys/class/powercap/intel-rapl/intel-rapl\:0/energy_uj
56039694184
Code: Added \
after intel-rapl\
to take into account unknown escape sequence
#define FILE_SIZE 512
static FILE *fp;
char filename[FILE_SIZE];
char TEMP[FILE_SIZE];
int FILE, READ;
long int POWER;
FILE = open("/sys/class/powercap/intel-rapl/intel-rapl\\:0/energy_uj", O_RDONLY);
READ = read(FILE, TEMP, sizeof(TEMP));
POWER= strtod(TEMP,NULL);
close(FILE);
sprintf(filename,"test.csv");
fp = fopen(filename,"a+");
fprintf(fp,"\n");
fprintf(fp, "%ld", POWER);
The code compiles without any error, but in the output file I am getting value as 0
. Is this due to how I am taking into account the escape sequence?
Thanks.