Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim trailing whitespace in config file #342

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,19 @@ static char *get_config_path(void) {
return NULL;
}

static void trim_end(char *str) {
if (strlen(str) == 0) {
return;
}

char* end = str + strlen(str) - 1;
while (end > str && isspace((unsigned char)*end)) {
end--;
}

*(end + 1) = '\0';
}

static int load_config(char *path, struct swaylock_state *state,
enum line_mode *line_mode) {
FILE *config = fopen(path, "r");
Expand All @@ -1043,6 +1056,8 @@ static int load_config(char *path, struct swaylock_state *state,
continue;
}

trim_end(line);

swaylock_log(LOG_DEBUG, "Config Line #%d: %s", line_number, line);
char *flag = malloc(nread + 3);
if (flag == NULL) {
Expand Down