xref: /titanic_41/usr/src/cmd/hal/tools/sunos/hal-system-lcd-get-brightness-sunos.c (revision d5ace9454616652a717c9831d949dffa319381f9)
1 /***************************************************************************
2  *
3  * hal-system-lcd-get-brightness-sunos.c : Get LCD brightness
4  *
5  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
6  * Use is subject to license terms.
7  *
8  * Licensed under the Academic Free License version 2.1
9  *
10  **************************************************************************/
11 
12 #pragma ident	"%Z%%M%	%I%	%E% SMI"
13 
14 #ifdef HAVE_CONFIG_H
15 #include <config.h>
16 #endif
17 
18 #include <errno.h>
19 #include <string.h>
20 #include <strings.h>
21 #include <ctype.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <sys/ioctl.h>
25 #include <fcntl.h>
26 #include <unistd.h>
27 #include "../../hald/util.h"
28 #include <sys/acpi_drv.h>
29 
30 int
31 main(int argc, char *argv[])
32 {
33 	struct acpi_drv_output_status status;
34 	int fd = -1;
35 	char *udi;
36 	char device_file[HAL_PATH_MAX] = "/devices";
37 	char *devfs_path;
38 
39 	if ((udi = getenv("UDI")) == NULL) {
40 		return (-1);
41 	}
42 	if ((devfs_path = getenv("HAL_PROP_SOLARIS_DEVFS_PATH")) == NULL) {
43 		return (-1);
44 	}
45 
46 	strlcat(device_file, devfs_path, HAL_PATH_MAX);
47 	fprintf(stderr, "Getting brightness on %s (udi=%s)",
48 	    device_file, udi);
49 	if ((fd = open(device_file, O_RDONLY | O_NONBLOCK)) < 0) {
50 		fprintf(stderr, "Cannot open %s: %s", device_file,
51 		    strerror(errno));
52 		return (-1);
53 	}
54 
55 	bzero(&status, sizeof (status));
56 	if (ioctl(fd, ACPI_DRV_IOC_STATUS, &status) < 0) {
57 		close(fd);
58 		return (-1);
59 	} else {
60 		close(fd);
61 		return (status.cur_level_index);
62 	}
63 }
64