From 49d384b1eb13ad0f9bb40cf7ad1adce82fc3eaa7 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Wed, 14 Nov 2012 15:10:58 +0100 Subject: [PATCH] ltlcross: diagnose failure to write into temporary files The removes a warning about the return code from write() being ignored. Reported by Thomas Badie. * src/bin/ltlcross.cc (string_to_tmp): Call error() on error. --- src/bin/ltlcross.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/bin/ltlcross.cc b/src/bin/ltlcross.cc index 00fb43591..e4c64489e 100644 --- a/src/bin/ltlcross.cc +++ b/src/bin/ltlcross.cc @@ -502,9 +502,12 @@ namespace string_to_tmp(std::string& str, unsigned n, std::string& tmpname) { int fd = create_tmpfile('i', n, tmpname); - write(fd, str.c_str(), str.size()); - write(fd, "\n", 1); - close(fd); + ssize_t s = str.size(); + if (write(fd, str.c_str(), s) != s + || write(fd, "\n", 1) != 1) + error(2, errno, "failed to write into %s", tmpname.c_str()); + if (close(fd)) + error(2, errno, "failed to close %s", tmpname.c_str()); toclean.push_back(tmpname); }