aboutsummaryrefslogtreecommitdiff
path: root/setbkl.c
blob: 05a7ffb5fe4e58c298dca0f4c7fec873f3b6d0bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// SPDX-License-Identifier: BSD-2-Clause

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <glob.h>

int
main(int argc, char **argv)
{
	if (argc != 2) {
		dprintf(2, "%s: missing brightness argument\n", argv[0]);
		return 1;
	}

	int fd = open("/sys/class/backlight/apple-panel-bl/brightness", O_WRONLY);
	if (fd == -1) {
		dprintf(2, "%s: can't open\n", argv[0]);
		return 6;
	}
	ssize_t wl = (write(fd, argv[1], strlen(argv[1])));
	if (wl == -1) {
		dprintf(2, "%s: can't write\n", argv[0]);
		return 7;
	} else if ((size_t)wl == strlen(argv[1])) {
	} else {
		dprintf(2, "%s: incomplete write\n", argv[0]);
		return 8;
	}
	if (close(fd) == -1) {
		dprintf(2, "%s: can't close\n", argv[0]);
		return 9;
	}

	return 0;
}