summaryrefslogtreecommitdiff
path: root/tools/filesystem.c
diff options
context:
space:
mode:
authorlouis <louis.braun@gmx.de>2015-01-15 13:12:47 +0100
committerlouis <louis.braun@gmx.de>2015-01-15 13:12:47 +0100
commitc7f71f3f2b580714bd9e5a5c773bc2179c0e8567 (patch)
treea39d3efd5494b60964152e559eaead76c7897af5 /tools/filesystem.c
downloadvdr-plugin-weatherforecast-0.0.1.tar.gz
vdr-plugin-weatherforecast-0.0.1.tar.bz2
Initial commit0.0.1
Diffstat (limited to 'tools/filesystem.c')
-rw-r--r--tools/filesystem.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/tools/filesystem.c b/tools/filesystem.c
new file mode 100644
index 0000000..0f04100
--- /dev/null
+++ b/tools/filesystem.c
@@ -0,0 +1,53 @@
+#include <string>
+#include <sstream>
+#include <iostream>
+#include <fstream>
+#include <sys/stat.h>
+#include <time.h>
+#include "filesystem.h"
+
+bool FileExists(const string &fullpath) {
+ struct stat buffer;
+ return (stat (fullpath.c_str(), &buffer) == 0);
+}
+
+bool FileExists(const string &path, const string &name, const string &ext) {
+ stringstream fileName;
+ fileName << path << name << "." << ext;
+ struct stat buffer;
+ return (stat (fileName.str().c_str(), &buffer) == 0);
+}
+
+string ReadFromFile(const string &path) {
+ string line;
+ stringstream content;
+ ifstream myfile (path.c_str());
+ if (myfile.is_open()) {
+ while ( getline (myfile,line) ) {
+ content << line << '\n';
+ }
+ myfile.close();
+ }
+ return content.str();
+}
+
+bool WriteIntoFile(const string &path, const string &content) {
+ if (content.size() < 5)
+ return false;
+ ofstream myfile;
+ myfile.open(path.c_str());
+ if (myfile.is_open()) {
+ myfile << content;
+ myfile.close();
+ return true;
+ }
+ return false;
+}
+
+time_t FileCreationTime(const string &path) {
+ struct stat t_stat;
+ stat(path.c_str(), &t_stat);
+ struct tm * timeinfo = localtime(&t_stat.st_ctime);
+ time_t creationTime = mktime(timeinfo);
+ return creationTime;
+}