diff options
author | Junio C Hamano <junkio@cox.net> | 2005-12-03 23:46:02 -0800 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2005-12-03 23:46:02 -0800 |
commit | 423325a2d24638ddcc82ce47be5e40be550f4507 (patch) | |
tree | 00960b001d786299d3da04a4467bd0c798bf8cda /git.c | |
parent | 93dcab2937624ebb97f91807576cddb242a55a46 (diff) | |
parent | d79374c7b58d3814ffdc277de608243f8e665e3a (diff) | |
download | git-423325a2d24638ddcc82ce47be5e40be550f4507.tar.gz git-423325a2d24638ddcc82ce47be5e40be550f4507.tar.xz |
Diffstat (limited to 'git.c')
-rw-r--r-- | git.c | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -13,6 +13,10 @@ # define PATH_MAX 4096 #endif +#ifdef NO_SETENV +extern int gitsetenv(char *name, char *value, int overwrite); +#endif + static const char git_usage[] = "Usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--help] COMMAND [ ARGS ]"; @@ -283,16 +287,21 @@ int main(int argc, char **argv, char **envp) len = strlen(git_command); prepend_to_path(git_command, len); - strncat(&git_command[len], "/git-", sizeof(git_command) - len); - len += 5; - strncat(&git_command[len], argv[i], sizeof(git_command) - len); - - if (access(git_command, X_OK)) - usage(exec_path, "'%s' is not a git-command", argv[i]); + len += snprintf(git_command + len, sizeof(git_command) - len, + "/git-%s", argv[i]); + if (sizeof(git_command) <= len) { + fprintf(stderr, "git: command name given is too long (%d)\n", len); + exit(1); + } /* execve() can only ever return if it fails */ execve(git_command, &argv[i], envp); - printf("Failed to run command '%s': %s\n", git_command, strerror(errno)); + + if (errno == ENOENT) + usage(exec_path, "'%s' is not a git-command", argv[i]); + + fprintf(stderr, "Failed to run command '%s': %s\n", + git_command, strerror(errno)); return 1; } |