diff options
author | drkhsh <me@drkhsh.at> | 2022-10-27 23:44:52 +0200 |
---|---|---|
committer | Rafael Marçalo <raroma09@gmail.com> | 2022-10-28 22:21:57 +0100 |
commit | e4d20140ece1a98149ba6def74978e7e90b9c11f (patch) | |
tree | 2cc6d8b4358d78cd1d931c37c8766103c6f00861 /components/netspeeds.c | |
parent | 1af8f3cebe5048b0e263303bbbcef75ecd236c4a (diff) |
various: Put paths into defines to avoid line wraps
Long, wrapped, multi-line if statements suck to read.
This fixes readability in the worst places by packing format strings for
paths into defines.
Diffstat (limited to 'components/netspeeds.c')
-rw-r--r-- | components/netspeeds.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/components/netspeeds.c b/components/netspeeds.c index 0f92368..18aa097 100644 --- a/components/netspeeds.c +++ b/components/netspeeds.c @@ -8,6 +8,9 @@ #if defined(__linux__) #include <stdint.h> + #define NET_RX_BYTES "/sys/class/net/%s/statistics/rx_bytes" + #define NET_TX_BYTES "/sys/class/net/%s/statistics/tx_bytes" + const char * netspeed_rx(const char *interface) { @@ -18,11 +21,8 @@ oldrxbytes = rxbytes; - if (esnprintf(path, sizeof(path), - "/sys/class/net/%s/statistics/rx_bytes", - interface) < 0) { + if (esnprintf(path, sizeof(path), NET_RX_BYTES, interface) < 0) return NULL; - } if (pscanf(path, "%ju", &rxbytes) != 1) { return NULL; } @@ -44,11 +44,8 @@ oldtxbytes = txbytes; - if (esnprintf(path, sizeof(path), - "/sys/class/net/%s/statistics/tx_bytes", - interface) < 0) { + if (esnprintf(path, sizeof(path), NET_TX_BYTES, interface) < 0) return NULL; - } if (pscanf(path, "%ju", &txbytes) != 1) { return NULL; } |