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 --- contrib/coccinelle/xopen.cocci | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 contrib/coccinelle/xopen.cocci (limited to 'contrib') diff --git a/contrib/coccinelle/xopen.cocci b/contrib/coccinelle/xopen.cocci new file mode 100644 index 0000000000..814d7b8a1a --- /dev/null +++ b/contrib/coccinelle/xopen.cocci @@ -0,0 +1,16 @@ +@@ +identifier fd; +identifier die_fn =~ "^(die|die_errno)$"; +@@ +( + fd = +- open ++ xopen + (...); +| + int fd = +- open ++ xopen + (...); +) +- if ( \( fd < 0 \| fd == -1 \) ) { die_fn(...); } -- cgit v1.2.3