summaryrefslogtreecommitdiff
path: root/Source/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Library')
-rw-r--r--Source/Library/Common/FileStream.class.cpp1
-rw-r--r--Source/Library/Userland/App/StreamApp.proto.cpp8
-rw-r--r--Source/Library/Userland/Binding/FSNode.class.h22
3 files changed, 31 insertions, 0 deletions
diff --git a/Source/Library/Common/FileStream.class.cpp b/Source/Library/Common/FileStream.class.cpp
index 317a023..e53d11b 100644
--- a/Source/Library/Common/FileStream.class.cpp
+++ b/Source/Library/Common/FileStream.class.cpp
@@ -62,6 +62,7 @@ FileOStream::FileOStream(const String& filename, u8int mode, u8int encoding, FSN
}
FileOStream::~FileOStream() {
+ m_file->close();
delete m_file;
}
diff --git a/Source/Library/Userland/App/StreamApp.proto.cpp b/Source/Library/Userland/App/StreamApp.proto.cpp
index b1dc7dd..90b8221 100644
--- a/Source/Library/Userland/App/StreamApp.proto.cpp
+++ b/Source/Library/Userland/App/StreamApp.proto.cpp
@@ -33,6 +33,14 @@ void StreamApp::init() {
} else {
FileIStream *f = new FileIStream(encoding, FS::cwdNode());
for (u32int i = 0; i < args.size(); i++) {
+ FSNode n = FS::find(args[i], FS::cwdNode());
+ if (!n.valid()) {
+ outvt << "File does not exist : " << args[i] << ENDL;
+ exit(-1);
+ } else if (n.type() != NT_FILE) {
+ outvt << "Not a file : " << args[i] << ENDL;
+ exit(-1);
+ }
f->appendFile(args[i]);
}
in = f;
diff --git a/Source/Library/Userland/Binding/FSNode.class.h b/Source/Library/Userland/Binding/FSNode.class.h
index a7adbc0..553197e 100644
--- a/Source/Library/Userland/Binding/FSNode.class.h
+++ b/Source/Library/Userland/Binding/FSNode.class.h
@@ -67,6 +67,28 @@ inline FSNode mkdir(String name, FSNode cwd = FSNode(0)) {
return FSNode(RessourceCaller::sCall(FNIF_OBJTYPE, FNIF_SMKDIR, (u32int)&name, cwd.resId()));
}
+inline String dirname(String filename) {
+ int lastSlash = 0;
+ for (int i = 0; i < filename.size(); i++) {
+ if (filename[i] == WChar("/")) {
+ lastSlash = i;
+ }
+ }
+ if (lastSlash == 0 and filename[0] == WChar("/")) return "/";
+ return filename.substr(0, lastSlash);
+}
+
+inline String basename(String filename) {
+ int lastSlash = 0;
+ for (int i = 0; i < filename.size(); i++) {
+ if (filename[i] == WChar("/")) {
+ lastSlash = i;
+ }
+ }
+ if (lastSlash == 0 and filename[0] != WChar("/")) return filename;
+ return filename.substr(lastSlash + 1);
+}
+
}
#endif