1N/A/***************************************************************************
1N/A *
1N/A * hal-system-lcd-get-brightness-sunos.c : Get LCD brightness
1N/A *
1N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
1N/A * Use is subject to license terms.
1N/A *
1N/A * Licensed under the Academic Free License version 2.1
1N/A *
1N/A **************************************************************************/
1N/A
1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A#ifdef HAVE_CONFIG_H
1N/A#include <config.h>
1N/A#endif
1N/A
1N/A#include <errno.h>
1N/A#include <string.h>
1N/A#include <strings.h>
1N/A#include <ctype.h>
1N/A#include <stdlib.h>
1N/A#include <stdio.h>
1N/A#include <sys/ioctl.h>
1N/A#include <fcntl.h>
1N/A#include <unistd.h>
1N/A#include "../../hald/util.h"
1N/A#include <sys/acpi_drv.h>
1N/A
1N/Aint
1N/Amain(int argc, char *argv[])
1N/A{
1N/A struct acpi_drv_output_status status;
1N/A int fd = -1;
1N/A char *udi;
1N/A char device_file[HAL_PATH_MAX] = "/devices";
1N/A char *devfs_path;
1N/A
1N/A if ((udi = getenv("UDI")) == NULL) {
1N/A return (-1);
1N/A }
1N/A if ((devfs_path = getenv("HAL_PROP_SOLARIS_DEVFS_PATH")) == NULL) {
1N/A return (-1);
1N/A }
1N/A
1N/A strlcat(device_file, devfs_path, HAL_PATH_MAX);
1N/A fprintf(stderr, "Getting brightness on %s (udi=%s)",
1N/A device_file, udi);
1N/A if ((fd = open(device_file, O_RDONLY | O_NONBLOCK)) < 0) {
1N/A fprintf(stderr, "Cannot open %s: %s", device_file,
1N/A strerror(errno));
1N/A return (-1);
1N/A }
1N/A
1N/A bzero(&status, sizeof (status));
1N/A if (ioctl(fd, ACPI_DRV_IOC_STATUS, &status) < 0) {
1N/A close(fd);
1N/A return (-1);
1N/A } else {
1N/A close(fd);
1N/A return (status.cur_level_index);
1N/A }
1N/A}