From 036ebab8a0452bd3cd20bae3d0281ff39b2b6a87 Mon Sep 17 00:00:00 2001 From: Guy Sherman Date: Tue, 8 Sep 2015 22:28:30 +0200 Subject: [PATCH] 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 :) --- libs/ardour/recent_sessions.cc | 48 +++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/libs/ardour/recent_sessions.cc b/libs/ardour/recent_sessions.cc index b70d017edc..85c3c55f16 100644 --- a/libs/ardour/recent_sessions.cc +++ b/libs/ardour/recent_sessions.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -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) { @@ -131,18 +151,33 @@ ARDOUR::write_recent_sessions (RecentSessions& rs) } { - ofstream recent (fout); + stringstream recent; + //ofstream recent (fout); - if (!recent) { - fclose (fout); - return -1; - } + // if (!recent) { + // fclose (fout); + // return -1; + // } for (RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) { 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); return 0; @@ -239,4 +274,3 @@ ARDOUR::remove_recent_sessions (const string& path) return 1; } } -