--- wmapm.c.orig	Sun Jan  3 11:27:09 1999
+++ wmapm.c	Sat Oct  9 19:27:17 1999
@@ -158,6 +158,20 @@
 #include "wmapm_master_LowColor.xpm"
 #include "wmapm_mask.xbm"
 
+#if !defined(MINIX) && !defined(WIN32)
+#include <sys/param.h>  /* for NOFILE */
+#endif
+
+#if (BSD >= 199103)
+#define USE_POSIX_WAIT
+#define HAS_POSIX_SAVED_IDS
+#endif
+
+#ifdef HAS_POSIX_SAVED_IDS
+#include <unistd.h>
+#include <sys/types.h>
+#include <errno.h>
+#endif /* HAS_POSIX_SAVED_IDS */
 
 
 #ifdef Linux
@@ -308,6 +322,7 @@
 	    my_cur_info.ac_line_status     = (int)temp_info.ai_acline;
 	    my_cur_info.battery_status     = (int)temp_info.ai_batt_stat;
 	    my_cur_info.battery_percentage = (int)temp_info.ai_batt_life;
+	    my_cur_info.battery_time       = (int)temp_info.ai_batt_time;
 #endif
 	
 
@@ -385,7 +400,7 @@
 	     *         If charging:     Time left before battery gets to maximum
 	     *
 	     */
-#ifdef Linux     /* FreeBSD's apm info does not support time left */
+#ifdef Linux
 	    if (my_cur_info.battery_time >= 1440) {
 
 		/*
@@ -411,11 +426,16 @@
 
 	    }
 #endif
-#ifdef FreeBSD
-	    /*
-	     *  Show "NULL" time indicator.
-	     */
-	    copyXPMArea(83, 106, 41, 9, 15, 7);
+#if FreeBSD
+		time_left = my_cur_info.battery_time / 60;
+	        hour_left = time_left / 60;
+	        min_left  = time_left % 60;
+
+	        copyXPMArea( (hour_left / 10) * 7 + 5, 93, 7, 9, 21, 7); 	/* Show 10's (hour) */
+	        copyXPMArea((hour_left % 10) * 7 + 5, 93, 7, 9, 29, 7); 	/* Show 1's (hour)  */
+	        copyXPMArea(76, 93, 2, 9, 38, 7);		 		/* colon  	    */
+	        copyXPMArea((min_left / 10) * 7 + 5, 93, 7, 9, 42, 7); 		/* Show 10's (min)  */
+	        copyXPMArea((min_left % 10) * 7 + 5, 93, 7, 9, 50, 7); 		/* Show 1's (min)   */
 #endif
 	
 
@@ -643,6 +663,13 @@
 
    int x=xev->x;
    int y=xev->y;
+#ifdef HAS_POSIX_SAVED_IDS
+   uid_t euid = geteuid();
+   gid_t egid = getegid();
+   uid_t ruid = getuid();
+   gid_t rgid = getgid();
+#endif /* HAS_POSIX_SAVED_IDS */
+
 
    if(x>=5 && y>=48 && x<=17 && y<=58){
 
@@ -656,7 +683,32 @@
 	 */
 	copyXPMArea(5, 106, 13, 11, 5, 48);
 	RedrawWindow();
+#if FreeBSD
+
+#ifdef HAS_POSIX_SAVED_IDS
+    if (setegid(rgid) == -1)
+		(void) fprintf(stderr, "setegid(%d): %s\n",
+					   (int) rgid, strerror(errno));
+    if (seteuid(ruid) == -1)
+		(void) fprintf(stderr, "seteuid(%d): %s\n",
+                       (int) ruid, strerror(errno));
+#endif /* HAS_POSIX_SAVED_IDS */
+
+	system("apm -Z");
+
+#ifdef HAS_POSIX_SAVED_IDS
+    if (seteuid(euid) == -1)
+        (void) fprintf(stderr, "seteuid(%d): %s\n",
+					   (int) euid, strerror(errno));
+
+    if (setegid(egid) == -1)
+		(void) fprintf(stderr, "setegid(%d): %s\n",
+					   (int) egid, strerror(errno));
+#endif
+
+#else
 	system("apm -S");
+#endif
 	usleep(2000000L);
 
    } else if (x>=46 && y>=48 && x<=58 && y<=58){
@@ -671,7 +723,31 @@
 	 */
 	copyXPMArea(21, 106, 13, 11, 46, 48);
 	RedrawWindow();
+#if FreeBSD
+
+#ifdef HAS_POSIX_SAVED_IDS
+    if (setegid(rgid) == -1)
+		(void) fprintf(stderr, "setegid(%d): %s\n",
+					   (int) rgid, strerror(errno));
+    if (seteuid(ruid) == -1)
+		(void) fprintf(stderr, "seteuid(%d): %s\n",
+                       (int) ruid, strerror(errno));
+#endif /* HAS_POSIX_SAVED_IDS */
+
+	system("apm -z");
+#ifdef HAS_POSIX_SAVED_IDS
+    if (seteuid(euid) == -1)
+        (void) fprintf(stderr, "seteuid(%d): %s\n",
+					   (int) euid, strerror(errno));
+
+    if (setegid(egid) == -1)
+		(void) fprintf(stderr, "setegid(%d): %s\n",
+					   (int) egid, strerror(errno));
+#endif
+
+#else
 	system("apm -s");
+#endif
 	usleep(2000000L);
 
    }
@@ -693,7 +769,11 @@
 int apm_exists()
 {
 
+#if FreeBSD
+	if (open(APMDEV, O_RDONLY) == -1)
+#else
     if (access(APMDEV, R_OK))
+#endif
 
 	/*
 	 *  Cannot find /proc/apm
