1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-14 04:00:34 +00:00

Avoid using cstdio header

See MISRA C++:2008, 27-0-1 - The stream input/output library <cstdio> shall not be used.
Replaced by filesystem library.
Avoid using cstring when it is easily replaced
This commit is contained in:
Carles Fernandez 2019-07-13 14:28:48 +02:00
parent 2d894a8507
commit 90a539ed26
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
8 changed files with 62 additions and 47 deletions

View File

@ -34,7 +34,6 @@
#include "pvt_solution.h"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <glog/logging.h>
#include <cstdio> // for remove
#include <ctime> // for tm
#include <exception> // for exception
#include <iomanip> // for operator<<
@ -240,7 +239,8 @@ bool GeoJSON_Printer::close_file()
// if nothing is written, erase the file
if (first_pos == true)
{
if (remove(filename_.c_str()) != 0)
errorlib::error_code ec;
if (!fs::remove(fs::path(filename_), ec))
{
LOG(INFO) << "Error deleting temporary file";
}

View File

@ -34,7 +34,6 @@
#include "rtklib_solver.h"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <glog/logging.h>
#include <cstdio> // for remove
#include <ctime> // for tm
#include <exception> // for exception
#include <iomanip> // for operator<<
@ -251,7 +250,8 @@ Gpx_Printer::~Gpx_Printer()
}
if (!positions_printed)
{
if (remove(gpx_filename.c_str()) != 0)
errorlib::error_code ec;
if (!fs::remove(fs::path(gpx_filename), ec))
{
LOG(INFO) << "Error deleting temporary GPX file";
}

View File

@ -34,9 +34,7 @@
#include "rtklib_solver.h"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <glog/logging.h>
#include <cstdio> // for remove
#include <cstdlib> // for mkstemp
#include <cstring> // for strncpy
#include <ctime> // for tm
#include <exception> // for exception
#include <iostream> // for cout, cerr
@ -366,7 +364,8 @@ Kml_Printer::~Kml_Printer()
}
if (!positions_printed)
{
if (remove(kml_filename.c_str()) != 0)
errorlib::error_code ec;
if (!fs::remove(fs::path(kml_filename), ec))
{
LOG(INFO) << "Error deleting temporary KML file";
}

View File

@ -133,6 +133,7 @@ Nmea_Printer::Nmea_Printer(const std::string& filename, bool flag_nmea_output_fi
Nmea_Printer::~Nmea_Printer()
{
auto pos = nmea_file_descriptor.tellp();
try
{
if (nmea_file_descriptor.is_open())
@ -148,6 +149,14 @@ Nmea_Printer::~Nmea_Printer()
{
std::cerr << e.what() << '\n';
}
if (pos == 0)
{
errorlib::error_code ec;
if (!fs::remove(fs::path(nmea_filename), ec))
{
std::cerr << "Problem removing NMEA temporary file: " << nmea_filename << '\n';
}
}
try
{
close_serial();

View File

@ -56,7 +56,6 @@
#include <glog/logging.h>
#include <algorithm> // for min and max
#include <cmath> // for floor
#include <cstring> // for memcpy
#include <exception>
#include <iostream> // for cout
#include <iterator>
@ -267,51 +266,59 @@ Rinex_Printer::~Rinex_Printer()
std::cerr << e.what() << '\n';
}
// If nothing written, erase the files.
if (posn == 0)
{
if (remove(navfilename.c_str()) != 0)
errorlib::error_code ec;
if (!fs::remove(fs::path(navfilename), ec))
{
LOG(INFO) << "Error deleting temporary file";
}
}
if (poso == 0)
{
if (remove(obsfilename.c_str()) != 0)
errorlib::error_code ec;
if (!fs::remove(fs::path(obsfilename), ec))
{
LOG(INFO) << "Error deleting temporary file";
}
}
if (poss == 0)
{
if (remove(sbsfilename.c_str()) != 0)
errorlib::error_code ec;
if (!fs::remove(fs::path(sbsfilename), ec))
{
LOG(INFO) << "Error deleting temporary file";
}
}
if (posng == 0)
{
if (remove(navGalfilename.c_str()) != 0)
errorlib::error_code ec;
if (!fs::remove(fs::path(navGalfilename), ec))
{
LOG(INFO) << "Error deleting temporary file";
}
}
if (posmn == 0)
{
if (remove(navMixfilename.c_str()) != 0)
errorlib::error_code ec;
if (!fs::remove(fs::path(navMixfilename), ec))
{
LOG(INFO) << "Error deleting temporary file";
}
}
if (posnr == 0)
{
if (remove(navGlofilename.c_str()) != 0)
errorlib::error_code ec;
if (!fs::remove(fs::path(navGlofilename), ec))
{
LOG(INFO) << "Error deleting temporary file";
}
}
if (posnc == 0)
{
if (remove(navBdsfilename.c_str()) != 0)
errorlib::error_code ec;
if (!fs::remove(fs::path(navBdsfilename), ec))
{
LOG(INFO) << "Error deleting temporary file";
}
@ -10171,10 +10178,10 @@ void Rinex_Printer::log_rinex_obs(std::fstream& out, const Gps_Ephemeris& eph, c
if ((total_mmap.count(mmap_iter->second.PRN)) == 1 && (mmap_iter->second.PRN != 0))
{
Gnss_Synchro gs = Gnss_Synchro();
std::string sys = "G";
gs.System = *sys.c_str();
std::string sig = "2S";
std::memcpy(static_cast<void*>(gs.Signal), sig.c_str(), 3);
gs.System = 'G';
gs.Signal[0] = '2';
gs.Signal[1] = 'S';
gs.Signal[2] = '\0';
gs.PRN = mmap_iter->second.PRN;
total_mmap.insert(std::pair<uint32_t, Gnss_Synchro>(mmap_iter->second.PRN, gs));
}
@ -10401,10 +10408,10 @@ void Rinex_Printer::log_rinex_obs(std::fstream& out, const Galileo_Ephemeris& ep
if (found_1B != std::string::npos)
{
Gnss_Synchro gs = Gnss_Synchro();
std::string sys = "E";
gs.System = *sys.c_str();
std::string sig = "1B";
std::memcpy(static_cast<void*>(gs.Signal), sig.c_str(), 3);
gs.System = 'E';
gs.Signal[0] = '1';
gs.Signal[1] = 'B';
gs.Signal[2] = '\0';
gs.PRN = prn_;
total_map.insert(std::pair<uint32_t, Gnss_Synchro>(prn_, gs));
}
@ -10426,20 +10433,20 @@ void Rinex_Printer::log_rinex_obs(std::fstream& out, const Galileo_Ephemeris& ep
if (found_1B != std::string::npos)
{
Gnss_Synchro gs = Gnss_Synchro();
std::string sys = "E";
gs.System = *sys.c_str();
std::string sig = "1B";
std::memcpy(static_cast<void*>(gs.Signal), sig.c_str(), 3);
gs.System = 'E';
gs.Signal[0] = '1';
gs.Signal[1] = 'B';
gs.Signal[2] = '\0';
gs.PRN = prn_;
total_map.insert(std::pair<uint32_t, Gnss_Synchro>(prn_, gs));
}
if (found_E5a != std::string::npos)
{
Gnss_Synchro gs = Gnss_Synchro();
std::string sys = "E";
gs.System = *sys.c_str();
std::string sig = "5X";
std::memcpy(static_cast<void*>(gs.Signal), sig.c_str(), 3);
gs.System = 'E';
gs.Signal[0] = '5';
gs.Signal[1] = 'X';
gs.Signal[2] = '\0';
gs.PRN = prn_;
total_map.insert(std::pair<uint32_t, Gnss_Synchro>(prn_, gs));
}
@ -10452,10 +10459,10 @@ void Rinex_Printer::log_rinex_obs(std::fstream& out, const Galileo_Ephemeris& ep
if ((total_map.count(prn_)) == 1)
{
Gnss_Synchro gs = Gnss_Synchro();
std::string sys = "E";
gs.System = *sys.c_str();
std::string sig = "5X";
std::memcpy(static_cast<void*>(gs.Signal), sig.c_str(), 3);
gs.System = 'E';
gs.Signal[0] = '5';
gs.Signal[1] = 'X';
gs.Signal[2] = '\0';
gs.PRN = prn_;
total_map.insert(std::pair<uint32_t, Gnss_Synchro>(prn_, gs));
}
@ -11521,10 +11528,10 @@ void Rinex_Printer::log_rinex_obs(std::fstream& out, const Beidou_Dnav_Ephemeris
if (found_B1 != std::string::npos)
{
Gnss_Synchro gs = Gnss_Synchro();
std::string sys = "C";
gs.System = *sys.c_str();
std::string sig = "B1";
std::memcpy(static_cast<void*>(gs.Signal), sig.c_str(), 3);
gs.System = 'C';
gs.Signal[0] = 'B';
gs.Signal[1] = '1';
gs.Signal[2] = '\0';
gs.PRN = prn_;
total_map.insert(std::pair<uint32_t, Gnss_Synchro>(prn_, gs));
}

View File

@ -40,7 +40,6 @@
#include "gps_ephemeris.h"
#include "rtcm.h"
#include <glog/logging.h>
#include <cstdio> // for remove
#include <ctime> // for tm
#include <exception> // for exception
#include <fcntl.h> // for O_RDWR
@ -221,7 +220,8 @@ Rtcm_Printer::~Rtcm_Printer()
}
if (pos == 0)
{
if (remove(rtcm_filename.c_str()) != 0)
errorlib::error_code ec;
if (!fs::remove(fs::path(rtcm_filename), ec))
{
LOG(INFO) << "Error deleting temporary RTCM file";
}

View File

@ -32,7 +32,6 @@
#include "dll_pll_conf.h"
#include "gnss_sdr_flags.h"
#include <cstring>
Dll_Pll_Conf::Dll_Pll_Conf()
{
@ -72,6 +71,7 @@ Dll_Pll_Conf::Dll_Pll_Conf()
enable_doppler_correction = false;
track_pilot = false;
system = 'G';
char sig_[3] = "1C";
std::memcpy(signal, sig_, 3);
signal[0] = '1';
signal[1] = 'C';
signal[2] = '\0';
}

View File

@ -32,7 +32,6 @@
#include "dll_pll_conf_fpga.h"
#include <cstring>
Dll_Pll_Conf_Fpga::Dll_Pll_Conf_Fpga()
{
@ -68,8 +67,9 @@ Dll_Pll_Conf_Fpga::Dll_Pll_Conf_Fpga()
carrier_lock_th = 0.85;
track_pilot = false;
system = 'G';
char sig_[3] = "1C";
std::memcpy(signal, sig_, 3);
signal[0] = '1';
signal[1] = 'C';
signal[2] = '\0';
device_name = "/dev/uio";
device_base = 1U;
multicorr_type = 0U;