summaryrefslogtreecommitdiff
path: root/builtin/init-db.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2014-11-30 08:24:46 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-12-01 19:00:16 (GMT)
commit91aacda85a91192a9f66a0f175d739f77971412f (patch)
treebeda5513b104a9f6a5295135250e4d70ee80d2ca /builtin/init-db.c
parent316e53e68c7c4d89876524f7f010685ebfe7be1e (diff)
downloadgit-91aacda85a91192a9f66a0f175d739f77971412f.zip
git-91aacda85a91192a9f66a0f175d739f77971412f.tar.gz
git-91aacda85a91192a9f66a0f175d739f77971412f.tar.bz2
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 'builtin/init-db.c')
-rw-r--r--builtin/init-db.c7
1 files changed, 1 insertions, 6 deletions
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 587a505..6b7fa5f 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -342,7 +342,6 @@ int set_git_dir_init(const char *git_dir, const char *real_git_dir,
static void separate_git_dir(const char *git_dir)
{
struct stat st;
- FILE *fp;
if (!stat(git_link, &st)) {
const char *src;
@@ -358,11 +357,7 @@ static void separate_git_dir(const char *git_dir)
die_errno(_("unable to move %s to %s"), src, git_dir);
}
- fp = fopen(git_link, "w");
- if (!fp)
- die(_("Could not create git link %s"), git_link);
- fprintf(fp, "gitdir: %s\n", git_dir);
- fclose(fp);
+ write_file(git_link, 1, "gitdir: %s\n", git_dir);
}
int init_db(const char *template_dir, unsigned int flags)