From 6cd903013f465f6cfef1d0bf2ab36055e5258559 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Mon, 13 Apr 2020 16:27:42 +0200 Subject: [PATCH] Pull safe_print_error() out into a new file. --- src/env_real.cpp | 10 +--------- src/meson.build | 1 + src/safe_print.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/safe_print.hpp | 25 +++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 src/safe_print.cpp create mode 100644 src/safe_print.hpp diff --git a/src/env_real.cpp b/src/env_real.cpp index f799b17..96c9a09 100644 --- a/src/env_real.cpp +++ b/src/env_real.cpp @@ -20,6 +20,7 @@ #include "env_real.hpp" #include "string_view_cat.hpp" +#include "safe_print.hpp" #include #include #include @@ -27,7 +28,6 @@ #include #include #include -#include #include #if defined(__GNU_LIBRARY__) && ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 17) || __GLIBC__ > 2) @@ -71,14 +71,6 @@ namespace { static void value() noexcept {} }; - void safe_print_error (std::string_view msg) noexcept { - try { - std::cerr << msg << std::endl; - } - catch (...) { - } - } - PointerMap& pointer_map() { static PointerMap pm; return pm; diff --git a/src/meson.build b/src/meson.build index 20eb946..8a762d8 100644 --- a/src/meson.build +++ b/src/meson.build @@ -21,6 +21,7 @@ executable(meson.project_name(), 'var_map.cpp', 'env_base.cpp', 'env_real.cpp', + 'safe_print.cpp', install: true, dependencies: [fslib_dep], include_directories: [cxxopts_incl], diff --git a/src/safe_print.cpp b/src/safe_print.cpp new file mode 100644 index 0000000..685f8a1 --- /dev/null +++ b/src/safe_print.cpp @@ -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 . + */ + +#include "safe_print.hpp" +#include + +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 + diff --git a/src/safe_print.hpp b/src/safe_print.hpp new file mode 100644 index 0000000..1d1d78b --- /dev/null +++ b/src/safe_print.hpp @@ -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 . + */ + +#pragma once + +#include + +namespace duck { + void safe_print (std::string_view msg) noexcept; + void safe_print_error (std::string_view msg) noexcept; +} //namespace duck