builtin-blame.c: use strbuf_readlink()
When faking a commit out of the work tree contents, use strbuf_readlink() to read the contents of symbolic links. Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Junio C Hamano committed
Dec 17, 2008 at 12:37 UTC
edfd45d2a0fc85d55479e13e8e3dc7e975a313ce
1 file changed
+1
-4
builtin-blame.c
+1
-4
@@ -1996,7 +1996,6 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
1996
if (!contents_from || strcmp("-", contents_from)) {
1997
struct stat st;
1998
const char *read_from;
1999
- unsigned long fin_size;
1999
2000
if (contents_from) {
2001
if (stat(contents_from, &st) < 0)
@@ -2008,7 +2007,6 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
2007
die("Cannot lstat %s", path);
2008
read_from = path;
2009
}
2011
- fin_size = xsize_t(st.st_size);
2010
mode = canon_mode(st.st_mode);
2011
switch (st.st_mode & S_IFMT) {
2012
case S_IFREG:
@@ -2016,9 +2014,8 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
2014
die("cannot open or read %s", read_from);
2015
break;
2016
case S_IFLNK:
2019
- if (readlink(read_from, buf.buf, buf.alloc) != fin_size)
2017
+ if (strbuf_readlink(&buf, read_from, st.st_size) < 0)
2018
die("cannot readlink %s", read_from);
2021
- buf.len = fin_size;
2019
break;
2020
default:
2021
die("unsupported file type %s", read_from);