return true;
}
+char *get_active_console(char *out, int len)
+{
+ char line[CMDLINE_SIZE + 1];
+ int fd = open("/sys/class/tty/console/active", O_RDONLY);
+ ssize_t r;
+
+ if (fd < 0)
+ return NULL;
+
+ r = read(fd, line, sizeof(line) - 1);
+ line[CMDLINE_SIZE] = '\0';
+
+ close(fd);
+
+ if (r <= 0)
+ return NULL;
+
+ /* The active file is terminated by a newline which we need to strip */
+ char *newline = strtok(line, "\n");
+
+ if (newline != NULL) {
+ strncpy(out, newline, len);
+ return out;
+ }
+
+ return NULL;
+}
+
char* get_cmdline_val(const char* name, char* out, int len)
{
char line[CMDLINE_SIZE + 1], *c, *sptr;
for (c = strtok_r(line, " \t\n", &sptr); c;
c = strtok_r(NULL, " \t\n", &sptr)) {
char *sep = strchr(c, '=');
+ if (sep == NULL)
+ continue;
+
ssize_t klen = sep - c;
- if (klen < 0 || strncmp(name, c, klen) || name[klen] != 0)
+ if (strncmp(name, c, klen) || name[klen] != 0)
continue;
strncpy(out, &sep[1], len);