4 int gitbox_main(int argc
, char **argv
);
6 static void prepend_to_path(const char *dir
, int len
)
8 const char *old_path
= getenv("PATH");
13 old_path
= "/usr/local/bin:/usr/bin:/bin";
15 path_len
= len
+ strlen(old_path
) + 1;
17 path
= xmalloc(path_len
+ 1);
19 memcpy(path
, dir
, len
);
25 memcpy(path
+ len
+ 1, old_path
, path_len
- len
);
27 setenv("PATH", path
, 1);
32 int cmd_box(int argc
, const char **argv
, const char *prefix
)
34 const char *cmd
= argv
[0];
35 char *slash
= strrchr(cmd
, '/');
36 const char *exec_path
= NULL
;
39 * Take the basename of argv[0] as the command
40 * name, and the dirname as the default exec_path
41 * if it's an absolute path and we don't have
52 slash
= strrchr(cmd
, '\\');
62 * We search for git commands in the following order:
64 * - the path of the "git" command if we could find it
69 prepend_to_path(exec_path
, strlen(exec_path
));
70 exec_path
= git_exec_path();
71 prepend_to_path(exec_path
, strlen(exec_path
));
73 return gitbox_main(argc
, argv
);