Pull safe_print_error() out into a new file.
This commit is contained in:
parent
ff0737f567
commit
6cd903013f
4 changed files with 65 additions and 9 deletions
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include "env_real.hpp"
|
#include "env_real.hpp"
|
||||||
#include "string_view_cat.hpp"
|
#include "string_view_cat.hpp"
|
||||||
|
#include "safe_print.hpp"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
@ -27,7 +28,6 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <iostream>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#if defined(__GNU_LIBRARY__) && ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 17) || __GLIBC__ > 2)
|
#if defined(__GNU_LIBRARY__) && ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 17) || __GLIBC__ > 2)
|
||||||
|
@ -71,14 +71,6 @@ namespace {
|
||||||
static void value() noexcept {}
|
static void value() noexcept {}
|
||||||
};
|
};
|
||||||
|
|
||||||
void safe_print_error (std::string_view msg) noexcept {
|
|
||||||
try {
|
|
||||||
std::cerr << msg << std::endl;
|
|
||||||
}
|
|
||||||
catch (...) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PointerMap& pointer_map() {
|
PointerMap& pointer_map() {
|
||||||
static PointerMap pm;
|
static PointerMap pm;
|
||||||
return pm;
|
return pm;
|
||||||
|
|
|
@ -21,6 +21,7 @@ executable(meson.project_name(),
|
||||||
'var_map.cpp',
|
'var_map.cpp',
|
||||||
'env_base.cpp',
|
'env_base.cpp',
|
||||||
'env_real.cpp',
|
'env_real.cpp',
|
||||||
|
'safe_print.cpp',
|
||||||
install: true,
|
install: true,
|
||||||
dependencies: [fslib_dep],
|
dependencies: [fslib_dep],
|
||||||
include_directories: [cxxopts_incl],
|
include_directories: [cxxopts_incl],
|
||||||
|
|
38
src/safe_print.cpp
Normal file
38
src/safe_print.cpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/* Copyright 2020, Michele Santullo
|
||||||
|
* This file is part of user-gcc.
|
||||||
|
*
|
||||||
|
* User-gcc is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* User-gcc is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with user-gcc. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "safe_print.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace duck {
|
||||||
|
void safe_print (std::string_view msg) noexcept {
|
||||||
|
try {
|
||||||
|
std::cout << msg << std::endl;
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void safe_print_error (std::string_view msg) noexcept {
|
||||||
|
try {
|
||||||
|
std::cerr << msg << std::endl;
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} //namespace duck
|
||||||
|
|
25
src/safe_print.hpp
Normal file
25
src/safe_print.hpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/* Copyright 2020, Michele Santullo
|
||||||
|
* This file is part of user-gcc.
|
||||||
|
*
|
||||||
|
* User-gcc is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* User-gcc is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with user-gcc. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
namespace duck {
|
||||||
|
void safe_print (std::string_view msg) noexcept;
|
||||||
|
void safe_print_error (std::string_view msg) noexcept;
|
||||||
|
} //namespace duck
|
Loading…
Reference in a new issue