mirror of
https://github.com/YosysHQ/yosys
synced 2025-09-30 05:09:04 +00:00
io: use std::filesystem
This commit is contained in:
parent
d31bfdd66a
commit
dad0ffe545
1 changed files with 12 additions and 12 deletions
24
kernel/io.cc
24
kernel/io.cc
|
@ -2,6 +2,7 @@
|
|||
#include "kernel/log.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
#if !defined(WIN32)
|
||||
#include <dirent.h>
|
||||
|
@ -384,23 +385,22 @@ std::string escape_filename_spaces(const std::string& filename)
|
|||
return out;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
const char* const OS_PATH_SEP = "/\\";
|
||||
#else
|
||||
const char* const OS_PATH_SEP = "/";
|
||||
#endif
|
||||
|
||||
std::string name_from_file_path(std::string path) {
|
||||
size_t sep_pos = path.find_last_of(OS_PATH_SEP);
|
||||
if (sep_pos != std::string::npos)
|
||||
return path.substr(sep_pos + 1);
|
||||
else
|
||||
return path;
|
||||
return std::filesystem::path(path).filename().string();
|
||||
}
|
||||
|
||||
// Includes OS_PATH_SEP at the end if present
|
||||
std::string parent_from_file_path(std::string path) {
|
||||
return path.substr(0, path.find_last_of(OS_PATH_SEP)+1);
|
||||
auto parent = std::filesystem::path(path).parent_path();
|
||||
if (parent.empty()) {
|
||||
return "";
|
||||
}
|
||||
// Add trailing separator to match original behavior
|
||||
std::string result = parent.string();
|
||||
if (!result.empty() && result.back() != std::filesystem::path::preferred_separator) {
|
||||
result += std::filesystem::path::preferred_separator;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void format_emit_unescaped(std::string &result, std::string_view fmt)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue