tReport frequency of CPU0 in Linux - spoon - dwm status utility (2f30 fork)
 (HTM) git clone git://src.adamsgaard.dk/spoon
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit 07f66ef7d3e6f3456bcdf7078e1d1a012c36922a
 (DIR) parent 311f1ed9305fbaadc78ecd85c50e3b2df87e5567
 (HTM) Author: lostd <lostd@2f30.org>
       Date:   Wed,  2 Nov 2016 16:00:54 +0100
       
       Report frequency of CPU0 in Linux
       
       Diffstat:
         M Makefile                            |       3 ++-
         M cpu.c                               |      19 +++++++++++++++++++
       
       2 files changed, 21 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/Makefile b/Makefile
       t@@ -13,7 +13,8 @@ CPPFLAGS_OpenBSD = -I/usr/X11R6/include -I/usr/local/include
        LDFLAGS_OpenBSD = -L/usr/X11R6/lib -L/usr/local/lib
        CPPFLAGS_Linux = -DPATH_BAT_CAP=\"/sys/class/power_supply/BAT0/capacity\"\
                         -DPATH_AC_ONLINE=\"/sys/class/power_supply/AC/online\"\
       -                 -DPATH_TEMP=\"/sys/class/hwmon/hwmon0/temp1_input\"
       +                 -DPATH_TEMP=\"/sys/class/hwmon/hwmon0/temp1_input\"\
       +                 -DPATH_CPU_FREQ=\"/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq\"
        CPPFLAGS = $(CPPFLAGS_$(UNAME))
        LDFLAGS = $(LDFLAGS_$(UNAME))
        LDLIBS = -lX11
 (DIR) diff --git a/cpu.c b/cpu.c
       t@@ -1,3 +1,4 @@
       +#include <err.h>
        #include <stdio.h>
        
        #ifdef __OpenBSD__
       t@@ -17,4 +18,22 @@ cpuread(void *arg, char *buf, size_t len)
                snprintf(buf, len, "%4dMHz", cpuspeed);
                return 0;
        }
       +#elif __linux__
       +int
       +cpuread(void *arg, char *buf, size_t len)
       +{
       +        FILE *fp;
       +        int freq;
       +
       +        fp = fopen(PATH_CPU_FREQ, "r");
       +        if (fp == NULL) {
       +                warn("fopen %s", PATH_CPU_FREQ);
       +                return -1;
       +        }
       +        fscanf(fp, "%d", &freq);
       +        fclose(fp);
       +        freq /= 1000;
       +        snprintf(buf, len, "%4dMHz", freq);
       +        return 0;
       +}
        #endif