Skip to content

Commit 5c44252

Browse files
Ramsay Jonesgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 66a51a9 commit 5c44252

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

path.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,14 @@ char *mkpath(const char *fmt, ...)
119119

120120
char *git_path(const char *fmt, ...)
121121
{
122-
const char *git_dir = get_git_dir();
123122
char *pathname = get_pathname();
124123
va_list args;
125-
unsigned len;
124+
char *ret;
126125

127-
len = strlen(git_dir);
128-
if (len > PATH_MAX-100)
129-
return bad_path;
130-
memcpy(pathname, git_dir, len);
131-
if (len && git_dir[len-1] != '/')
132-
pathname[len++] = '/';
133126
va_start(args, fmt);
134-
len += vsnprintf(pathname + len, PATH_MAX - len, fmt, args);
127+
ret = vsnpath(pathname, PATH_MAX, fmt, args);
135128
va_end(args);
136-
if (len >= PATH_MAX)
137-
return bad_path;
138-
return cleanup_path(pathname);
129+
return ret;
139130
}
140131

141132
void home_config_paths(char **global, char **xdg, char *file)

0 commit comments

Comments
 (0)