1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-11-17 15:47:15 +00:00

Don't use filesystem

This commit is contained in:
Mathieu Favreau
2025-09-29 15:37:02 +00:00
parent 9f68c73dc0
commit eabaaf3a1a

View File

@@ -20,17 +20,7 @@
#include "labsat23_source.h"
#include "INIReader.h"
#include "command_event.h"
#include <gnuradio/io_signature.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstdint>
#include <exception>
#include <filesystem>
#include <iomanip>
#include <iostream>
#include <memory>
#include <sstream>
#if HAS_BOOST_ENDIAN
#include <boost/endian/conversion.hpp>
@@ -102,6 +92,33 @@ void read_file_register_to_local_endian(std::ifstream &binary_input_file, uint64
#endif
}
std::string get_extension(const std::string &path)
{
size_t slash_pos = path.find_last_of("/\\"); // handle directories
size_t dot_pos = path.find_last_of('.');
// No dot or dot is in the directory part → no extension
if (dot_pos == std::string::npos || (slash_pos != std::string::npos && dot_pos < slash_pos))
{
return ""; // no extension
}
return path.substr(dot_pos); // includes the dot
}
std::string replace_extension(const std::string &path, const std::string &new_ext)
{
const auto dot_pos = path.find_last_of('.');
if (dot_pos == std::string::npos)
{
return path + new_ext; // no extension just append
}
else
{
return path.substr(0, dot_pos) + new_ext;
}
}
} // namespace
@@ -146,11 +163,10 @@ labsat23_source::labsat23_source(const char *signal_file_basename,
std::cout << "LabSat file version 4 detected.\n";
}
std::filesystem::path file_path(signal_file);
file_path.replace_extension(".ini");
const auto ini_file = replace_extension(signal_file, ".ini");
// Read ini file
if (read_ls3w_ini(file_path) != 0)
if (read_ls3w_ini(ini_file) != 0)
{
exit(1);
}
@@ -192,8 +208,7 @@ labsat23_source::~labsat23_source()
std::string labsat23_source::generate_filename()
{
std::filesystem::path file_path(d_signal_file_basename);
const auto extension = file_path.extension();
const auto extension = get_extension(d_signal_file_basename);
if (extension == ".ls2" or extension == ".LS2")
{