1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-31 10:46:08 +02:00

combine-diff.c: use strbuf_readlink()

When showing combined diff using work tree contents, use strbuf_readlink()
to read symbolic links.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Junio C Hamano 2008-12-17 12:37:58 -08:00
parent edfd45d2a0
commit 912342d9d6

View File

@ -703,15 +703,15 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
goto deleted_file; goto deleted_file;
if (S_ISLNK(st.st_mode)) { if (S_ISLNK(st.st_mode)) {
size_t len = xsize_t(st.st_size); struct strbuf buf = STRBUF_INIT;
result_size = len;
result = xmalloc(len + 1); if (strbuf_readlink(&buf, elem->path, st.st_size) < 0) {
if (result_size != readlink(elem->path, result, len)) {
error("readlink(%s): %s", elem->path, error("readlink(%s): %s", elem->path,
strerror(errno)); strerror(errno));
return; return;
} }
result[len] = 0; result_size = buf.len;
result = strbuf_detach(&buf, NULL);
elem->mode = canon_mode(st.st_mode); elem->mode = canon_mode(st.st_mode);
} }
else if (0 <= (fd = open(elem->path, O_RDONLY)) && else if (0 <= (fd = open(elem->path, O_RDONLY)) &&