Fix FileOps::touch()

creat() returns -1 on error or an fd otherwise which should be closed.
This commit is contained in:
Robert Knight 2011-08-20 00:58:09 +01:00
parent 8df91a76eb
commit 96793d262b

View file

@ -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));
}