From 5bdb2a95df7272112df60b42b6025cbceea74b15 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 25 Jan 2009 20:50:02 +0100 Subject: [PATCH] Make linux-dependant part use #ifdef LINUX --- Makefile | 4 ++++ wmiistatus.c | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 88e4062..0cb662a 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,10 @@ CFLAGS+=-Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -W CFLAGS+=-g CFLAGS+=-DPREFIX=\"\" +ifeq ($(shell uname),Linux) +CFLAGS+=-DLINUX +endif + wmiistatus: wmiistatus.o wmiistatus.h config.h config.o clean: diff --git a/wmiistatus.c b/wmiistatus.c index bb65690..15434b9 100644 --- a/wmiistatus.c +++ b/wmiistatus.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -50,9 +51,10 @@ #include #include #include +#ifdef LINUX #include #include - +#endif #define _IS_WMIISTATUS_C #include "wmiistatus.h" @@ -355,6 +357,7 @@ static char *get_eth_info() { int ethspeed = 0; if (get_ethspeed) { +#ifdef LINUX /* This code path requires root privileges */ struct ifreq ifr; struct ethtool_cmd ecmd; @@ -366,6 +369,7 @@ static char *get_eth_info() { if (ioctl(general_socket, SIOCETHTOOL, &ifr) == 0) ethspeed = (ecmd.speed == USHRT_MAX ? 0 : ecmd.speed); else get_ethspeed = false; +#endif } if (ip_address == NULL) @@ -406,8 +410,7 @@ static bool process_runs(const char *path) { int main(int argc, char *argv[]) { char part[512], - pathbuf[512], - *end; + pathbuf[512]; unsigned int i; int load_avg; @@ -415,12 +418,18 @@ int main(int argc, char *argv[]) { int o, option_index = 0; struct option long_options[] = { {"config", required_argument, 0, 'c'}, + {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; - while ((o = getopt_long(argc, argv, "c:", long_options, &option_index)) != -1) + while ((o = getopt_long(argc, argv, "c:h", long_options, &option_index)) != -1) if ((char)o == 'c') configfile = optarg; + else if ((char)o == 'h') { + printf("wmiistatus (c) 2008-2009 Michael Stapelberg\n" + "Syntax: %s [-c ]\n", argv[0]); + return 0; + } if (load_configuration(configfile) < 0) return EXIT_FAILURE; @@ -457,8 +466,7 @@ int main(int argc, char *argv[]) { die("Could not open /proc/loadavg"); (void)read(load_avg, part, sizeof(part)); (void)close(load_avg); - end = skip_character(part, ' ', 3); - *end = '\0'; + *skip_character(part, ' ', 3) = '\0'; write_to_statusbar(concat(order[ORDER_LOAD], "load"), part); if (time_format) { -- 2.39.2