Browse Source

More robust preprocessor switches

Replace #ifdef with #if defined() and #elif with #elif defined() as it
should only test if it is defined or not.
master
Aaron Marcher 8 years ago
parent
commit
e79d4932ea
  1. 10
      components/battery.c
  2. 2
      components/cpu.c
  3. 2
      components/entropy.c
  4. 2
      components/ip.c
  5. 2
      components/ram.c
  6. 2
      components/swap.c
  7. 2
      components/temperature.c
  8. 8
      components/uptime.c
  9. 2
      components/volume.c
  10. 2
      components/wifi.c

10
components/battery.c

@ -1,10 +1,10 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#include <err.h> #include <err.h>
#include <stdio.h> #include <stdio.h>
#ifdef __linux__ #if defined(__linux__)
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
#elif __OpenBSD__ #elif defined(__OpenBSD__)
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
@ -16,14 +16,14 @@
const char * const char *
battery_perc(const char *bat) battery_perc(const char *bat)
{ {
#ifdef __linux__ #if defined(__linux__)
int perc; int perc;
char path[PATH_MAX]; char path[PATH_MAX];
snprintf(path, sizeof(path), "%s%s%s", "/sys/class/power_supply/", bat, "/capacity"); snprintf(path, sizeof(path), "%s%s%s", "/sys/class/power_supply/", bat, "/capacity");
return (pscanf(path, "%i", &perc) == 1) ? return (pscanf(path, "%i", &perc) == 1) ?
bprintf("%d", perc) : NULL; bprintf("%d", perc) : NULL;
#elif __OpenBSD__ #elif defined(__OpenBSD__)
struct apm_power_info apm_info; struct apm_power_info apm_info;
int fd; int fd;
@ -44,7 +44,7 @@ battery_perc(const char *bat)
#endif #endif
} }
#ifdef __linux__ #if defined(__linux__)
const char * const char *
battery_power(const char *bat) battery_power(const char *bat)
{ {

2
components/cpu.c

@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#ifdef __linux__ #if defined(__linux__)
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>

2
components/entropy.c

@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#ifdef __linux__ #if defined(__linux__)
#include <stdio.h> #include <stdio.h>
#include "../util.h" #include "../util.h"

2
components/ip.c

@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#ifdef __linux__ #if defined(__linux__)
#include <err.h> #include <err.h>
#include <ifaddrs.h> #include <ifaddrs.h>
#include <netdb.h> #include <netdb.h>

2
components/ram.c

@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#ifdef __linux__ #if defined(__linux__)
#include <stdio.h> #include <stdio.h>
#include "../util.h" #include "../util.h"

2
components/swap.c

@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#ifdef __linux__ #if defined(__linux__)
#include <err.h> #include <err.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>

2
components/temperature.c

@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#ifdef __linux__ #if defined(__linux__)
#include <stdio.h> #include <stdio.h>
#include "../util.h" #include "../util.h"

8
components/uptime.c

@ -1,8 +1,8 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#include <stdio.h> #include <stdio.h>
#ifdef __linux__ #if defined(__linux__)
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#elif __OpenBSD__ #elif defined(__OpenBSD__)
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include <sys/time.h> #include <sys/time.h>
#endif #endif
@ -15,12 +15,12 @@ uptime(void)
int h; int h;
int m; int m;
int uptime = 0; int uptime = 0;
#ifdef __linux__ #if defined(__linux__)
struct sysinfo info; struct sysinfo info;
sysinfo(&info); sysinfo(&info);
uptime = info.uptime; uptime = info.uptime;
#elif __OpenBSD__ #elif defined(__OpenBSD__)
int mib[2]; int mib[2];
size_t size; size_t size;
time_t now; time_t now;

2
components/volume.c

@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#ifdef __linux__ #if defined(__linux__)
#include <err.h> #include <err.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/soundcard.h> #include <sys/soundcard.h>

2
components/wifi.c

@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#ifdef __linux__ #if defined(__linux__)
#include <err.h> #include <err.h>
#include <ifaddrs.h> #include <ifaddrs.h>
#include <linux/wireless.h> #include <linux/wireless.h>

Loading…
Cancel
Save