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