use the safer mkstemp instead of tmpnam
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4839 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
069aa18e9f
commit
ab5977c0ad
2 changed files with 13 additions and 9 deletions
|
@ -29,6 +29,7 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
@ -108,21 +109,22 @@ namespace POSIX {
|
||||||
return string(buffer);
|
return string(buffer);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
//#ifdef POSIX
|
|
||||||
// This is a POSIX version of the function, together with #include <stdio.h>
|
|
||||||
// but I will not add it in a final release version.
|
|
||||||
string getTempFile() {
|
string getTempFile() {
|
||||||
char filebuf [L_tmpnam];
|
char t[] = "/tmp/genpatXXXXXX";
|
||||||
|
|
||||||
// create a temporary filename
|
mode_t old_umask = umask(0077);
|
||||||
const char *fname = tmpnam (filebuf);
|
|
||||||
|
|
||||||
if (!fname)
|
int fd = mkstemp(t);
|
||||||
|
if (fd == -1) {
|
||||||
cerr << "Cannot create temporary filename";
|
cerr << "Cannot create temporary filename";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
|
||||||
return string(fname);
|
umask(old_umask);
|
||||||
|
|
||||||
|
return string(t);
|
||||||
}
|
}
|
||||||
//#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,6 +166,8 @@ int main( int argc, char * argv[] ) {
|
||||||
targetCRC->mode = TChecksum::MD5; // default
|
targetCRC->mode = TChecksum::MD5; // default
|
||||||
|
|
||||||
string tempFileName = POSIX::getTempFile();
|
string tempFileName = POSIX::getTempFile();
|
||||||
|
if (tempFileName == "")
|
||||||
|
return 2;
|
||||||
|
|
||||||
// open the files
|
// open the files
|
||||||
bifstream source;
|
bifstream source;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue