path: root/builtin/init-db.c
diff options
authorNguyễn Thái Ngọc Duy <>2014-11-30 08:24:46 (GMT)
committerJunio C Hamano <>2014-12-01 19:00:16 (GMT)
commit91aacda85a91192a9f66a0f175d739f77971412f (patch)
treebeda5513b104a9f6a5295135250e4d70ee80d2ca /builtin/init-db.c
parent316e53e68c7c4d89876524f7f010685ebfe7be1e (diff)
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 <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/init-db.c')
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)