From 124ef7fe3d1ec2db9dbcf0a593ee9033fba54e92 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Tue, 4 Jan 2022 23:10:14 +0100 Subject: [PATCH] Move the backslash replacement out into a separate function --- src/main.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main.c b/src/main.c index 47081c1b..94222f56 100644 --- a/src/main.c +++ b/src/main.c @@ -302,6 +302,17 @@ static void cleanup_main(void) cleanup_config(); } +static void replace_backslashes(char *s) +{ + // Replace all backslashes with forward slashes + for (int i = 0; i < strlen(s); i++) { + if (s[i] == '\\') { + s[i] = '/'; + } + } +} + + /* * main routine */ @@ -667,17 +678,7 @@ int main(int argc, char * argv []) // Make sure the string is null terminated executable_abspath[executable_abspath_len] = '\0'; - // Replace all backslashes with forward slashes - i = 0; - while (true) { - if (executable_abspath[i] == '\0') { - break; - } - if (executable_abspath[i] == '\\') { - executable_abspath[i] = '/'; - } - i++; - } + replace_backslashes(executable_abspath); // Define 'executable_dirpath' to be the path to the parent folder of the // executable.