summary refs log tree commit diff
path: root/.bin/bri.c
diff options
context:
space:
mode:
Diffstat (limited to '.bin/bri.c')
-rwxr-xr-x.bin/bri.c42
1 files changed, 22 insertions, 20 deletions
diff --git a/.bin/bri.c b/.bin/bri.c
index 3995ee2b..4c53475f 100755
--- a/.bin/bri.c
+++ b/.bin/bri.c
@@ -15,16 +15,18 @@ exit
 #include <sysexits.h>
 #include <unistd.h>
 
+static const char *CLASS = "/sys/class/backlight";
+
 int main(int argc, char *argv[]) {
     int error;
 
     if (argc < 2) errx(EX_USAGE, "usage: bri N | +... | -...");
 
-    error = chdir("/sys/class/backlight");
-    if (error) err(EX_IOERR, "/sys/class/backlight");
+    error = chdir(CLASS);
+    if (error) err(EX_IOERR, "%s", CLASS);
 
     DIR *dir = opendir(".");
-    if (!dir) err(EX_IOERR, "opendir");
+    if (!dir) err(EX_IOERR, "%s", CLASS);
 
     struct dirent *entry;
     while (NULL != (errno = 0, entry = readdir(dir))) {
@@ -35,42 +37,42 @@ int main(int argc, char *argv[]) {
         break;
     }
     if (!entry) {
-        if (errno) err(EX_IOERR, "readdir");
-        errx(EX_CONFIG, "empty /sys/class/backlight");
+        if (errno) err(EX_IOERR, "%s", CLASS);
+        errx(EX_CONFIG, "empty %s", CLASS);
     }
 
-    char *bright = argv[1];
+    char *value = argv[1];
 
-    if (bright[0] == '+' || bright[0] == '-') {
+    if (value[0] == '+' || value[0] == '-') {
         FILE *actual = fopen("actual_brightness", "r");
         if (!actual) err(EX_IOERR, "actual_brightness");
 
-        unsigned int current;
-        int match = fscanf(actual, "%u", &current);
-        if (match == EOF) err(EX_IOERR, "fscanf");
-        if (match < 1) err(EX_DATAERR, "fscanf");
+        unsigned int brightness;
+        int match = fscanf(actual, "%u", &brightness);
+        if (match == EOF) err(EX_IOERR, "actual_brightness");
+        if (match < 1) err(EX_DATAERR, "actual_brightness");
 
-        size_t count = strnlen(bright, 15);
-        if (bright[0] == '+') {
-            current += 16 * count;
+        size_t count = strnlen(value, 15);
+        if (value[0] == '+') {
+            brightness += 16 * count;
         } else {
-            current -= 16 * count;
+            brightness -= 16 * count;
         }
 
         char buf[15];
-        snprintf(buf, sizeof(buf), "%u", current);
+        snprintf(buf, sizeof(buf), "%u", brightness);
 
-        bright = buf;
+        value = buf;
     }
 
     error = setuid(0);
-    if (error) err(EX_NOPERM, "setuid");
+    if (error) err(EX_NOPERM, "setuid(0)");
 
     FILE *brightness = fopen("brightness", "w");
     if (!brightness) err(EX_IOERR, "brightness");
 
-    int count = fprintf(brightness, "%s", bright);
-    if (count < 0) err(EX_IOERR, "fprintf");
+    int count = fprintf(brightness, "%s", value);
+    if (count < 0) err(EX_IOERR, "brightness");
 
     return EX_OK;
 }