1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-18 02:55:12 +00:00

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
This commit is contained in:
Toni Spets 2007-05-06 09:32:21 +00:00
parent f9cab2a051
commit a2fbf01fe2
4 changed files with 55 additions and 26 deletions

View File

@ -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) {

View File

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

View File

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

View File

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