diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2014-11-30 15:24:46 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-12-01 11:00:16 -0800 |
commit | 91aacda85a91192a9f66a0f175d739f77971412f (patch) | |
tree | beda5513b104a9f6a5295135250e4d70ee80d2ca /transport.c | |
parent | 316e53e68c7c4d89876524f7f010685ebfe7be1e (diff) | |
download | git-91aacda85a91192a9f66a0f175d739f77971412f.tar.gz |
use new wrapper write_file() for simple file writing
This fixes common problems in these code about error handling,
forgetting to close the file handle after fprintf() fails, or not
printing out the error string..
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'transport.c')
-rw-r--r-- | transport.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/transport.c b/transport.c index 70d38e4c4b..051b7ac175 100644 --- a/transport.c +++ b/transport.c @@ -283,7 +283,6 @@ static int write_one_ref(const char *name, const unsigned char *sha1, { struct strbuf *buf = data; int len = buf->len; - FILE *f; /* when called via for_each_ref(), flags is non-zero */ if (flags && !starts_with(name, "refs/heads/") && @@ -292,10 +291,9 @@ static int write_one_ref(const char *name, const unsigned char *sha1, strbuf_addstr(buf, name); if (safe_create_leading_directories(buf->buf) || - !(f = fopen(buf->buf, "w")) || - fprintf(f, "%s\n", sha1_to_hex(sha1)) < 0 || - fclose(f)) - return error("problems writing temporary file %s", buf->buf); + write_file(buf->buf, 0, "%s\n", sha1_to_hex(sha1))) + return error("problems writing temporary file %s: %s", + buf->buf, strerror(errno)); strbuf_setlen(buf, len); return 0; } |