git » drill.git » commit f65c43b

Handle errors when closing the file

author Rodrigo Campos
2014-01-20 15:37:16 UTC
committer Rodrigo Campos
2014-01-20 16:56:23 UTC
parent 17eac901cb9a07a5409022a4f060f7582639f860

Handle errors when closing the file

close() can easily fail if a previous write failed, or if it's interrupted by a
signal. So, let's handle those errors.

Signed-off-by: Rodrigo Campos <rodrigo@sdfg.com.ar>

drill.c +6 -1

diff --git a/drill.c b/drill.c
index d9da017..54ddce2 100644
--- a/drill.c
+++ b/drill.c
@@ -164,6 +164,11 @@ int main(int argc, char **argv)
 
 	int ret = drill(fd, hole_size);
 
-	close(fd);
+	int err = close(fd);
+	if (err) {
+		perror("write failed");
+		ret = 1;
+	}
+
 	return ret;
 }