You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2013/03/23 00:12:31 UTC

svn commit: r1460052 - /incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp

Author: vinodkone
Date: Fri Mar 22 23:12:31 2013
New Revision: 1460052

URL: http://svn.apache.org/r1460052
Log:
Fixed os::mktemp to use mkstemp, instead of the deprecated mktemp
syscall.

From: Ben Mahler <be...@gmail.com>
Review: https://reviews.apache.org/r/10074

Modified:
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp

Modified: incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp?rev=1460052&r1=1460051&r2=1460052&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/os.hpp Fri Mar 22 23:12:31 2013
@@ -202,14 +202,21 @@ inline Try<Nothing> touch(const std::str
 inline Try<std::string> mktemp(const std::string& path = "/tmp/XXXXXX")
 {
   char* temp = new char[path.size() + 1];
-  if (::mktemp(::strcpy(temp, path.c_str())) != NULL) {
-    std::string result(temp);
-    delete temp;
-    return result;
-  } else {
+  int fd = ::mkstemp(::strcpy(temp, path.c_str()));
+
+  if (fd < 0) {
     delete temp;
     return ErrnoError();
   }
+
+  // We ignore the return value of close(). This is because users
+  // calling this function are interested in the return value of
+  // mkstemp(). Also an unsuccessful close() doesn't affect the file.
+  os::close(fd);
+
+  std::string result(temp);
+  delete temp;
+  return result;
 }
 
 
@@ -249,9 +256,9 @@ inline Try<Nothing> write(const std::str
 
   Try<Nothing> result = write(fd.get(), message);
 
-  // NOTE: We ignore the return value of close(). This is because users calling
-  // this function are interested in the return value of write(). Also an
-  // unsuccessful close() doesn't affect the write.
+  // We ignore the return value of close(). This is because users
+  // calling this function are interested in the return value of
+  // mkstemp(). Also an unsuccessful close() doesn't affect the write.
   os::close(fd.get());
 
   return result;
@@ -661,6 +668,7 @@ inline std::string getcwd()
 }
 
 
+// TODO(bmahler): Wrap with a Try.
 inline std::list<std::string> ls(const std::string& directory)
 {
   std::list<std::string> result;