Commit a46d1522 authored by miloyip's avatar miloyip

Merge branch 'master' into issue120floatprecision

parents d8a51bf2 1fafc38e
...@@ -158,9 +158,7 @@ protected: ...@@ -158,9 +158,7 @@ protected:
// Test FileWriteStream // Test FileWriteStream
{ {
char filename[L_tmpnam]; char filename[L_tmpnam];
TempFilename(filename); FILE* fp = TempFile(filename);
FILE *fp = fopen(filename, "wb");
char buffer[16]; char buffer[16];
FileWriteStream os(fp, buffer, sizeof(buffer)); FileWriteStream os(fp, buffer, sizeof(buffer));
EncodedOutputStream<FileEncoding, FileWriteStream> eos(os, putBOM); EncodedOutputStream<FileEncoding, FileWriteStream> eos(os, putBOM);
...@@ -193,9 +191,8 @@ protected: ...@@ -193,9 +191,8 @@ protected:
// Test FileWriteStream // Test FileWriteStream
{ {
char filename[L_tmpnam]; char filename[L_tmpnam];
TempFilename(filename); FILE* fp = TempFile(filename);
FILE *fp = fopen(filename, "wb");
char buffer[16]; char buffer[16];
FileWriteStream os(fp, buffer, sizeof(buffer)); FileWriteStream os(fp, buffer, sizeof(buffer));
AutoUTFOutputStream<unsigned, FileWriteStream> eos(os, type, putBOM); AutoUTFOutputStream<unsigned, FileWriteStream> eos(os, type, putBOM);
......
...@@ -98,9 +98,8 @@ TEST_F(FileStreamTest, FileReadStream) { ...@@ -98,9 +98,8 @@ TEST_F(FileStreamTest, FileReadStream) {
TEST_F(FileStreamTest, FileWriteStream) { TEST_F(FileStreamTest, FileWriteStream) {
char filename[L_tmpnam]; char filename[L_tmpnam];
TempFilename(filename); FILE* fp = TempFile(filename);
FILE *fp = fopen(filename, "wb");
char buffer[65536]; char buffer[65536];
FileWriteStream os(fp, buffer, sizeof(buffer)); FileWriteStream os(fp, buffer, sizeof(buffer));
for (size_t i = 0; i < length_; i++) for (size_t i = 0; i < length_; i++)
......
...@@ -67,13 +67,21 @@ inline Ch* StrDup(const Ch* str) { ...@@ -67,13 +67,21 @@ inline Ch* StrDup(const Ch* str) {
return buffer; return buffer;
} }
inline void TempFilename(char *filename) { inline FILE* TempFile(char *filename) {
#if _MSC_VER
filename = tmpnam(filename); filename = tmpnam(filename);
// For Visual Studio, tmpnam() adds a backslash in front. Remove it. // For Visual Studio, tmpnam() adds a backslash in front. Remove it.
if (filename[0] == '\\') if (filename[0] == '\\')
for (int i = 0; filename[i] != '\0'; i++) for (int i = 0; filename[i] != '\0'; i++)
filename[i] = filename[i + 1]; filename[i] = filename[i + 1];
return fopen(filename, "wb");
#else
strcpy(filename, "/tmp/fileXXXXXX");
int fd = mkstemp(filename);
return fdopen(fd, "w");
#endif
} }
// Use exception for catching assert // Use exception for catching assert
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment