@@ -2514,6 +2514,10 @@ GLIBCXX_3.4.31 {
_ZNKSt12__shared_ptrINSt10filesystem28recursive_directory_iterator10_Dir_stackELN9__gnu_cxx12_Lock_policyE[012]EEcvbEv;
_ZNKSt12__shared_ptrINSt10filesystem7__cxx1128recursive_directory_iterator10_Dir_stackELN9__gnu_cxx12_Lock_policyE[012]EEcvbEv;
+ # These are only defined for *-*-mingw*
+ _ZSt16__fd_for_consolePSt15basic_streambufIcSt11char_traitsIcEE;
+ _ZSt24__write_utf16_to_consoleiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE;
+
} GLIBCXX_3.4.30;
GLIBCXX_3.4.32 {
@@ -85,6 +85,7 @@ std_headers = \
${std_srcdir}/memory_resource \
${std_srcdir}/mutex \
${std_srcdir}/ostream \
+ ${std_srcdir}/print \
${std_srcdir}/queue \
${std_srcdir}/random \
${std_srcdir}/regex \
@@ -441,6 +441,7 @@ std_freestanding = \
@GLIBCXX_HOSTED_TRUE@ ${std_srcdir}/memory_resource \
@GLIBCXX_HOSTED_TRUE@ ${std_srcdir}/mutex \
@GLIBCXX_HOSTED_TRUE@ ${std_srcdir}/ostream \
+@GLIBCXX_HOSTED_TRUE@ ${std_srcdir}/print \
@GLIBCXX_HOSTED_TRUE@ ${std_srcdir}/queue \
@GLIBCXX_HOSTED_TRUE@ ${std_srcdir}/random \
@GLIBCXX_HOSTED_TRUE@ ${std_srcdir}/regex \
@@ -1578,6 +1578,15 @@ ftms = {
};
};
+ftms = {
+ name = print;
+ values = {
+ v = 202211;
+ cxxmin = 23;
+ hosted = yes;
+ };
+};
+
ftms = {
name = spanstream;
values = {
@@ -1923,6 +1923,17 @@
#undef __glibcxx_want_out_ptr
// from version.def line 1582
+#if !defined(__cpp_lib_print)
+# if (__cplusplus >= 202100L) && _GLIBCXX_HOSTED
+# define __glibcxx_print 202211L
+# if defined(__glibcxx_want_all) || defined(__glibcxx_want_print)
+# define __cpp_lib_print 202211L
+# endif
+# endif
+#endif /* !defined(__cpp_lib_print) && defined(__glibcxx_want_print) */
+#undef __glibcxx_want_print
+
+// from version.def line 1591
#if !defined(__cpp_lib_spanstream)
# if (__cplusplus >= 202100L) && _GLIBCXX_HOSTED && (__glibcxx_span)
# define __glibcxx_spanstream 202106L
@@ -39,6 +39,11 @@
#include <ios>
#include <bits/ostream_insert.h>
+#if __cplusplus > 202002L
+# include <format>
+#endif
+
+# define __glibcxx_want_print
#include <bits/version.h> // __glibcxx_syncbuf
namespace std _GLIBCXX_VISIBILITY(default)
@@ -872,6 +877,103 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
#endif // __glibcxx_syncbuf
+#if __cpp_lib_print // C++ >= 23
+
+ inline void
+ vprint_nonunicode(ostream& __os, string_view __fmt, format_args __args)
+ {
+ ostream::sentry __cerb(__os);
+ if (__cerb)
+ {
+ string __out = std::vformat(__fmt, __args);
+ __try
+ {
+ const streamsize __w = __os.width();
+ const streamsize __n = __out.size();
+ if (__w > __n)
+ {
+ const bool __left
+ = (__os.flags() & ios_base::adjustfield) == ios_base::left;
+ if (!__left)
+ std::__ostream_fill(__os, __w - __n);
+ if (__os.good())
+ std::__ostream_write(__os, __out.data(), __n);
+ if (__left && __os.good())
+ std::__ostream_fill(__os, __w - __n);
+ }
+ else
+ std::__ostream_write(__os, __out.data(), __n);
+ }
+ __catch(const __cxxabiv1::__forced_unwind&)
+ {
+ __os._M_setstate(ios_base::badbit);
+ __throw_exception_again;
+ }
+ __catch(...)
+ { __os._M_setstate(ios_base::badbit); }
+ }
+ }
+
+ inline void
+ vprint_unicode(ostream& __os, string_view __fmt, format_args __args)
+ {
+ // TODO: diagnose invalid UTF-8 code units
+#ifdef _WIN32
+ int __fd_for_console(std::streambuf*);
+ void __write_utf16_to_console(int, string);
+
+ // If stream refers to a terminal convert to UTF-16 and use WriteConsoleW.
+ if (int __fd = __fd_for_console(__os.rdbuf()); __fd >= 0)
+ {
+ ostream::sentry __cerb(__os);
+ if (__cerb)
+ {
+ string __out = std::vformat(__fmt, __args);
+ ios_base::iostate __err = ios_base::goodbit;
+ __try
+ {
+ if (__os.rdbuf()->pubsync() == -1)
+ __err = ios::badbit;
+ else if (__write_utf16_to_console(__fd, __out))
+ __err = ios::badbit;
+ }
+ __catch(const __cxxabiv1::__forced_unwind&)
+ {
+ __os._M_setstate(ios_base::badbit);
+ __throw_exception_again;
+ }
+ __catch(...)
+ { __os._M_setstate(ios_base::badbit); }
+
+ if (__err)
+ __os.setstate(__err);
+ }
+ }
+#endif
+ std::vprint_nonunicode(__os, __fmt, __args);
+ }
+
+
+ template<typename... _Args>
+ inline void
+ print(ostream& __os, format_string<_Args...> __fmt, _Args&&... __args)
+ {
+ auto __fmtargs = std::make_format_args(std::forward<_Args>(__args)...);
+ if constexpr (string_view(__GNUC_EXECUTION_CHARSET_NAME) == "UTF-8")
+ std::vprint_unicode(__os, __fmt.get(), __fmtargs);
+ else
+ std::vprint_nonunicode(__os, __fmt.get(), __fmtargs);
+ }
+
+ template<typename... _Args>
+ inline void
+ println(ostream& __os, format_string<_Args...> __fmt, _Args&&... __args)
+ {
+ std::print(__os, "{}\n",
+ std::format(__fmt, std::forward<_Args>(__args)...));
+ }
+#endif // __cpp_lib_print
+
#endif // C++11
_GLIBCXX_END_NAMESPACE_VERSION
new file mode 100644
@@ -0,0 +1,128 @@
+// <print> Print functions -*- C++ -*-
+
+// Copyright The GNU Toolchain Authors.
+//
+// This file is part of the GNU ISO C++ Library. This library 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, or (at your option)
+// any later version.
+
+// This library 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.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file include/print
+ * This is a Standard C++ Library header.
+ */
+
+#ifndef _GLIBCXX_PRINT
+#define _GLIBCXX_PRINT 1
+
+#pragma GCC system_header
+
+#include <bits/requires_hosted.h> // for std::format
+
+#define __glibcxx_want_print
+#include <bits/version.h>
+
+#ifdef __cpp_lib_print // C++ >= 23
+
+#include <format>
+#include <cstdio>
+#include <cerrno>
+#include <bits/functexcept.h>
+
+#ifdef _WIN32
+# include <system_error>
+#endif
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+ inline void
+ vprint_nonunicode(FILE* __stream, string_view __fmt, format_args __args)
+ {
+ string __out = std::vformat(__fmt, __args);
+ if (std::fwrite(__out.data(), 1, __out.size(), __stream) != __out.size())
+ __throw_system_error(EIO);
+ }
+
+ inline void
+ vprint_unicode(FILE* __stream, string_view __fmt, format_args __args)
+ {
+ // TODO: diagnose invalid UTF-8 code units
+#ifdef _WIN32
+ int __fd_for_console(FILE*);
+ void __write_utf16_to_console(int, string);
+
+ // If stream refers to a terminal convert to UTF-16 and use WriteConsoleW.
+ if (int __fd = __fd_for_console(__stream); __fd >= 0)
+ {
+ string __out = std::vformat(__fmt, __args);
+ error_code __e;
+ if (!std::fflush(__stream))
+ {
+ if (!(__e = __write_utf16_to_console(__fd, __out)))
+ return;
+ }
+ else
+ __e = error_code(errno, generic_category());
+ _GLIBCXX_THROW_OR_ABORT(system_error(__e, "std::vprint_unicode"));
+ }
+#endif
+ std::vprint_nonunicode(__stream, __fmt, __args);
+ }
+
+ template<typename... _Args>
+ inline void
+ print(FILE* __stream, format_string<_Args...> __fmt, _Args&&... __args)
+ {
+ auto __fmtargs = std::make_format_args(std::forward<_Args>(__args)...);
+ if constexpr (string_view(__GNUC_EXECUTION_CHARSET_NAME) == "UTF-8")
+ std::vprint_unicode(__stream, __fmt.get(), __fmtargs);
+ else
+ std::vprint_nonunicode(__stream, __fmt.get(), __fmtargs);
+ }
+
+ template<typename... _Args>
+ inline void
+ print(format_string<_Args...> __fmt, _Args&&... __args)
+ { std::print(stdout, __fmt, std::forward<_Args>(__args)...); }
+
+ template<typename... _Args>
+ inline void
+ println(FILE* __stream, format_string<_Args...> __fmt, _Args&&... __args)
+ {
+ std::print(__stream, "{}\n",
+ std::format(__fmt, std::forward<_Args>(__args)...));
+ }
+
+ template<typename... _Args>
+ inline void
+ println(format_string<_Args...> __fmt, _Args&&... __args)
+ { std::println(stdout, __fmt, std::forward<_Args>(__args)...); }
+
+ inline void
+ vprint_unicode(string_view __fmt, format_args __args)
+ { std::vprint_unicode(stdout, __fmt, __args); }
+
+ inline void
+ vprint_nonunicode(string_view __fmt, format_args __args)
+ { std::vprint_nonunicode(stdout, __fmt, __args); }
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace std
+#endif // __cpp_lib_print
+#endif // _GLIBCXX_PRINT
@@ -36,7 +36,7 @@ else
inst_sources =
endif
-sources = tzdb.cc
+sources = tzdb.cc print.cc
vpath % $(top_srcdir)/src/c++20
@@ -121,7 +121,7 @@ CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
libc__20convenience_la_LIBADD =
-am__objects_1 = tzdb.lo
+am__objects_1 = tzdb.lo print.lo
@ENABLE_EXTERN_TEMPLATE_TRUE@am__objects_2 = sstream-inst.lo
@GLIBCXX_HOSTED_TRUE@am_libc__20convenience_la_OBJECTS = \
@GLIBCXX_HOSTED_TRUE@ $(am__objects_1) $(am__objects_2)
@@ -432,7 +432,7 @@ headers =
@ENABLE_EXTERN_TEMPLATE_TRUE@inst_sources = \
@ENABLE_EXTERN_TEMPLATE_TRUE@ sstream-inst.cc
-sources = tzdb.cc
+sources = tzdb.cc print.cc
@GLIBCXX_HOSTED_FALSE@libc__20convenience_la_SOURCES =
@GLIBCXX_HOSTED_TRUE@libc__20convenience_la_SOURCES = $(sources) $(inst_sources)
new file mode 100644
@@ -0,0 +1,35 @@
+#ifdef _WIN32
+#include <system_error>
+#include <codecvt>
+#include <bits/locale_conv.h>
+#include <stdio.h> // _fileno
+#include <io.h> // _get_osfhandle, _isatty
+#include <windows.h> // GetLastError, WriteConsoleW
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+ int
+ __fd_for_console(FILE* f)
+ {
+ if (int fd = _fileno(f); fd >= 0 && _isatty(fd))
+ return fd;
+ return -1;
+ }
+
+ error_code
+ __write_utf16_to_console(int fd, string str)
+ {
+ std::wstring wstr;
+ std::codecvt_utf8_utf16<wchar_t> wcvt;
+ const auto p = str.data();
+ unsigned long nchars = 0;
+ if (!std::__str_codecvt_in_all(p, p + str.size(), wstr, wcvt))
+ return std::make_error_code(errc::illegal_byte_sequence);
+ WriteConsoleW(reinterpret_cast<void*>(_get_osfhandle(fd)),
+ wstr.data(), wstr.size(), &nchars, nullptr);
+ if (nchars != wstr.size())
+ return {(int)GetLastError(), system_category()};
+ return {};
+ }
+}
+#endif // _WIN32
@@ -107,3 +107,26 @@ namespace __gnu_internal _GLIBCXX_VISIBILITY(hidden)
fake_wfilebuf buf_wcerr;
#endif
} // namespace __gnu_internal
+
+#ifdef _WIN32
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+ int __fd_for_console(FILE*);
+
+ int __fd_for_console(std::streambuf* sb)
+ {
+ using namespace __gnu_internal;
+ using namespace __gnu_cxx;
+
+ FILE* f = NULL;
+ void* p = sb;
+ if (p == buf_cout_sync || p == buf_cin_sync || p == buf_cerr_sync)
+ f = dynamic_cast<stdio_sync_filebuf<char>*>(sb)->file();
+ else if (p == buf_cout || p == buf_cin || p == buf_cerr)
+ f = dynamic_cast<stdio_filebuf<char>*>(sb)->file();
+ else
+ return -1;
+ return __fd_for_console(f);
+ }
+}
+#endif