mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
path.c: Use vsnpath() in the implementation of git_path()
The current implementation of git_path() is essentially the same as that of vsnpath(), with two minor differences. First, git_path() currently insists that the git directory path is no longer than PATH_MAX-100 characters in length. However, vsnpath() does not attempt this arbitrary 100 character reservation for the remaining path components. Second, vsnpath() uses the "is_dir_sep()" macro, rather than comparing directly to '/', to determine if the git_dir path component ends with a path separator. In order to benefit from the above improvements, along with increased compatability with git_snpath() and git_pathdup(), we reimplement the git_path() function using vsnpath(). Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
66a51a9aae
commit
5c44252e13
15
path.c
15
path.c
@@ -119,23 +119,14 @@ char *mkpath(const char *fmt, ...)
|
|||||||
|
|
||||||
char *git_path(const char *fmt, ...)
|
char *git_path(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
const char *git_dir = get_git_dir();
|
|
||||||
char *pathname = get_pathname();
|
char *pathname = get_pathname();
|
||||||
va_list args;
|
va_list args;
|
||||||
unsigned len;
|
char *ret;
|
||||||
|
|
||||||
len = strlen(git_dir);
|
|
||||||
if (len > PATH_MAX-100)
|
|
||||||
return bad_path;
|
|
||||||
memcpy(pathname, git_dir, len);
|
|
||||||
if (len && git_dir[len-1] != '/')
|
|
||||||
pathname[len++] = '/';
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
len += vsnprintf(pathname + len, PATH_MAX - len, fmt, args);
|
ret = vsnpath(pathname, PATH_MAX, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
if (len >= PATH_MAX)
|
return ret;
|
||||||
return bad_path;
|
|
||||||
return cleanup_path(pathname);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void home_config_paths(char **global, char **xdg, char *file)
|
void home_config_paths(char **global, char **xdg, char *file)
|
||||||
|
|||||||
Reference in New Issue
Block a user