Skip to content

Commit f459823

Browse files
0xAXgitster
authored andcommitted
exec_cmd.c: use find_last_dir_sep() for code simplification
We are trying to extract dirname from argv0 in the git_extract_argv0_path(). But in the same time, the <git-compat-util.h> provides find_last_dir_sep() to get dirname from a given path. Let's use it instead of loop for the code simplification. Signed-off-by: Alexander Kuleshov <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a2558fb commit f459823

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

exec_cmd.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ const char *git_extract_argv0_path(const char *argv0)
4343

4444
if (!argv0 || !*argv0)
4545
return NULL;
46-
slash = argv0 + strlen(argv0);
4746

48-
while (argv0 <= slash && !is_dir_sep(*slash))
49-
slash--;
47+
slash = find_last_dir_sep(argv0);
5048

51-
if (slash >= argv0) {
49+
if (slash) {
5250
argv0_path = xstrndup(argv0, slash - argv0);
5351
return slash + 1;
5452
}

0 commit comments

Comments
 (0)