head	1.1;
branch	1.1.1;
access;
symbols
	perseant-exfatfs:1.1.1.1.0.2
	perseant-exfatfs-base-20261102:1.1.1.1
	gcc-14-4-0:1.1.1.1
	gcc-14-3-0:1.1.1.1
	FSF:1.1.1;
locks; strict;
comment	@# @;


1.1
date	2025.09.13.23.45.48;	author mrg;	state Exp;
branches
	1.1.1.1;
next	;
commitid	KwhwN4krNWa6XBaG;

1.1.1.1
date	2025.09.13.23.45.48;	author mrg;	state Exp;
branches
	1.1.1.1.2.1;
next	;
commitid	KwhwN4krNWa6XBaG;

1.1.1.1.2.1
date	2025.09.13.23.45.48;	author perseant;	state dead;
branches;
next	1.1.1.1.2.2;
commitid	3QTNojfCEH9lUb2H;

1.1.1.1.2.2
date	2026.11.04.22.52.10;	author perseant;	state Exp;
branches;
next	;
commitid	3QTNojfCEH9lUb2H;


desc
@@


1.1
log
@Initial revision
@
text
@// <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)
  {
    __format::_Str_sink<char> __buf;
    std::vformat_to(__buf.out(), __fmt, __args);
    auto __out = __buf.view();
    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)
  {
#if !defined(_WIN32) || defined(__CYGWIN__)
    // For most targets we don't need to do anything special to write
    // Unicode to a terminal.
    std::vprint_nonunicode(__stream, __fmt, __args);
#else
    __format::_Str_sink<char> __buf;
    std::vformat_to(__buf.out(), __fmt, __args);
    auto __out = __buf.view();

    void* __open_terminal(FILE*);
    error_code __write_to_terminal(void*, span<char>);
    // If stream refers to a terminal, write a native Unicode string to it.
    if (auto __term = __open_terminal(__stream))
      {
	string __out = std::vformat(__fmt, __args);
	error_code __e;
	if (!std::fflush(__stream))
	  {
	    __e = __write_to_terminal(__term, __out);
	    if (!__e)
	      return;
	    if (__e == std::make_error_code(errc::illegal_byte_sequence))
	      return;
	  }
	else
	  __e = error_code(errno, generic_category());
	_GLIBCXX_THROW_OR_ABORT(system_error(__e, "std::vprint_unicode"));
      }

    // Otherwise just write the string to the file as vprint_nonunicode does.
    if (std::fwrite(__out.data(), 1, __out.size(), __stream) != __out.size())
      __throw_system_error(EIO);
#endif
  }

  template<typename... _Args>
    inline void
    print(FILE* __stream, format_string<_Args...> __fmt, _Args&&... __args)
    {
      auto __fmtargs = std::make_format_args(__args...);
      if constexpr (__unicode::__literal_encoding_is_utf8())
	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); }

  // Defined for C++26, supported as an extension to C++23.
  inline void println(FILE* __stream)
  {
#if defined(_WIN32) && !defined(__CYGWIN__)
    if constexpr (__unicode::__literal_encoding_is_utf8())
      std::vprint_unicode(__stream, "\n", std::make_format_args());
    else
#endif
      if (std::putc('\n', __stream) == EOF)
	__throw_system_error(EIO);
  }

  inline void println() { std::println(stdout); }

_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
#endif // __cpp_lib_print
#endif // _GLIBCXX_PRINT
@


1.1.1.1
log
@initial import of GCC 14.3.0.

major changes in GCC 13:
- improved sanitizer
- zstd debug info compression
- LTO improvements
- SARIF based diagnostic support
- new warnings: -Wxor-used-as-pow, -Wenum-int-mismatch, -Wself-move,
  -Wdangling-reference
- many new -Wanalyzer* specific warnings
- enhanced warnings: -Wpessimizing-move, -Wredundant-move
- new attributes to mark file descriptors, c++23 "assume"
- several C23 features added
- several C++23 features added
- many new features for Arm, x86, RISC-V

major changes in GCC 14:
- more strict C99 or newer support
- ia64* marked deprecated (but seemingly still in GCC 15.)
- several new hardening features
- support for "hardbool", which can have user supplied values of true/false
- explicit support for stack scrubbing upon function exit
- better auto-vectorisation support
- added clang-compatible __has_feature and __has_extension
- more C23, including -std=c23
- several C++26 features added
- better diagnostics in C++ templates
- new warnings: -Wnrvo, Welaborated-enum-base
- many new features for Arm, x86, RISC-V
- possible ABI breaking change for SPARC64 and small structures with arrays
  of floats.
@
text
@@


1.1.1.1.2.1
log
@file print was added on branch perseant-exfatfs on 2026-11-04 22:52:10 +0000
@
text
@d1 156
@


1.1.1.1.2.2
log
@Sync with HEAD
@
text
@a0 156
// <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)
  {
    __format::_Str_sink<char> __buf;
    std::vformat_to(__buf.out(), __fmt, __args);
    auto __out = __buf.view();
    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)
  {
#if !defined(_WIN32) || defined(__CYGWIN__)
    // For most targets we don't need to do anything special to write
    // Unicode to a terminal.
    std::vprint_nonunicode(__stream, __fmt, __args);
#else
    __format::_Str_sink<char> __buf;
    std::vformat_to(__buf.out(), __fmt, __args);
    auto __out = __buf.view();

    void* __open_terminal(FILE*);
    error_code __write_to_terminal(void*, span<char>);
    // If stream refers to a terminal, write a native Unicode string to it.
    if (auto __term = __open_terminal(__stream))
      {
	string __out = std::vformat(__fmt, __args);
	error_code __e;
	if (!std::fflush(__stream))
	  {
	    __e = __write_to_terminal(__term, __out);
	    if (!__e)
	      return;
	    if (__e == std::make_error_code(errc::illegal_byte_sequence))
	      return;
	  }
	else
	  __e = error_code(errno, generic_category());
	_GLIBCXX_THROW_OR_ABORT(system_error(__e, "std::vprint_unicode"));
      }

    // Otherwise just write the string to the file as vprint_nonunicode does.
    if (std::fwrite(__out.data(), 1, __out.size(), __stream) != __out.size())
      __throw_system_error(EIO);
#endif
  }

  template<typename... _Args>
    inline void
    print(FILE* __stream, format_string<_Args...> __fmt, _Args&&... __args)
    {
      auto __fmtargs = std::make_format_args(__args...);
      if constexpr (__unicode::__literal_encoding_is_utf8())
	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); }

  // Defined for C++26, supported as an extension to C++23.
  inline void println(FILE* __stream)
  {
#if defined(_WIN32) && !defined(__CYGWIN__)
    if constexpr (__unicode::__literal_encoding_is_utf8())
      std::vprint_unicode(__stream, "\n", std::make_format_args());
    else
#endif
      if (std::putc('\n', __stream) == EOF)
	__throw_system_error(EIO);
  }

  inline void println() { std::println(stdout); }

_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
#endif // __cpp_lib_print
#endif // _GLIBCXX_PRINT
@


