From aaabc853e84a03f72208c0e80634bd986c3ca4e2 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Sun, 19 Aug 2018 16:44:10 +0900 Subject: chore: move libdeno files to //libdeno/ --- libdeno/file_util.cc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 libdeno/file_util.cc (limited to 'libdeno/file_util.cc') diff --git a/libdeno/file_util.cc b/libdeno/file_util.cc new file mode 100644 index 000000000..a0cae5f58 --- /dev/null +++ b/libdeno/file_util.cc @@ -0,0 +1,31 @@ +// Copyright 2018 the Deno authors. All rights reserved. MIT license. +#include +#include +#include +#include +#include + +#include "file_util.h" + +namespace deno { + +bool ReadFileToString(const char* fn, std::string* contents) { + std::ifstream file(fn, std::ios::binary); + if (file.fail()) { + return false; + } + contents->assign(std::istreambuf_iterator{file}, {}); + return !file.fail(); +} + +std::string Basename(std::string const& filename) { + for (auto it = filename.rbegin(); it != filename.rend(); ++it) { + char ch = *it; + if (ch == '\\' || ch == '/') { + return std::string(it.base(), filename.end()); + } + } + return filename; +} + +} // namespace deno -- cgit v1.2.3