13
0

Replaced broken code in recent_sessions.cc

The original broken code was intended to stop using ifstream
and ofstream to open files, but it used a very old MSVCism to
open streams from FILE*.

In the case for reading, this patch replaces that code by using
standard c file manipulation to read the data into a stringstream,
and then it uses the existing stream-based code to read from there.

Similarly the ofstream in the code for writing the recent files list
is replaced by a stringstream, and then a c-string is extracted
from it and written using standard c file manipulation.

Also tweaked a couple of typos from rgareus :)
This commit is contained in:
Guy Sherman 2015-09-08 22:28:30 +02:00 committed by Robin Gareus
parent 929db238c9
commit 036ebab8a0

View File

@ -21,6 +21,7 @@
#include <cerrno> #include <cerrno>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <sstream>
#include <algorithm> #include <algorithm>
#include <glib/gstdio.h> #include <glib/gstdio.h>
@ -60,7 +61,26 @@ ARDOUR::read_recent_sessions (RecentSessions& rs)
} }
} }
ifstream recent (fin);
// Read the file into a std::string;
std::stringstream recent;
char temporaryBuffer[1024];
while (!feof(fin))
{
size_t charsRead = fread(&temporaryBuffer[0], sizeof(char), 1024, fin);
if (charsRead != 1024 && ferror(fin))
{
error << string_compose (_("Error reading recent session file %1 (%2)"), path, strerror (errno)) << endmsg;
fclose(fin);
return -1;
}
recent << &temporaryBuffer[0];
}
//ifstream recent (fin);
while (true) { while (true) {
@ -131,18 +151,33 @@ ARDOUR::write_recent_sessions (RecentSessions& rs)
} }
{ {
ofstream recent (fout); stringstream recent;
//ofstream recent (fout);
if (!recent) { // if (!recent) {
fclose (fout); // fclose (fout);
return -1; // return -1;
} // }
for (RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) { for (RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
recent << (*i).first << '\n' << (*i).second << endl; recent << (*i).first << '\n' << (*i).second << endl;
} }
string recentString = recent.str();
size_t writeSize = recentString.length();
fwrite(recentString.c_str(), sizeof(char), writeSize, fout);
if (ferror(fout))
{
error << string_compose (_("Error writing recent sessions file %1 (%2)"), recent_file_name, strerror (errno)) << endmsg;
fclose(fout);
return -1;
}
} }
fclose (fout); fclose (fout);
return 0; return 0;
@ -239,4 +274,3 @@ ARDOUR::remove_recent_sessions (const string& path)
return 1; return 1;
} }
} }