summaryrefslogtreecommitdiff
path: root/libs/ardour/recent_sessions.cc
diff options
context:
space:
mode:
authorGuy Sherman <guy@guysherman.com>2015-09-08 22:28:30 +0200
committerRobin Gareus <robin@gareus.org>2015-09-08 22:29:20 +0200
commit036ebab8a0452bd3cd20bae3d0281ff39b2b6a87 (patch)
tree4208ef91673b69fedab6ce857b98c538042327b6 /libs/ardour/recent_sessions.cc
parent929db238c911f9c8d451e62c8e3834e3d39fc426 (diff)
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 :)
Diffstat (limited to 'libs/ardour/recent_sessions.cc')
-rw-r--r--libs/ardour/recent_sessions.cc48
1 files 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 <cerrno>
#include <fstream>
#include <iostream>
+#include <sstream>
#include <algorithm>
#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) {
@@ -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;
}
}
-