diff --git a/Contrib/VPatch/Source/GenPat/POSIXUtil.cpp b/Contrib/VPatch/Source/GenPat/POSIXUtil.cpp index 27368542..111a87e1 100644 --- a/Contrib/VPatch/Source/GenPat/POSIXUtil.cpp +++ b/Contrib/VPatch/Source/GenPat/POSIXUtil.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -108,21 +109,22 @@ namespace POSIX { return string(buffer); } #else -//#ifdef POSIX - // This is a POSIX version of the function, together with #include - // but I will not add it in a final release version. string getTempFile() { - char filebuf [L_tmpnam]; + char t[] = "/tmp/genpatXXXXXX"; - // create a temporary filename - const char *fname = tmpnam (filebuf); + mode_t old_umask = umask(0077); - if (!fname) + int fd = mkstemp(t); + if (fd == -1) { cerr << "Cannot create temporary filename"; + return ""; + } + close(fd); - return string(fname); + umask(old_umask); + + return string(t); } -//#endif #endif } diff --git a/Contrib/VPatch/Source/GenPat/main.cpp b/Contrib/VPatch/Source/GenPat/main.cpp index 68d83a13..c6fcebab 100644 --- a/Contrib/VPatch/Source/GenPat/main.cpp +++ b/Contrib/VPatch/Source/GenPat/main.cpp @@ -166,6 +166,8 @@ int main( int argc, char * argv[] ) { targetCRC->mode = TChecksum::MD5; // default string tempFileName = POSIX::getTempFile(); + if (tempFileName == "") + return 2; // open the files bifstream source;