On Tue, Jul 02, 2024 at 02:26:25PM -0700, Reinette Chatre wrote: > Hi Tony, > > On 7/1/24 9:04 AM, Luck, Tony wrote: > > +static bool cpus_offline_empty(void) > > +{ > > + char offline_cpus_str[64]; > > + FILE *fp; > > + > > + fp = fopen("/sys/devices/system/cpu/offline", "r"); > > > > Check for fp == NULL before using it. > > > > + if (fscanf(fp, "%s", offline_cpus_str) < 0) { > > > > fscanf() seems like a heavy hammer. > > Do you perhaps have any recommendations that should be used instead of > fscanf()? I checked with stat() but could not see a difference between > file with a CPU and a file without. Other alternative is > open()/read()/close()? Looks like when there are no offline CPUs then > the file will only contain '\n' so it may be possible to read one byte > from the file and confirm it is '\n' as a check for "cpus_offline_empty()". Sorry. I replied with Outlook and didn't quote things properly so my alternate suggestion didn't stand out. Here it is again: if (fgets(offline_cpus_str, sizeof(offline_cpus_str), fp) == NULL) { fclose(fp); return true; } But that was with the assumption that /sys/devices/system/cpu/offline would be empty. Not that it would conatain a single "\n" as you say above. So fgets( ...) followed with "if (offline_cpus_str[0] == '\n') "? -Tony