From 69b2487650782f135db76078c4a7fb841cb936ac Mon Sep 17 00:00:00 2001 From: drkhsh Date: Thu, 27 Oct 2022 23:44:52 +0200 Subject: 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. --- components/netspeeds.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'components/netspeeds.c') diff --git a/components/netspeeds.c b/components/netspeeds.c index f7bac2e..3a1817b 100644 --- a/components/netspeeds.c +++ b/components/netspeeds.c @@ -8,6 +8,9 @@ #if defined(__linux__) #include + #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; } -- cgit v1.2.3