path operator/( path const & p, path const & rel_path ) { if ( p.empty() ) return rel_path; if ( rel_path.empty() ) return p; path::string_type new_path_name = p.native(), rel_path_name = rel_path.native(); if ( !IS_DIR_SEPARATORW( new_path_name.back() ) ) { new_path_name += ( IS_DIR_SEPARATORW( rel_path_name.front() ) ? L"" : L"\\" ) + rel_path_name; } else { int const index = rel_path_name.find_first_not_of( L"\\." ); new_path_name += rel_path_name.substr( index, path::string_type::npos ); } return path{ new_path_name }; }
bool __equivalent(const path& p1, const path& p2, std::error_code *ec) { std::error_code ec1, ec2; struct ::stat st1 = {}; struct ::stat st2 = {}; auto s1 = detail::posix_stat(p1.native(), st1, &ec1); auto s2 = detail::posix_stat(p2.native(), st2, &ec2); if ((!exists(s1) && !exists(s2)) || (is_other(s1) && is_other(s2))) { set_or_throw(make_error_code(errc::not_supported), ec, "equivalent", p1, p2); return false; } if (ec) ec->clear(); return (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino); }
void CDynamicLibrary::Load(const path& path) const { #if UCFG_USE_POSIX m_hModule = ::dlopen(String(path), 0); DlCheck(m_hModule == 0); #else Win32Check((m_hModule = ::LoadLibrary(String(path.native()))) != 0); #endif }
std::unique_ptr<std::ifstream> read(const path& path) { if (!File::exists(path) || !File::is_regular_file(path)) { throw std::invalid_argument("File "+path.native()+" not found"); } return std::unique_ptr<std::ifstream>(new ::boost::filesystem::ifstream(path)); }
Source::Source(Language *sourceLanguage, const path &sourceFilePath) throw(SourceException) { //variables ifstream sourceFile; FileBuffer *sourceBuffer = nullptr; size_t sourceFileSize = 0; //vérification de l'existence du fichier if (!exists(sourceFilePath)) { throw SourceException(tr("Le fichier source \"%0\" n'existe pas.", sourceFilePath.native())); } //taille du fichier sourceFileSize = file_size(sourceFilePath); //ouverture du fichier sourceFile.open(sourceFilePath.c_str(), ios::in); if (sourceFile.is_open()) { //allocation d'un buffer sourceBuffer = new FileBuffer(sourceFileSize); //récupération des données dans le fichier source sourceFile.read(sourceBuffer->getBufferPtr(), sourceBuffer->getBufferSize()); if (sourceFile.bad()) { throw SourceException(tr("La lecture du fichier source \"%0\" a échoué.", sourceFilePath.native())); } //fermeture du fichier sourceFile.close(); //parsage des données _sourceParser.parseSource(sourceFilePath.native(), sourceBuffer, sourceLanguage); //déallocation du buffer delete sourceBuffer; } else { //traitement des erreurs throw SourceException(tr("La lecture du fichier source \"%0\" a échoué.", sourceFilePath.native())); } }
bool __equivalent(const path& p1, const path& p2, std::error_code *ec) { auto make_unsupported_error = [&]() { set_or_throw(make_error_code(errc::not_supported), ec, "equivalent", p1, p2); return false; }; std::error_code ec1, ec2; struct ::stat st1 = {}; struct ::stat st2 = {}; auto s1 = detail::posix_stat(p1.native(), st1, &ec1); if (!exists(s1)) return make_unsupported_error(); auto s2 = detail::posix_stat(p2.native(), st2, &ec2); if (!exists(s2)) return make_unsupported_error(); if (ec) ec->clear(); return detail::stat_equivalent(st1, st2); }
void prepend(path fname, std::vector<uint8_t> const& prepend_data) { using namespace boost::iostreams; auto size = file_size(fname); auto resized = size + prepend_data.size(); resize_file(fname, resized); mapped_file mf(fname.native().c_str()); std::rotate(mf.data(), mf.data() + size, mf.data() + resized); std::copy(prepend_data.begin(), prepend_data.end(), mf.data()); }
void copy_file_transact(const path& from, const path& to) { path t = to.native() + ".deleteme"; SCOPE_FAIL{ cout << "Scope Fail" << endl; ::remove(t.c_str()); }; copy_file(from, t); rename(t, to); throw 1; }
Source::Source(LanguagePool *languagePool, const path &sourceFilePath) throw(LanguageException, SourceException) { //variable Language *sourceLanguage = nullptr; //vérification de l'existence du fichier if (!exists(sourceFilePath)) { throw SourceException(tr("Le fichier source \"%0\" n'existe pas.", sourceFilePath.native())); } //récupération du langage en fonction de l'extension de la source sourceLanguage = languagePool->getLanguageWithExtension(sourceFilePath.extension().native()); //parsage de la source Source(sourceLanguage, sourceFilePath); }
std::string LoadFileAsString(const path &relpath) { const path abspath = GetResourceAbspath(relpath); std::ifstream input; input.open(abspath.native()); if (!input.is_open()) { throw std::runtime_error("Cannot open for reading: " + abspath.generic_string()); } std::string text; text.reserve(FILE_RESERVE_SIZE); input.exceptions(std::ios::badbit); std::string line; while (std::getline(input, line)) { text.append(line); text.append("\n"); } return text; }
int path::compare(const path& p) const noexcept { return native() < p.native(); }