From 66e905b7dd0f4e9dd576be681f30fbaeeb19ec4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Wed, 25 Aug 2021 22:16:46 +0200 Subject: use xopen() to handle fatal open(2) failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add and apply a semantic patch for using xopen() instead of calling open(2) and die() or die_errno() explicitly. This makes the error messages more consistent and shortens the code. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- pack-write.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'pack-write.c') diff --git a/pack-write.c b/pack-write.c index f1fc3ecafa..2767b78619 100644 --- a/pack-write.c +++ b/pack-write.c @@ -75,9 +75,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec index_name = strbuf_detach(&tmp_file, NULL); } else { unlink(index_name); - fd = open(index_name, O_CREAT|O_EXCL|O_WRONLY, 0600); - if (fd < 0) - die_errno("unable to create '%s'", index_name); + fd = xopen(index_name, O_CREAT|O_EXCL|O_WRONLY, 0600); } f = hashfd(fd, index_name); } @@ -256,9 +254,7 @@ const char *write_rev_file_order(const char *rev_name, rev_name = strbuf_detach(&tmp_file, NULL); } else { unlink(rev_name); - fd = open(rev_name, O_CREAT|O_EXCL|O_WRONLY, 0600); - if (fd < 0) - die_errno("unable to create '%s'", rev_name); + fd = xopen(rev_name, O_CREAT|O_EXCL|O_WRONLY, 0600); } f = hashfd(fd, rev_name); } else if (flags & WRITE_REV_VERIFY) { -- cgit v1.2.3