backlight: fix FreeBSD implementation new-api

Wed, 29 Jan 2020 06:03:40 +0100

author
David Demelier <markand@malikania.fr>
date
Wed, 29 Jan 2020 06:03:40 +0100
changeset 18
281cc3a22f1b
parent 17
37d1b7dd73ee
child 19
0de3886f98ad

backlight: fix FreeBSD implementation

backlight.c file | annotate | diff | comparison | revisions
--- a/backlight.c	Fri Oct 11 14:18:17 2019 +0200
+++ b/backlight.c	Wed Jan 29 06:03:40 2020 +0100
@@ -129,16 +129,21 @@
 	int levels[200] = {0};
 	size_t length = sizeof (levels);
 
-	if (sysctlbyname("hw.acpi.video.lcd0.levels", levels, &length, NULL, 0) == -1)
+	if (sysctlbyname("hw.acpi.video.lcd0.levels", levels, &length, NULL, 0) < 0)
 		die("sysctl: %s\n", strerror(errno));
 
+	length /= sizeof (int);
+
 	/* Find appropriate nearest level */
 	if (percent > 0 && percent < 100) {
 		sort(levels, length);
 		percent = levels[upper_bound(levels, length, percent)];
 	}
 
-	printf("===> setting level to %u\n", percent);
+	if (sysctlbyname("hw.acpi.video.lcd0.brightness", NULL, NULL,
+	    &percent, sizeof (int)) < 0)
+		die("sysctl: %s\n", strerror(errno));
+
 }
 
 static unsigned int
@@ -316,7 +321,7 @@
 	++ argv;
 
 	if (argc < 1)
-		usage(argv[0]);
+		usage("backlight");
 
 	if (strcmp(argv[0], "get") == 0)
 		printf("%d\n", get());

mercurial