From a2fbf01fe252afd1dde5dcf48aa46639e038d2ac Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Sun, 6 May 2007 09:32:21 +0000 Subject: [PATCH] fixed apm_adapter for both openbsd and freebsd and some build warnings cleaned git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@862 7f574dfc-610e-0410-a909-a81674777703 --- src/conky.c | 20 +++++++++++++------- src/conky.h | 4 +++- src/freebsd.c | 28 +++++++++++++++++++--------- src/openbsd.c | 29 ++++++++++++++++++++--------- 4 files changed, 55 insertions(+), 26 deletions(-) diff --git a/src/conky.c b/src/conky.c index 8f6124b5..c9073b56 100644 --- a/src/conky.c +++ b/src/conky.c @@ -454,6 +454,9 @@ int check_mount(char *s) return 1; return 0; +#elif defined(__OpenBSD__) + /* stub */ + return 0; #endif } @@ -599,7 +602,7 @@ memrchr (const void *buffer, int c, size_t n) for (p += n; n ; n--) if (*--p == c) - return p; + return (void *)p; return NULL; } #endif @@ -1083,11 +1086,11 @@ enum text_object_type { OBJ_pop3, OBJ_pop3_unseen, OBJ_pop3_used, -#if defined(__FreeBSD__) && (defined(i386) || defined(__i386__)) +#if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__)) OBJ_apm_adapter, OBJ_apm_battery_time, OBJ_apm_battery_life, -#endif /* __FreeBSD__ */ +#endif /* __FreeBSD__ __OpenBSD__ */ #ifdef __OpenBSD__ OBJ_obsd_sensors_temp, OBJ_obsd_sensors_fan, @@ -2966,7 +2969,7 @@ static struct text_object *construct_text_object(const char *s, const char *arg, } END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END -#if defined(__FreeBSD__) && (defined(i386) || defined(__i386__)) +#if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__)) OBJ(apm_adapter, 0) END OBJ(apm_battery_life, 0) END OBJ(apm_battery_time, 0) END @@ -4574,9 +4577,12 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object * format_seconds(p, p_max_size, (int) cur->uptime); } -#if defined(__FreeBSD__) && (defined(i386) || defined(__i386__)) +#if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__)) OBJ(apm_adapter) { - snprintf(p, p_max_size, "%s", get_apm_adapter()); + char *msg; + msg = get_apm_adapter(); + snprintf(p, p_max_size, "%s", msg); + free(msg); } OBJ(apm_battery_life) { char *msg; @@ -4590,7 +4596,7 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object * snprintf(p, p_max_size, "%s", msg); free(msg); } -#endif /* __FreeBSD__ */ +#endif /* __FreeBSD__ __OpenBSD__ */ #ifdef MPD OBJ(mpd_title) { diff --git a/src/conky.h b/src/conky.h index 18893d78..66c7a13e 100644 --- a/src/conky.h +++ b/src/conky.h @@ -562,8 +562,10 @@ void update_mail_count(); kvm_t *kd; #endif -#if defined(__FreeBSD__) && (defined(i386) || defined(__i386__)) +#if (defined(__FreeBSD__) || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__)) +#ifdef __FreeBSD__ int apm_getinfo(int fd, apm_info_t aip); +#endif char *get_apm_adapter(void); char *get_apm_battery_life(void); char *get_apm_battery_time(void); diff --git a/src/freebsd.c b/src/freebsd.c index d90d3092..e27f4809 100644 --- a/src/freebsd.c +++ b/src/freebsd.c @@ -819,28 +819,38 @@ char int fd; struct apm_info info; + out = (char *)calloc(16, sizeof (char)); + fd = open(APMDEV, O_RDONLY); - if (fd < 0) - return ("ERR"); + if (fd < 0) { + strncpy(out, "ERR", 16); + return (out); + } if (apm_getinfo(fd, &info) != 0) { close(fd); - return ("ERR"); + strncpy(out, "ERR", 16); + return (out); } close(fd); switch (info.ai_acline) { case 0: - return ("off-line"); + strncpy(out, "off-line", 16); + return (out); break; case 1: - if (info.ai_batt_stat == 3) - return ("charging"); - else - return ("on-line"); + if (info.ai_batt_stat == 3) { + strncpy(out, "charging", 16); + return (out); + } else { + strncpy(out, "on-line", 16); + return (out); + } break; default: - return ("unknown"); + strncpy(out, "unknown", 16); + return (out); break; } } diff --git a/src/openbsd.c b/src/openbsd.c index 803ad75a..3e0d3e9c 100644 --- a/src/openbsd.c +++ b/src/openbsd.c @@ -688,29 +688,40 @@ char { int fd; struct apm_power_info info; + char *out; + + out = (char *)calloc(16, sizeof (char)); fd = open(APMDEV, O_RDONLY); - if (fd < 0) - return ("ERR"); + if (fd < 0) { + strncpy(out, "ERR", 16); + return (out); + } if (apm_getinfo(fd, &info) != 0) { close(fd); - return ("ERR"); + strncpy(out, "ERR", 16); + return (out); } close(fd); switch (info.ac_state) { case APM_AC_OFF: - return ("off-line"); + strncpy(out, "off-line", 16); + return (out); break; case APM_AC_ON: - if (info.battery_state == APM_BATT_CHARGING) - return ("charging"); - else - return ("on-line"); + if (info.battery_state == APM_BATT_CHARGING) { + strncpy(out, "charging", 16); + return (out); + } else { + strncpy(out, "on-line", 16); + return (out); + } break; default: - return ("unknown"); + strncpy(out, "unknown", 16); + return (out); break; } }