style: formatting and linter satisfaction

This commit is contained in:
rmntgx 2025-06-29 10:56:31 +05:00
parent 1714b477ad
commit 16d1325f96
3 changed files with 33 additions and 28 deletions

View File

@ -1,5 +1,8 @@
#ifndef _LAUNCHSTATEH_
#define _LAUNCHSTATEH_
#ifndef LAUNCHSTATEH_
#define LAUNCHSTATEH_
#include <stdbool.h>
#include <stdio.h>
struct LaunchState {
int user_opt;

View File

@ -1,27 +1,27 @@
// Small file to save last selection
// Small file for saving last selection
#define STATE_PATH "/var/lib/lidm/state"
#include <stdio.h>
#include <stdbool.h>
#include "launch_state.h"
struct LaunchState read_launch_state() {
struct LaunchState state;
state.user_opt = 1;
state.session_opt = 1;
FILE* f = fopen(STATE_PATH, "r");
if(!f) return state;
fscanf(f, "%i;%i", &state.user_opt, &state.session_opt);
fclose(f);
FILE* state_fd = fopen(STATE_PATH, "r");
if (!state_fd) return state;
if (fscanf(state_fd, "%i;%i", &state.user_opt, &state.session_opt) != 2) {
state.user_opt = 1;
state.session_opt = 1;
}
(void)fclose(state_fd);
return state;
}
bool write_launch_state(struct LaunchState state) {
FILE* f = fopen(STATE_PATH, "w");
if(!f) return false;
fprintf(f, "%i;%i", state.user_opt, state.session_opt);
fclose(f);
FILE* state_fd = fopen(STATE_PATH, "w");
if (!state_fd) return false;
(void)fprintf(state_fd, "%i;%i", state.user_opt, state.session_opt);
(void)fclose(state_fd);
return true;
}

View File

@ -20,13 +20,13 @@
#include "auth.h"
#include "efield.h"
#include "keys.h"
#include "launch_state.h"
#include "ofield.h"
#include "sessions.h"
#include "ui.h"
#include "ui_state.h"
#include "users.h"
#include "util.h"
#include "launch_state.h"
const u_char INPUTS_N = 3;
@ -200,7 +200,9 @@ int load(struct Vector* users, struct Vector* sessions) {
of_passwd = ofield_new(0);
struct LaunchState initial_state = read_launch_state();
if(initial_state.user_opt > users->length || initial_state.session_opt > sessions->length + g_config->behavior.include_defshell) {
if (initial_state.user_opt > users->length ||
initial_state.session_opt >
sessions->length + g_config->behavior.include_defshell) {
initial_state.user_opt = 1;
initial_state.session_opt = 1;
}