Am 28.07.2014 um 21:15 schrieb Jeff King:
On Mon, Jul 28, 2014 at 08:33:55PM +0200, René Scharfe wrote:
const char *absolute_path(const char *path)
{
- static char buf[PATH_MAX + 1];
-
- if (!*path) {
- die("The empty string is not a valid path");
- } else if (is_absolute_path(path)) {
- if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
- die("Too long path: %.*s", 60, path);
- } else {
- size_t len;
- const char *fmt;
- const char *cwd = get_pwd_cwd();
- if (!cwd)
- die_errno("Cannot determine the current working directory");
- len = strlen(cwd);
- fmt = (len > 0 && is_dir_sep(cwd[len - 1])) ? "%s%s" : "%s/%s";
- if (snprintf(buf, PATH_MAX, fmt, cwd, path) >= PATH_MAX)
- die("Too long path: %.*s", 60, path);
- }
- return buf;
+ static struct strbuf sb;
+ strbuf_init(&sb, 0);
+ strbuf_add_absolute_path(&sb, path);
+ return sb.buf;
}
Is it right to strbuf_init here? That means that we are throwing away
the old buffer for each call. I would think you want instead:
static struct strbuf sb = STRBUF_INIT;
strbuf_reset(&sb);
...
I changed it from _reset to _init, but I can't remember why. :( Perhaps
it's the summer heat. Your version makes more sense to me now.
René
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html