aboutsummaryrefslogtreecommitdiff
path: root/src/utility.h
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-04-17 21:51:20 +0200
committerAdrian Kummerländer2014-04-17 21:51:20 +0200
commit9648c804a23278fcdf66e0f78c350e2ddce492ee (patch)
tree3da73f21148ffaa3773abf5cd7a0d35cba76f8e5 /src/utility.h
downloadInputXSLT-9648c804a23278fcdf66e0f78c350e2ddce492ee.tar
InputXSLT-9648c804a23278fcdf66e0f78c350e2ddce492ee.tar.gz
InputXSLT-9648c804a23278fcdf66e0f78c350e2ddce492ee.tar.bz2
InputXSLT-9648c804a23278fcdf66e0f78c350e2ddce492ee.tar.lz
InputXSLT-9648c804a23278fcdf66e0f78c350e2ddce492ee.tar.xz
InputXSLT-9648c804a23278fcdf66e0f78c350e2ddce492ee.tar.zst
InputXSLT-9648c804a23278fcdf66e0f78c350e2ddce492ee.zip
First commit of _InputXSLT_
* quick and dirty proof-of-concept for adding plain-file access to XSLT ** based on Apache Xalan XSLT processor * The idea is to create something like a static counterpart to Symphony CMS * Adding functions to XSLT for file system, plain file and binary file (read)-access * This project aims to test how such functionality can be integrated into XSLT ** if it works it could be developed into a nice static content transformation system * Contrary to the popular opinion I actually like XML and XSLT when used responsibly
Diffstat (limited to 'src/utility.h')
-rw-r--r--src/utility.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/utility.h b/src/utility.h
new file mode 100644
index 0000000..7050cee
--- /dev/null
+++ b/src/utility.h
@@ -0,0 +1,48 @@
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <cstddef>
+#include <cstdio>
+
+namespace {
+
+const int OpenFlags = O_RDONLY;
+const mode_t OpenMode = S_IRUSR | S_IWUSR;
+
+}
+
+std::string readFile(const std::string& path) {
+ int descriptor(
+ open(path.data(), OpenFlags, OpenMode)
+ );
+
+ if ( descriptor == -1 ) {
+ close(descriptor);
+
+ return "io error";
+ } else {
+ struct stat info;
+ fstat(descriptor, &info);
+ const std::size_t size(info.st_size);
+
+ char* buffer(new char[size]);
+
+ ssize_t readSize(read(
+ descriptor,
+ reinterpret_cast<void*>(buffer),
+ size
+ ));
+
+ close(descriptor);
+
+ std::string content(
+ buffer,
+ readSize
+ );
+
+ delete[] buffer;
+
+ return content;
+ }
+}