8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / hal / tools / sunos / hal-system-lcd-set-brightness-sunos.c
blobd3e7fa0988f787aeb496fb3cc4f3c1308e3bdad6
1 /***************************************************************************
3 * hal-system-lcd-set-brightness-sunos.c : Set LCD brightness
5 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
6 * Use is subject to license terms.
8 * Licensed under the Academic Free License version 2.1
10 **************************************************************************/
12 #pragma ident "%Z%%M% %I% %E% SMI"
14 #ifdef HAVE_CONFIG_H
15 #include <config.h>
16 #endif
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 <sys/acpi_drv.h>
28 #include "../../hald/util.h"
30 int
31 main(int argc, char *argv[])
33 char arg[10];
34 int level;
35 int fd = -1;
36 char *udi;
37 char device_file[HAL_PATH_MAX] = "/devices";
38 char *devfs_path;
40 if ((udi = getenv("UDI")) == NULL) {
41 return (1);
43 if ((devfs_path = getenv("HAL_PROP_SOLARIS_DEVFS_PATH")) == NULL) {
44 return (1);
46 strlcat(device_file, devfs_path, HAL_PATH_MAX);
47 fprintf(stderr, "Setting brightness on %s (udi=%s)",
48 device_file, udi);
50 if ((fd = open(device_file, O_RDONLY | O_NONBLOCK)) < 0) {
51 fprintf(stderr, "Cannot open %s: %s", device_file,
52 strerror(errno));
53 return (1);
55 if (fgets(arg, sizeof (arg), stdin)) {
56 level = atoi(arg);
58 if (ioctl(fd, ACPI_DRV_IOC_SET_BRIGHTNESS, &level) < 0) {
59 close(fd);
60 return (1);
61 } else {
62 close(fd);
63 return (0);