mirror of
https://github.com/javalsai/lidm.git
synced 2025-07-03 22:38:41 +02:00
fix: create directory
This commit is contained in:
parent
16d1325f96
commit
f0e962ad50
@ -3,6 +3,7 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
struct LaunchState {
|
||||
int user_opt;
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Small file for saving last selection
|
||||
|
||||
#define STATE_PATH "/var/lib/lidm/state"
|
||||
#define STATE_DIR "/var/lib/lidm"
|
||||
#define STATE_FILE "/var/lib/lidm/state"
|
||||
|
||||
#include "launch_state.h"
|
||||
|
||||
@ -8,8 +9,8 @@ struct LaunchState read_launch_state() {
|
||||
struct LaunchState state;
|
||||
state.user_opt = 1;
|
||||
state.session_opt = 1;
|
||||
FILE* state_fd = fopen(STATE_PATH, "r");
|
||||
if (!state_fd) return state;
|
||||
FILE* state_fd = fopen(STATE_FILE, "r");
|
||||
if (state_fd == NULL) return state;
|
||||
if (fscanf(state_fd, "%i;%i", &state.user_opt, &state.session_opt) != 2) {
|
||||
state.user_opt = 1;
|
||||
state.session_opt = 1;
|
||||
@ -19,8 +20,12 @@ struct LaunchState read_launch_state() {
|
||||
}
|
||||
|
||||
bool write_launch_state(struct LaunchState state) {
|
||||
FILE* state_fd = fopen(STATE_PATH, "w");
|
||||
if (!state_fd) return false;
|
||||
FILE* state_fd = fopen(STATE_FILE, "w");
|
||||
if (state_fd == NULL) {
|
||||
if (mkdir(STATE_DIR, 0755) == -1) return false;
|
||||
state_fd = fopen(STATE_FILE, "w");
|
||||
if (state_fd == NULL) return false;
|
||||
}
|
||||
(void)fprintf(state_fd, "%i;%i", state.user_opt, state.session_opt);
|
||||
(void)fclose(state_fd);
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user