summaryrefslogtreecommitdiffstats
path: root/usr.sbin/apm/apm.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/apm/apm.c')
-rw-r--r--usr.sbin/apm/apm.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/usr.sbin/apm/apm.c b/usr.sbin/apm/apm.c
index 0e3847d..5c8b1dd 100644
--- a/usr.sbin/apm/apm.c
+++ b/usr.sbin/apm/apm.c
@@ -13,6 +13,12 @@
* Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
*/
+#ifndef lint
+static const char rcsid[] =
+ "$Id$";
+#endif /* not lint */
+
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -23,31 +29,27 @@
#define APMDEV "/dev/apm"
-static char *cmdname;
-
void
usage()
{
- fprintf(stderr, "usage: %s [-ablsz] [-d 1|0]\n", cmdname);
+ fprintf(stderr, "%s\n%s\n",
+ "usage: apm [-ablsz] [-d 1|0]",
+ " zzz");
exit(1);
}
void
apm_suspend(int fd)
{
- if (ioctl(fd, APMIO_SUSPEND, NULL) == -1) {
- perror(cmdname);
- exit(1);
- }
+ if (ioctl(fd, APMIO_SUSPEND, NULL) == -1)
+ err(1, NULL);
}
void
apm_getinfo(int fd, apm_info_t aip)
{
- if (ioctl(fd, APMIO_GETINFO, aip) == -1) {
- perror(cmdname);
- exit(1);
- }
+ if (ioctl(fd, APMIO_GETINFO, aip) == -1)
+ err(1, NULL);
}
void
@@ -93,22 +95,19 @@ print_all_info(apm_info_t aip)
void
apm_display(int fd, int newstate)
{
- if (ioctl(fd, APMIO_DISPLAY, &newstate) == -1) {
- perror(cmdname);
- exit(1);
- }
+ if (ioctl(fd, APMIO_DISPLAY, &newstate) == -1)
+ err(1, NULL);
}
-extern char *optarg;
-extern int optind;
-
int
main(int argc, char *argv[])
{
int c, fd;
int sleep = 0, all_info = 1, apm_status = 0, batt_status = 0;
int display = 0, batt_life = 0, ac_status = 0;
+ char *cmdname;
+
if ((cmdname = strrchr(argv[0], '/')) != NULL)
cmdname++;
@@ -133,7 +132,7 @@ main(int argc, char *argv[])
case 'd':
display = *optarg - '0';
if (display < 0 || display > 1) {
- fprintf(stderr, "%s: Argument of option '-%c' is invalid.\n", cmdname, c);
+ warnx("argument of option '-%c' is invalid", c);
usage();
}
display++;
@@ -161,7 +160,7 @@ main(int argc, char *argv[])
finish_option:
fd = open(APMDEV, O_RDWR);
if (fd == -1) {
- fprintf(stderr, "%s: Can't open %s.\n", cmdname, APMDEV);
+ warnx("can't open %s", APMDEV);
return 1;
}
if (sleep)
OpenPOWER on IntegriCloud