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.
This commit is contained in:
drkhsh
2022-10-27 23:44:52 +02:00
parent c46c1487a9
commit 69b2487650
5 changed files with 36 additions and 41 deletions

View File

@ -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;
}