Commit: 7bced14670d73a48fc528ab2cafd8a6ddf0e0b94
Parent: 244b48cc3ef715e190ecdaac511f302404eb8365
Author: Randy Palamar
Date: Tue, 24 Dec 2024 11:17:48 -0700
backlight.c: use compile time path component lengths
Diffstat:
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/blocks/linux/backlight.c b/blocks/linux/backlight.c
@@ -25,14 +25,19 @@ static BLOCK_INIT_FN(backlight_init)
b->user_data = lbd = push_struct(a, struct linux_backlight_data);
Arena tmp = *a;
- char *path = alloc(&tmp, char, 4096);
- snprintf(path, 4096, "/sys/class/backlight/%s/max_brightness", (char *)b->arg);
- if (pscanf(path, "%ld", &lbd->max_brightness) != 1)
+ Stream path = stream_alloc(&tmp, KB(1));
+ stream_push_s8(&path, s8("/sys/class/backlight/"));
+ stream_push_s8(&path, *(s8 *)b->arg);
+ size sidx = path.write_index;
+ stream_push_s8(&path, s8("/max_brightness"));
+ if (pscanf(stream_ensure_c_str(&path), "%ld", &lbd->max_brightness) != 1)
die("backlight_init: failed to read max brightness\n");
+ path.write_index = sidx;
- i64 len = snprintf(path, 4096, "/sys/class/backlight/%s/brightness", (char *)b->arg);
- lbd->brightness_path = path;
- a->beg += len;
+ stream_push_s8(&path, s8("/brightness"));
+ path.buffer[path.write_index++] = 0;
+ lbd->brightness_path = (char *)path.buffer;
+ a->beg += path.write_index;
backlight_update(b, 0);
add_file_watch(a, lbd->brightness_path, block_index, backlight_update);
diff --git a/config.def.h b/config.def.h
@@ -19,12 +19,15 @@ static struct bat_arg ba = {.bat = s8("BAT0"), .interval = 30};
/* check blocks/date.c for info */
static struct date_arg da = {.fmt = "%R", .interval = 30};
+/* backlight name (/sys/class/backlight/xxx) */
+//static s8 linux_backlight = s8("xxx");
+
/* status block definitions
*
* block description arg (ex)
*
* battery_info battery percentage and status (struct bat_arg *)
- * backlight percentage (char *) backlight name (intel_backlight)
+ * backlight percentage (s8 *) backlight name
* date date and time (struct date_arg *)
*/