Fix error handling in gmx_tmpnam
authorOlivier Fisette <ofisette@gmail.com>
Sun, 26 Apr 2015 13:54:27 +0000 (15:54 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Thu, 30 Apr 2015 12:01:47 +0000 (14:01 +0200)
The return code of mkstemp was being mis-used for error handling.
This could explain some long-standing issues with (e.g.) DSSP
mysteriously not working even when the user had done everything right.

Fixes #1717

Change-Id: I72b385a751b99c3f49d99a14bfc6964ad776c22d

src/gromacs/fileio/futil.cpp

index a93bf6f1f0a6a55ddda9693fb51e426c874d15a1..17134292a61fbb64c360a023043b8fa0218e6c25 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -851,19 +851,10 @@ void gmx_tmpnam(char *buf)
 #else
     int fd = mkstemp(buf);
 
-    switch (fd)
+    if (fd < 0)
     {
-        case EINVAL:
-            gmx_fatal(FARGS, "Invalid template %s for mkstemp", buf);
-            break;
-        case EEXIST:
-            gmx_fatal(FARGS, "mkstemp created existing file", buf);
-            break;
-        case EACCES:
-            gmx_fatal(FARGS, "Permission denied for opening %s", buf);
-            break;
-        default:
-            break;
+        gmx_fatal(FARGS, "Creating temporary file %s: %s", buf,
+                  strerror(errno));
     }
     close(fd);
 #endif