From 96793d262b6128bf2814d7f96c9ac2671e6d6c0a Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Sat, 20 Aug 2011 00:58:09 +0100 Subject: [PATCH] Fix FileOps::touch() creat() returns -1 on error or an fd otherwise which should be closed. --- src/FileOps.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/FileOps.cpp b/src/FileOps.cpp index f6d3c52..8497d12 100644 --- a/src/FileOps.cpp +++ b/src/FileOps.cpp @@ -194,7 +194,12 @@ void FileOps::touch(const char* path) throw (IOException) { #ifdef PLATFORM_UNIX // see http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html - if (creat(path,S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) != 0) + int fd = creat(path,S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + if (fd != -1) + { + close(fd); + } + else { throw IOException("Unable to touch file " + std::string(path)); }