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>
This commit is contained in:
committed by
Junio C Hamano
parent
316e53e68c
commit
91aacda85a
@ -764,7 +764,6 @@ static const char edit_description[] = "BRANCH_DESCRIPTION";
|
||||
|
||||
static int edit_branch_description(const char *branch_name)
|
||||
{
|
||||
FILE *fp;
|
||||
int status;
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
struct strbuf name = STRBUF_INIT;
|
||||
@ -777,8 +776,7 @@ static int edit_branch_description(const char *branch_name)
|
||||
" %s\n"
|
||||
"Lines starting with '%c' will be stripped.\n",
|
||||
branch_name, comment_line_char);
|
||||
fp = fopen(git_path(edit_description), "w");
|
||||
if ((fwrite(buf.buf, 1, buf.len, fp) < buf.len) || fclose(fp)) {
|
||||
if (write_file(git_path(edit_description), 0, "%s", buf.buf)) {
|
||||
strbuf_release(&buf);
|
||||
return error(_("could not write branch description template: %s"),
|
||||
strerror(errno));
|
||||
|
||||
Reference in New Issue
Block a user